Beispiel #1
0
        private void AddLeaf(Hash256 index, ShaMapLeafNode leaf)
        {
            int ix       = index.Nibblet(this.depth);
            var existing = this.branches[ix];

            this.Invalidate();

            if (existing == null)
            {
                this.SetNode(ix, leaf);
            }
            else
            {
                var node = existing as ShaMapLeafNode;
                if (node != null)
                {
                    if (node.Index.Equals(index))
                    {
                        throw new InvalidOperationException("Tried to add node already in tree!");
                    }

                    var container = this.MakeInnerChild();
                    container.AddLeaf(node.Index, node);
                    container.AddLeaf(index, leaf);
                    this.SetNode(ix, container);
                }
                else
                {
                    var existingInner = (ShaMapInnerNode)existing;
                    existingInner.AddLeaf(index, leaf);
                }
            }
        }
Beispiel #2
0
        public void TestNibblet()
        {
            var     ledgerIndex = "D66D0EC951FD5707633BEBE74DB18B6D2DDA6771BA0FBF079AD08BFDE6066056";
            Hash256 index       = this.Hash(ledgerIndex);

            for (int i = 0; i < ledgerIndex.Length; i++)
            {
                int    n1 = index.Nibblet(i);
                string s  = n1.ToString("X").ToUpper();
                Assert.AreEqual(ledgerIndex.Substring(i, 1), s);
            }
        }
Beispiel #3
0
        protected ShaMapLeafNode GetLeaf(Hash256 id, bool invalidating)
        {
            int        ix       = id.Nibblet(this.depth);
            ShaMapNode existing = this.branches[ix];

            if (invalidating)
            {
                this.Invalidate();
            }

            if (existing == null)
            {
                return(null);
            }

            var node = existing as ShaMapLeafNode;

            if (node != null)
            {
                return(node);
            }

            return(((ShaMapInnerNode)existing).GetLeaf(id, invalidating));
        }
Beispiel #4
0
 protected internal int SelectBranch(Hash256 index)
 {
     return index.Nibblet(Depth);
 }
Beispiel #5
0
 protected internal ShaMapNode GetBranch(Hash256 index)
 {
     return GetBranch(index.Nibblet(Depth));
 }