コード例 #1
0
        /// <summary>
        /// Looks up a key value in the trie.
        /// </summary>
        /// <param name="key">The key to look up.</param>
        /// <returns>The exact matching <see cref="BinaryTrieNode"/> in the trie.</returns>
        public BinaryTrieNode FindExactMatch(Int32 key)
        {
            if ((key ^ _key) == 0)
            {
                return(this);
            }

            // Pick the child to investigate.
            if ((key & _bit[_keyLength + 1]) == 0)
            {
                // If the key matches the child's key, pass on the request.
                if (null != _zero)
                {
                    if ((key ^ _zero._key) < _bit[_zero._keyLength])
                    {
                        return(_zero.FindExactMatch(key));
                    }
                }
            }
            else
            {
                // If the key matches the child's key, pass on the request.
                if (null != _one)
                {
                    if ((key ^ _one._key) < _bit[_one._keyLength])
                    {
                        return(_one.FindExactMatch(key));
                    }
                }
            }
            // If we got here, neither child was a match, so the current
            // node is the best match.
            return(null);
        }
コード例 #2
0
        /// <summary>
        /// Finds the exact internal match for a key.
        /// </summary>
        /// <param name="index">
        /// The index of the root <see cref="BinaryTrieNode"/> for the given key value.
        /// </param>
        /// <param name="key">An <see cref="Int32"/> key value.</param>
        /// <returns>A reference to the <see cref="Object"/> containing the key.</returns>
        protected Object FindExactMatchInternal(Int32 index, Int32 key)
        {
            BinaryTrieNode root = _roots[index];

            if (null == root)
            {
                return(null);
            }
            return(root.FindExactMatch(key).UserData);
        }