Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
 private Func <PersistentTrieItem> NewChild(PersistentTrieItem child)
 {
     if (child == null)
     {
         throw new ArgumentNullException(nameof(child));
     }
     return(() => child);
 }
Ejemplo n.º 3
0
 public PersistentTrie(Stream storage)
 {
     _storage = storage;
     _root    = new PersistentTrieItem(storage, 0);
 }