/// <summary> /// Joins two Patricia Tries having different keys with common branch. /// </summary> /// <param name="prefixA">Prfix of the first Trie.</param> /// <param name="nodeA">First Patricia Trie.</param> /// <param name="prefixB">Prefix of the second Trie.</param> /// <param name="nodeB">Second Trie.</param> /// <returns>New Patritia Trie node having given nodes as her children.</returns> public static IPatriciaNode <T> Join <T>(int prefixA, IPatriciaNode <T> nodeA, int prefixB, IPatriciaNode <T> nodeB) { var bb = BranchingBit(prefixA, prefixB); var newPrefix = prefixA & (bb - 1); return((prefixA & bb) == 0 ? new PatriciaBranch <T>(newPrefix, bb, nodeA, nodeB) : new PatriciaBranch <T>(newPrefix, bb, nodeB, nodeA)); }
private IPatriciaNode <T> CreateNode <T>(IEnumerable <T> items) where T : class { IPatriciaNode <T> empty = EmptyPatriciaTrie <T> .Instance; return(items.Aggregate(empty, (current, item) => current.Modify(item.GetHashCode(), InsertOperation(item)))); }
private ImmutableHashSet(IPatriciaNode <T> root) { if (root == null) { throw new ArgumentNullException(nameof(root)); } _root = root; }
public void RemovingSequentialKeys_Test() { var items = Enumerable.Range(0, _items.Length). Zip(_items, (i, s) => new KeyValuePair <int, string>(i, s)).ToArray(); IPatriciaNode <string> empty = EmptyPatriciaTrie <string> .Instance; var node = items.Aggregate(empty, (current, item) => current.Modify(item.Key, InsertOperation(item.Value))); foreach (var item in items) { node = node.Modify(item.Key, NullOperation <string>()) ?? EmptyPatriciaTrie <string> .Instance; CollectionAssert.DoesNotContain(node.GetItems(), item.Value); } }
// Constructors public ImmutableHashSet() { _root = EmptyPatriciaTrie <T> .Instance; }
public PatriciaBranch(int prefix, int mask, IPatriciaNode <T> left, IPatriciaNode <T> right) : this(prefix, mask, new[] { left, right }) { }
private ImmutableHashDictionary(IPatriciaNode <KeyValuePair <TKey, TValue> > root) { _root = root; }
// Constructors public ImmutableHashDictionary() { _root = EmptyPatriciaTrie <KeyValuePair <TKey, TValue> > .Instance; }