public void TestTrieBulkData() { var memDb = new MemoryDictionarySource(); var trie = new PatriciaTrie(memDb); Dictionary <string, string> toInput = new Dictionary <string, string>(); for (int i = 0; i < 1000; i++) { toInput.Add( new Random().Next().ToString(), new Random().Next().ToString() ); } foreach (var kvp in toInput) { trie.Put(Encoding.UTF8.GetBytes(kvp.Key), Encoding.UTF8.GetBytes(kvp.Value)); } foreach (var kvp in toInput) { Assert.Equal(kvp.Value, Encoding.UTF8.GetString(trie.Get(Encoding.UTF8.GetBytes(kvp.Key)))); } trie.Put(dog, cat); trie.Put(fish, bird); trie.Put(dodecahedron, fish); trie.Flush(); byte[] savedHash = trie.GetRootHash(); var trie2 = new PatriciaTrie(memDb); trie2.SetRootHash(savedHash); Assert.Equal(cat, trie.Get(dog)); Assert.Equal(cat, trie2.Get(dog)); Assert.Equal(bird, trie2.Get(fish)); Assert.Equal(fish, trie2.Get(dodecahedron)); foreach (var kvp in toInput) { Assert.Equal(kvp.Value, Encoding.UTF8.GetString(trie2.Get(Encoding.UTF8.GetBytes(kvp.Key)))); } }
public void TestTrieLoad() { var memDb = new MemoryDictionarySource(); var trie = new PatriciaTrie(memDb); trie.Put(dog, cat); trie.Put(fish, bird); trie.Put(dodecahedron, fish); trie.Flush(); byte[] savedHash = trie.GetRootHash(); var trie2 = new PatriciaTrie(memDb); trie2.SetRootHash(savedHash); Assert.Equal(cat, trie.Get(dog)); Assert.Equal(cat, trie2.Get(dog)); Assert.Equal(bird, trie2.Get(fish)); Assert.Equal(fish, trie2.Get(dodecahedron)); }