示例#1
0
        public static RoslynHashEvaluator Create(string[] keys)
        {
            var random = new Random();

            while (true)
            {
                int  a       = random.Next();
                int  b       = random.Next();
                var  result  = new RoslynHashEvaluator(a, b);
                var  hashSet = new HashSet <int>();
                bool ok      = true;
                foreach (var key in keys)
                {
                    var hashCode = result.ComputeStringHash(key);
                    if (hashSet.Contains(hashCode))
                    {
                        ok = false;
                        break;
                    }
                    hashSet.Add(hashCode);
                }
                if (ok)
                {
                    return(result);
                }
            }
        }
示例#2
0
        public static Func <string, int> Create(string[] keys)
        {
            var fastHashEvaluator1 = FastHashEvaluator1.Create(keys);

            if (fastHashEvaluator1 != null)
            {
                return(fastHashEvaluator1.ComputeStringHash);
            }
            var fastHashEvaluator2 = FastHashEvaluator2.Create(keys);

            if (fastHashEvaluator2 != null)
            {
                return(fastHashEvaluator2.ComputeStringHash);
            }
            var fastHashEvaluator3 = FastHashEvaluator3.Create(keys);

            if (fastHashEvaluator3 != null)
            {
                return(fastHashEvaluator3.ComputeStringHash);
            }
            return(RoslynHashEvaluator.Create(keys).ComputeStringHash);
        }
示例#3
0
        public Runner(int numberOfKeys, int seed)
        {
            random = new Random(seed);
            var keys   = new string[numberOfKeys];
            var values = new int[numberOfKeys];

            for (int i = 0; i < numberOfKeys; ++i)
            {
                int len = random.Next(3, 10);
                var arr = new char[len];
                for (int j = 0; j < len; ++j)
                {
                    arr[j] = (char)random.Next(33, 128);
                }
                keys[i]   = new string(arr);
                values[i] = i * 3;
            }

            testKeys = new string[numberOfKeys * 20];
            for (int i = 0; i < testKeys.Length / 2; ++i)
            {
                testKeys[i] = keys[random.Next(numberOfKeys)];
            }
            for (int i = testKeys.Length / 2; i < testKeys.Length; ++i)
            {
                int len = random.Next(3, 10);
                var arr = new char[len];
                for (int j = 0; j < len; ++j)
                {
                    arr[j] = (char)random.Next(33, 128);
                }
                testKeys[i] = new string(arr);
            }
            RandomShuffle(testKeys, random);

            var dict = new Dictionary <string, int>();

            for (int i = 0; i < numberOfKeys; ++i)
            {
                dict.Add(keys[i], values[i]);
            }
            dictionary = dict.TryGetValue;

            perfectHashtable = PerfectHashtableBuilder.Build(keys, values, FastHashEvaluator.Create(keys));

            perfectHashtableWithRoslynHash = PerfectHashtableBuilder.Build(keys, values, RoslynHashEvaluator.Create(keys).ComputeStringHash);

            trie = TrieBuilder.Build(keys, values);

            bunchOfIffs = BunchOfIfsBuilder.Build(keys, values);

            unrolledBSWithRoslynHash = UnrolledBinarySearchBuilder.Build(keys, values, RoslynHashEvaluator.Create(keys).ComputeStringHash);

            unrolledBSWithFastHash = UnrolledBinarySearchBuilder.Build(keys, values, FastHashEvaluator.Create(keys));
        }