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); }
public void Dispose() { trie?.Dispose(); if (container != null) { if (container is MemoryMappedNodeContainer <int> ) { File.Delete("./gtrie.bin"); } if (container is GrowableMemoryMappedNodeContainer <int> ) { Directory.Delete("./gtrie", true); } } }