Exemple #1
0
        public static TrieKey SingleHex(int hex)
        {
            TrieKey ret = new TrieKey(new byte[1], 1, false);

            ret.SetHex(0, hex);
            return(ret);
        }
Exemple #2
0
        public TrieKey Concat(TrieKey k)
        {
            if (IsTerminal)
            {
                throw new System.Exception("Can' append to terminal key: " + this + " + " + k);
            }
            int len     = GetLength();
            int klen    = k.GetLength();
            int new_len = len + klen;

            byte[]  newKeyBytes = new byte[(new_len + 1) >> 1];
            TrieKey ret         = new TrieKey(newKeyBytes, new_len & 1, k.IsTerminal);

            for (int i = 0; i < len; i++)
            {
                ret.SetHex(i, GetHex(i));
            }
            for (int i = 0; i < klen; i++)
            {
                ret.SetHex(len + i, k.GetHex(i));
            }
            return(ret);
        }
Exemple #3
0
        public TrieKey GetCommonPrefix(TrieKey k)
        {
            int prefix_length = 0;
            int thisLength    = GetLength();
            int klen          = k.GetLength();

            while (prefix_length < thisLength && prefix_length < klen && GetHex(prefix_length) == k.GetHex(prefix_length))
            {
                prefix_length++;
            }
            byte[]  prefix_key = new byte[(prefix_length + 1) >> 1];
            TrieKey ret        = new TrieKey(prefix_key, (prefix_length & 1) == 0 ? 0 : 1,
                                             prefix_length == GetLength() && prefix_length == k.GetLength() && terminal && k.IsTerminal);

            for (int i = 0; i < prefix_length; i++)
            {
                ret.SetHex(i, k.GetHex(i));
            }
            return(ret);
        }