@@ -37,7 +37,7 @@ namespace Semmle.Util
3737 /// </remarks>
3838 ///
3939 /// <typeparam name="T">The value type.</typeparam>
40- public class FuzzyDictionary < T >
40+ public class FuzzyDictionary < T > where T : class
4141 {
4242 // All data items indexed by the "base string" (stripped of numbers)
4343 readonly Dictionary < string , List < KeyValuePair < string , T > > > index = new Dictionary < string , List < KeyValuePair < string , T > > > ( ) ;
@@ -61,7 +61,7 @@ public void Add(string k, T v)
6161 /// <param name="v1">Vector 1</param>
6262 /// <param name="v2">Vector 2</param>
6363 /// <returns>The Hamming Distance.</returns>
64- static int HammingDistance < U > ( IEnumerable < U > v1 , IEnumerable < U > v2 )
64+ static int HammingDistance < U > ( IEnumerable < U > v1 , IEnumerable < U > v2 ) where U : notnull
6565 {
6666 return v1 . Zip ( v2 , ( x , y ) => x . Equals ( y ) ? 0 : 1 ) . Sum ( ) ;
6767 }
@@ -72,11 +72,10 @@ static int HammingDistance<U>(IEnumerable<U> v1, IEnumerable<U> v2)
7272 /// <param name="query">The query string.</param>
7373 /// <param name="distance">The distance between the query string and the stored string.</param>
7474 /// <returns>The best match, or null (default).</returns>
75- public T FindMatch ( string query , out int distance )
75+ public T ? FindMatch ( string query , out int distance )
7676 {
7777 string root = StripDigits ( query ) ;
78- List < KeyValuePair < string , T > > list ;
79- if ( ! index . TryGetValue ( root , out list ) )
78+ if ( ! index . TryGetValue ( root , out var list ) )
8079 {
8180 distance = 0 ;
8281 return default ( T ) ;
@@ -93,9 +92,9 @@ public T FindMatch(string query, out int distance)
9392 /// <param name="distance">The distance function.</param>
9493 /// <param name="bestDistance">The distance between the query and the stored string.</param>
9594 /// <returns>The stored value.</returns>
96- static T BestMatch ( string query , IEnumerable < KeyValuePair < string , T > > candidates , Func < string , string , int > distance , out int bestDistance )
95+ static T ? BestMatch ( string query , IEnumerable < KeyValuePair < string , T > > candidates , Func < string , string , int > distance , out int bestDistance )
9796 {
98- T bestMatch = default ( T ) ;
97+ T ? bestMatch = default ( T ) ;
9998 bestDistance = 0 ;
10099 bool first = true ;
101100
0 commit comments