Exemplo n.º 1
0
        private static long BenchmarkFastDictionaryStringOut(string[] tuples, int tries)
        {
            int y        = 0;
            var fast     = Stopwatch.StartNew();
            var fastDict = new FastDictionary <int, string>(tuples.Length * 2);

            for (int i = 0; i < tries; i++)
            {
                for (int j = 0; j < tuples.Length; j++)
                {
                    fastDict[j] = tuples[j];
                }

                string k;
                for (int j = 0; j < tuples.Length; j++)
                {
                    fastDict.TryGetValue(j, out k);
                    //k = fastDict[j];
                    if (k != null)
                    {
                        y++;
                    }
                }

                //fastDict.Clear();
            }
            fast.Stop();
            return(fast.ElapsedMilliseconds);
        }
Exemplo n.º 2
0
        private static long BenchmarkFastDictionaryString(string[] tuples, int tries)
        {
            var fast     = Stopwatch.StartNew();
            var fastDict = new FastDictionary <string, int>(tuples.Length * 2);

            for (int i = 0; i < tries; i++)
            {
                for (int j = 0; j < tuples.Length; j++)
                {
                    fastDict[tuples[j]] = j;
                }

                int k;
                for (int j = 0; j < tuples.Length; j++)
                {
                    fastDict.TryGetValue(tuples[j], out k);
                    // k = fastDict[tuples[j]];
                    k++;
                }

                //fastDict.Clear();
            }
            fast.Stop();
            return(fast.ElapsedMilliseconds);
        }
Exemplo n.º 3
0
        public void ConsecutiveInsertsWithShrink()
        {
            var dict = new FastDictionary <int, int>();

            for (int i = 0; i < 100; i++)
            {
                dict[i] = i;
            }

            dict.Clear();

            for (int i = 0; i < 33; i++)
            {
                dict[i] = i;
            }

            dict.Remove(32);

            int value;

            Assert.True(dict.TryGetValue(0, out value));

            Assert.Equal(32, dict.Count);
            Assert.True(dict.Capacity > 32);
        }
Exemplo n.º 4
0
        public void AddAndRemoveWithoutGrowth()
        {
            var dict = new FastDictionary <long, int>(8);

            for (int i = 0; i < 100; i++)
            {
                dict.Add(i, i);
                dict.Remove(i);
                int dummy;
                Assert.False(dict.TryGetValue(i, out dummy));
            }

            Assert.Equal(0, dict.Count);
            Assert.Equal(8, dict.Capacity);
        }