Esempio n. 1
0
        public byte[] Get(TrieNode node, TrieKey key)
        {
            if (node == null)
            {
                return(null);
            }

            if (node.NodeType == TrieNode.TrieNodeType.BranchNode)
            {
                if (key.IsEmpty)
                {
                    return(node.BranchNodeGetValue());
                }
                TrieNode child = node.BranchNodeGetChild(key.GetHex(0));
                return(Get(child, key.Shift(1)));
            }
            else
            {
                TrieKey k = key.MatchAndShift(node.KVNodeGetKey());
                if (k == null)
                {
                    return(null);
                }

                if (node.NodeType == TrieNode.TrieNodeType.KVNodeValue)
                {
                    return(k.IsEmpty ? node.KVNodeGetValue() : null);
                }
                else
                {
                    return(Get(node.KVNodeGetChildNode(), k));
                }
            }
        }
Esempio n. 2
0
        public void ScanTree(TrieNode node, TrieKey key, IScanAction scan_action)
        {
            if (node != null)
            {
                if (node.Hash != null)
                {
                    scan_action.OnNode(node.Hash, node);
                }

                if (node.NodeType == TrieNode.TrieNodeType.BranchNode)
                {
                    if (node.BranchNodeGetValue() != null)
                    {
                        scan_action.OnValue(node.Hash, node, key.ToNormal(), node.BranchNodeGetValue());
                    }

                    for (int i = 0; i < 16; i++)
                    {
                        ScanTree(node.BranchNodeGetChild(i), key.Concat(TrieKey.SingleHex(i)), scan_action);
                    }
                }
                else if (node.NodeType == TrieNode.TrieNodeType.KVNodeNode)
                {
                    ScanTree(node.KVNodeGetChildNode(), key.Concat(node.KVNodeGetKey()), scan_action);
                }
                else
                {
                    scan_action.OnValue(node.Hash, node, key.Concat(node.KVNodeGetKey()).ToNormal(), node.KVNodeGetValue());
                }
            }
        }