Пример #1
0
        public virtual T Find(sbyte[] bytes)
        {
            ByteTrieNode <T> node = _root;
            T value = node._value;

            foreach (sbyte b in bytes)
            {
                ByteTrieNode <T> child = node._children.Get(b);
                if (child == null)
                {
                    break;
                }
                node = child;
                if (node._value != null)
                {
                    value = node._value;
                }
            }
            return(value);
        }
        /// <summary>Store the given value at the specified path.</summary>
        public void Add(T value, params byte[][] parts)
        {
            var depth = 0;
            var node  = _root;

            foreach (var part in parts)
            {
                foreach (var b in part)
                {
                    if (!node.Children.TryGetValue(b, out ByteTrieNode child))
                    {
                        child            = new ByteTrieNode();
                        node.Children[b] = child;
                    }
                    node = child;
                    depth++;
                }
            }
            node.SetValue(value);
            MaxDepth = Math.Max(MaxDepth, depth);
        }
Пример #3
0
        /// <summary>Store the given value at the specified path.</summary>
        public virtual void AddPath(T value, params sbyte[][] parts)
        {
            int depth             = 0;
            ByteTrieNode <T> node = _root;

            foreach (sbyte[] part in parts)
            {
                foreach (sbyte b in part)
                {
                    ByteTrieNode <T> child = node._children.Get(b);
                    if (child == null)
                    {
                        child = new ByteTrieNode <T>();
                        node._children.Put(b, child);
                    }
                    node = child;
                    depth++;
                }
            }
            node.SetValue(value);
            _maxDepth = Math.Max(_maxDepth, depth);
        }