private void MakeGrandchild(PersistentTrieItem oldChild) { var discriminator = oldChild.Prefix.Skip(Prefix.Count).First(); var grandchild = NewChild(new PersistentTrieItem(_storage, oldChild.Prefix.Skip(Prefix.Count + 1), oldChild.HasValue, oldChild.Value, oldChild.True, oldChild.False, oldChild.TrueCount, oldChild.FalseCount)); if (discriminator) { if (True != null) { throw new InvalidOperationException("Child 1 already set"); } True = grandchild; TrueCount = (uint)oldChild.Count; } else { if (False != null) { throw new InvalidOperationException("Child 0 already set"); } False = grandchild; FalseCount = (uint)oldChild.Count; } MarkDirty(); }
private Func <PersistentTrieItem> NewChild(PersistentTrieItem child) { if (child == null) { throw new ArgumentNullException(nameof(child)); } return(() => child); }
public PersistentTrie(Stream storage) { _storage = storage; _root = new PersistentTrieItem(storage, 0); }