public ShaMapLeaf GetLeafForUpdating(Hash256 leaf) { var path = PathToIndex(leaf); if (path.HasMatchedLeaf()) { return path.InvalidatedPossiblyCopiedLeafForUpdating(); } return null; }
private void RemoveBranch(Hash256 index) { RemoveBranch(SelectBranch(index)); }
protected internal ShaMapNode GetBranch(Hash256 index) { return GetBranch(index.Nibblet(Depth)); }
protected internal int SelectBranch(Hash256 index) { return index.Nibblet(Depth); }
public void Invalidate() { CachedHash = null; }
protected internal void SetBranch(Hash256 index, ShaMapNode node) { SetBranch(SelectBranch(index), node); }
public bool HasLeaf(Hash256 index) { return PathToIndex(index).HasMatchedLeaf(); }
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(); } } }
public bool AddItem(Hash256 index, IShaMapItem<object> item) { return AddLeaf(new ShaMapLeaf(index, item)); }
public bool UpdateItem(Hash256 index, IShaMapItem<object> item) { return UpdateLeaf(new ShaMapLeaf(index, item)); }
public IShaMapItem<object> GetItem(Hash256 index) { return GetLeaf(index)?.Item; }
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; }
public virtual Hash256 Hash() { return CachedHash ?? (CachedHash = CreateHash()); }
protected internal ShaMapLeaf(Hash256 index, IShaMapItem<object> item) { Index = index; Item = item; }
public ShaMapLeaf GetLeaf(Hash256 index) { var stack = PathToIndex(index); return stack.HasMatchedLeaf() ? stack.Leaf : null; }
public PathToIndex(ShaMapInner root, Hash256 index) { Index = index; MakeStack(root, index); }
public PathToIndex PathToIndex(Hash256 index) { return new PathToIndex(this, index); }
public Hash256 ReadHash256() { return(Hash256.FromParser(_parser)); }
private static void AssertHashesEqual(Hash256 h1, Hash h2) { if (!h1.Equals(h2)) { throw new AssertionError(h1 + " != " + h2); } }