예제 #1
0
        private static int IndexOfNull <TValue>(
            byte[] buffer,
            int index,
            int count,
            ref BsonTrieNode <TValue> bsonTrieNode)
        {
            for (; count > 0; index++, count--)
            {
                // bsonTrieNode might be null on entry or it might become null while navigating the trie
                if (bsonTrieNode == null)
                {
                    return(Array.IndexOf <byte>(buffer, 0, index, count));
                }

                var keyByte = buffer[index];
                if (keyByte == 0)
                {
                    return(index);
                }

                bsonTrieNode = bsonTrieNode.GetChild(keyByte); // might return null
            }

            return(-1);
        }
예제 #2
0
        /// <summary>
        /// Gets the node associated with the specified element name.
        /// </summary>
        /// <param name="utf8">The element name.</param>
        /// <param name="node">
        /// When this method returns, contains the node associated with the specified element name, if the key is found;
        /// otherwise, null. This parameter is passed unitialized.
        /// </param>
        /// <returns>True if the node was found; otherwise, false.</returns>
        public bool TryGetNode(ArraySegment <byte> utf8, out BsonTrieNode <TValue> node)
        {
            node = _root;
            for (var i = 0; node != null && i < utf8.Count; i++)
            {
                var keyByte = utf8.Array[utf8.Offset + i];
                node = node.GetChild(keyByte);
            }

            return(node != null);
        }