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);
        }
예제 #2
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());
        }