public override void Add(KeyValuePair <TKey, TValue> pair)
 {
     DoReadWriteNotify(
         () => _sorter.GetInsertIndex(_internalCollection.Count, pair.Key, i => _internalCollection.List[i].Key),
         (index) => _internalCollection.Insert(index, pair),
         (index) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, pair, index)
         );
 }
コード例 #2
0
 protected override int IListAdd(T item)
 {
     return(DoReadWriteNotify(
                () => _sorter.GetInsertIndex(ImmutableList.Count, item, i => _internalCollection[i]),
                (index) => ImmutableList.Insert(index, item),
                (index) => new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item, index)
                ));
 }
コード例 #3
0
        protected override void InsertItem(int index, TKey item)
        {
            // Sorted list, throw away the index and work out the correct position

            int sortedIndex = _sorter.GetInsertIndex(this.Count, item, delegate(int mid){
                return(this[mid]);
            });

            base.InsertItem(sortedIndex, item);
        }
コード例 #4
0
        /// <summary>
        /// Adds an element with the provided key and value to the IDictionary<TKey, TValue>.
        /// </summary>
        /// <param name="key">
        /// The object to use as the key of the element to add.
        /// </param>
        /// <param name="value">
        /// The object to use as the value of the element to add.
        /// </param>
        public override void Add(TKey key, TValue value)
        {
            int index = _sorter.GetInsertIndex(_masterList.Count, key, delegate(int mid){
                return(_masterList[mid].Key);
            });

            if (index >= _masterList.Count)
            {
                base.Add(key, value);
            }
            else
            {
                TKey listKey = _masterList[index].Key;
                DoubleLinkListIndexNode next    = _keyToIndex[listKey];
                DoubleLinkListIndexNode newNode = new DoubleLinkListIndexNode(next.Previous, next);
                _keyToIndex[key] = newNode;
                _masterList.Insert(index, new KeyValuePair <TKey, TValue>(key, value));
            }
        }
        /// <summary>
        /// Adds an element with the provided key and value to the IDictionary<TKey, TValue>.
        /// </summary>
        /// <param name="key">
        /// The object to use as the key of the element to add.
        /// </param>
        /// <param name="value">
        /// The object to use as the value of the element to add.
        /// </param>
        protected override void BaseAdd(TKey key, TValue value)
        {
            int index = _sorter.GetInsertIndex(WriteCollection.Count, key, delegate(int testIndex) {
                return(WriteCollection[testIndex].Key);
            });

            if (index >= WriteCollection.Count)
            {
                base.BaseAdd(key, value);
            }
            else
            {
                TKey listKey = WriteCollection[index].Key;
                DoubleLinkListIndexNode next    = _keyToIndex[listKey];
                DoubleLinkListIndexNode newNode = new DoubleLinkListIndexNode(next.Previous, next);
                _keyToIndex[key] = newNode;
                WriteCollection.Insert(index, new KeyValuePair <TKey, TValue>(key, value));
            }
        }
コード例 #6
0
        public void Add(T item)
        {
            int index = _sorter.GetInsertIndex(_list.Count, item, i => _list[i]);

            _list.Insert(index, item);
        }