Exemplo n.º 1
0
 private ImHashMap(Data data, ImHashMap <K, V> left, ImHashMap <K, V> right, int height)
 {
     _data  = data;
     Left   = left;
     Right  = right;
     Height = height;
 }
Exemplo n.º 2
0
 private ImHashMap(Data data)
 {
     _data  = data;
     Left   = Empty;
     Right  = Empty;
     Height = 1;
 }
Exemplo n.º 3
0
 private ImHashMap(Data data, ImHashMap <K, V> left, ImHashMap <K, V> right)
 {
     _data  = data;
     Left   = left;
     Right  = right;
     Height = 1 + (left.Height > right.Height ? left.Height : right.Height);
 }
Exemplo n.º 4
0
        /// <summary>
        ///     Depth-first in-order traversal as described in http://en.wikipedia.org/wiki/Tree_traversal
        ///     The only difference is using fixed size array instead of stack for speed-up (~20% faster than stack).
        /// </summary>
        /// <returns>Sequence of enumerated key value pairs.</returns>
        public IEnumerable <KV <K, V> > Enumerate()
        {
            if (Height == 0)
            {
                yield break;
            }

            var parents = new ImHashMap <K, V> [Height];

            var node        = this;
            var parentCount = -1;

            while (node.Height != 0 || parentCount != -1)
            {
                if (node.Height != 0)
                {
                    parents[++parentCount] = node;
                    node = node.Left;
                }
                else
                {
                    node = parents[parentCount--];
                    yield return(new KV <K, V>(node.Key, node.Value));

                    if (node.Conflicts != null)
                    {
                        for (var i = 0; i < node.Conflicts.Length; i++)
                        {
                            yield return(node.Conflicts[i]);
                        }
                    }

                    node = node.Right;
                }
            }
        }
Exemplo n.º 5
0
 private ImHashMap <K, V> With(ImHashMap <K, V> left, ImHashMap <K, V> right)
 {
     return(left == Left && right == Right ? this : new ImHashMap <K, V>(_data, left, right));
 }