Ejemplo n.º 1
0
            internal Enumerator(SortedTable <TKey, TValue> table)
            {
                _table = table;
                _index = 0;

                _pair    = default(KeyValuePair <TKey, TValue>);
                _version = _table._version;
            }
Ejemplo n.º 2
0
            public ValueEnumerator(SortedTable <TKey, TValue> table)
            {
                _table = table;
                _index = 0;

                _value   = default(TValue);
                _version = _table._version;
            }
Ejemplo n.º 3
0
            internal KeyEnumerator(SortedTable <TKey, TValue> table)
            {
                _table = table;
                _index = 0;

                _key     = default(TKey);
                _version = _table._version;
            }
Ejemplo n.º 4
0
 internal KeyList(SortedTable <TKey, TValue> table)
 {
     _table = table;
 }
Ejemplo n.º 5
0
        public void Merge(SortedTable <TKey, TValue> other)
        {
            if (null == other || other.Count == 0)
            {
                return;
            }

            var counter1 = Count;
            var counter2 = other.Count;
            var capacity = counter1 + counter2;

            var keys   = new TKey[capacity];
            var values = new TValue[capacity];

            int currentIndex = 0;
            int index1       = 0;
            int index2       = 0;

            while (index1 < counter1 && index2 < counter2)
            {
                var key1 = _keys[index1];
                var key2 = other._keys[index2];

                var flags = _comparer.Compare(key1, key2);
                if (flags < 0)
                {
                    keys[currentIndex]   = key1;
                    values[currentIndex] = _values[index1];
                    ++index1;
                }
                else if (flags > 0)
                {
                    keys[currentIndex]   = key2;
                    values[currentIndex] = other._values[index2];
                    ++index2;
                }
                else
                {
                    keys[currentIndex]   = key2;
                    values[currentIndex] = other._values[index2];
                    ++index2;
                    ++index1;
                }

                ++currentIndex;
            }

            while (index1 < counter1)
            {
                keys[currentIndex]   = _keys[index1];
                values[currentIndex] = _values[index1];
                ++index1;
                ++currentIndex;
            }

            while (index2 < counter2)
            {
                keys[currentIndex]   = other._keys[index2];
                values[currentIndex] = other._values[index2];
                ++index2;
                ++currentIndex;
            }

            _keys     = keys;
            _values   = values;
            _size     = currentIndex;
            _capacity = capacity;
            ++_version;
        }