public void BinaryTrieCanBeRestoredFromFile()
        {
            var trie  = new PlugableBinaryTrie <int>(c);
            var item1 = 5;
            var item2 = 13;

            trie.Add(item1, item1);
            trie.Add(item2, item2);

            var expectedValuesCount = trie.Count;

            trie.Dispose();

            var restoredTrie = new PlugableBinaryTrie <int>(
                new MemoryMappedNodeContainer <int>(c.FileName)
                );

            Assert.Equal(expectedValuesCount, restoredTrie.Count);

            var sortedPairs = restoredTrie.GetEntrySet().ToArray();

            Assert.Equal(expectedValuesCount, sortedPairs.Length);

            Assert.Equal(item1, sortedPairs[0].Item2);
            Assert.Equal(item1, sortedPairs[0].Item1[0]);
            Assert.Equal(item2, sortedPairs[1].Item2);
            Assert.Equal(item2, sortedPairs[1].Item1[0]);

            restoredTrie.Add(5, 10);
            restoredTrie.Add(10, 15);

            var storedValue = restoredTrie.GetValue(new [] { 13 });

            Assert.Equal(13, storedValue);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            //var container = new ArrayBackedNodesContainer<int>(initialSize:32000000);
            var container = new GrowableArrayBackedNodeContainer <int>();
            var trie      = new PlugableBinaryTrie <int>(container);

            for (int i = 1000000; i > 0; i--)
            {
                trie.Add(i, i);
            }

            var allOk = true;

            for (int i = 1; i <= 1000000; i++)
            {
                var value = trie.GetValue(i);
                allOk = allOk & value == i;
            }

            if (allOk)
            {
                Console.WriteLine("All Ok.");
            }
            else
            {
                Console.WriteLine("Something is wrong.");
            }
        }
Beispiel #3
0
        public void UsingIntKeysOnArrayBackedGrowableTrie()
        {
            object f1()
            {
                var container = new GrowableArrayBackedNodeContainer <int>(5000000, true);

                var trie = new PlugableBinaryTrie <int>(container);

                for (int i = TotalKeys; i >= 0; i--)
                {
                    trie.Add(i, i);
                }

                Assert.Equal(TotalKeys + 1, trie.Count);

                var lastKey = -1;
                var allOk   = true;

                foreach (var kvp in trie.GetEntrySet(reuseKeysList: true))
                {
                    var key   = kvp.Item1[0];
                    var value = kvp.Item2;

                    allOk   = allOk && key == value;
                    allOk   = allOk && key >= lastKey;
                    lastKey = key;
                }

                Assert.True(allOk);

                return(trie);
            }

            var oldCount = TotalKeys;

            TotalKeys = 100000;
            var disposable = f1() as IDisposable;

            disposable.Dispose();
            TotalKeys = oldCount;
            var execution = H.Run(f1);

            this.output.WriteLine(execution.ToString());
        }
Beispiel #4
0
        public void UsingGrowableMemoryMapedTrie()
        {
            object f1()
            {
                var container = new GrowableMemoryMappedNodeContainer <int>(size: TotalKeys * 32);
                var trie      = new PlugableBinaryTrie <int>(container);

                for (int i = TotalKeys; i >= 0; i--)
                {
                    trie.Add(i, i);
                }

                Assert.Equal(trie.Count, TotalKeys + 1);
                var allOk = true;

                for (int i = 0; i <= TotalKeys; i++)
                {
                    var value = trie.GetValue(i, -1);
                    allOk = allOk && value == i;
                }

                Assert.True(allOk);
                return(trie);
            }

            var oldKeysCount = TotalKeys;

            TotalKeys = 10000;
            var testTrie = f1() as IDisposable;

            testTrie.Dispose();
            Dispose();
            TotalKeys = oldKeysCount;

            var execution = H.Run(f1);

            this.output.WriteLine(execution.ToString());
        }
Beispiel #5
0
        public void UsingArrayBackedTrie()
        {
            object f1()
            {
                var container = new ArrayBackedNodesContainer <int>(TotalKeys * 32);
                var trie      = new PlugableBinaryTrie <int>(container);

                for (int i = TotalKeys; i >= 0; i--)
                {
                    trie.Add(i, i);
                }

                var allOk = true;

                for (int i = TotalKeys; i >= 0; i--)
                {
                    var value = trie.GetValue(i, -1);
                    allOk = allOk && value == i;
                }

                Assert.True(allOk);

                return(trie);
            }

            var oldCount = TotalKeys;

            TotalKeys = 100000;
            var disp = f1() as IDisposable;

            disp.Dispose();
            TotalKeys = oldCount;

            var execution = H.Run(f1);

            this.output.WriteLine(execution.ToString());
        }