Esempio n. 1
0
        private IEnumerable <RWayNode <TValue> > Traversal(RWayNode <TValue> node)
        {
            var stack = new Stack <RWayNode <TValue> >();

            stack.Push(node);

            while (stack.Count > 0)
            {
                var n = stack.Pop();
                yield return(n);

                foreach (var child in node)
                {
                    stack.Push(child);
                }
            }
        }
Esempio n. 2
0
        private void Insert(String key, TValue value, bool update)
        {
            if (_root == null)
            {
                _root = new RWayNode <TValue>();
            }

            var node = _root;

            var bytes = _encoding.GetBytes(key);

            for (int i = 0; i < bytes.Length; i++)
            {
                var @byte = bytes[i];

                var child = node[@byte];
                if (child == null)
                {
                    child = new RWayNode <TValue> {
                        Byte = @byte
                    };

                    node[@byte] = child;
                }

                node = child;
            }

            if (!update && node.IsLeaf)
            {
                throw new Exception();
            }

            node.Key    = key;
            node.IsLeaf = true;
            node.Value  = value;
        }