Пример #1
0
 public ShaMapLeaf GetLeafForUpdating(Hash256 leaf)
 {
     var path = PathToIndex(leaf);
     if (path.HasMatchedLeaf())
     {
         return path.InvalidatedPossiblyCopiedLeafForUpdating();
     }
     return null;
 }
Пример #2
0
 private void RemoveBranch(Hash256 index)
 {
     RemoveBranch(SelectBranch(index));
 }
Пример #3
0
 protected internal ShaMapNode GetBranch(Hash256 index)
 {
     return GetBranch(index.Nibblet(Depth));
 }
Пример #4
0
 protected internal int SelectBranch(Hash256 index)
 {
     return index.Nibblet(Depth);
 }
Пример #5
0
 public void Invalidate()
 {
     CachedHash = null;
 }
Пример #6
0
 protected internal void SetBranch(Hash256 index, ShaMapNode node)
 {
     SetBranch(SelectBranch(index), node);
 }
Пример #7
0
 public bool HasLeaf(Hash256 index)
 {
     return PathToIndex(index).HasMatchedLeaf();
 }
Пример #8
0
        private void MakeStack(ShaMapInner root, Hash256 index)
        {
            _inners = new LinkedList<ShaMapInner>();
            var top = root;

            while (true)
            {
                _inners.AddLast(top);
                var existing = top.GetBranch(index);
                if (existing == null)
                {
                    break;
                }
                if (existing.IsLeaf)
                {
                    Leaf = existing.AsLeaf();
                    _matched = Leaf.Index.Equals(index);
                    break;
                }
                if (existing.IsInner)
                {
                    top = existing.AsInner();
                }
            }
        }
Пример #9
0
 public bool AddItem(Hash256 index, IShaMapItem<object> item)
 {
     return AddLeaf(new ShaMapLeaf(index, item));
 }
Пример #10
0
 public bool UpdateItem(Hash256 index, IShaMapItem<object> item)
 {
     return UpdateLeaf(new ShaMapLeaf(index, item));
 }
Пример #11
0
 public IShaMapItem<object> GetItem(Hash256 index)
 {
     return GetLeaf(index)?.Item;
 }
Пример #12
0
 public bool RemoveLeaf(Hash256 index)
 {
     var path = PathToIndex(index);
     if (!path.HasMatchedLeaf()) return false;
     var top = path.DirtyOrCopyInners();
     top.RemoveBranch(index);
     path.CollapseOnlyLeafChildInners();
     return true;
 }
Пример #13
0
 public virtual Hash256 Hash()
 {
     return CachedHash ?? (CachedHash = CreateHash());
 }
Пример #14
0
 protected internal ShaMapLeaf(Hash256 index, IShaMapItem<object> item)
 {
     Index = index;
     Item = item;
 }
Пример #15
0
 public ShaMapLeaf GetLeaf(Hash256 index)
 {
     var stack = PathToIndex(index);
     return stack.HasMatchedLeaf() ? stack.Leaf : null;
 }
Пример #16
0
 public PathToIndex(ShaMapInner root, Hash256 index)
 {
     Index = index;
     MakeStack(root, index);
 }
Пример #17
0
 public PathToIndex PathToIndex(Hash256 index)
 {
     return new PathToIndex(this, index);
 }
Пример #18
0
 public Hash256 ReadHash256()
 {
     return(Hash256.FromParser(_parser));
 }
Пример #19
0
 private static void AssertHashesEqual(Hash256 h1, Hash h2)
 {
     if (!h1.Equals(h2))
     {
         throw new AssertionError(h1 + " != " + h2);
     }
 }