/// <summary> /// Adds the specified item. /// </summary> /// <param name="item">The item.</param> /// <returns>Returns the position where the item was added.</returns> public int Add(T item) { var index = Interlocked.Increment(ref _index) & (_capacity - 1); bool isNew; _bucket.Set(index, item, out isNew); return(index); }
/// <summary> /// Sets the value associated with the specified key. /// </summary> /// <param name="key">The key.</param> /// <param name="value">The value.</param> /// <param name="offset">The offset from the default index.</param> /// <param name="isNew">if set to <c>true</c> the key was not present before.</param> /// <returns>The index where the value was set; -1 otherwise.</returns> public int Set(TKey key, TValue value, int offset, out bool isNew) { int index = Index(key, offset); KeyValuePair <TKey, TValue> oldEntry; isNew = !_entries.TryGet(index, out oldEntry); if ((isNew || _keyComparer.Equals(key, oldEntry.Key)) && _entries.Set(index, new KeyValuePair <TKey, TValue>(key, value), out isNew)) { return(index); } else { return(-1); } }
//Hack internal int Set(T item, int offset, out bool isNew) { int index = Index(item, offset); T oldEntry; isNew = !_entries.TryGet(index, out oldEntry); if ((isNew || _comparer.Equals(item, oldEntry)) && _entries.Set(index, item, out isNew)) { return(index); } else { return(-1); } }
//HACK internal bool Set(int index, T item, out bool isNew) { if (_bucket.Set(index, item, out isNew)) { if (isNew) { Interlocked.Increment(ref _preCount); } return(true); } else { return(false); } }
protected static void Root(Timeout timeout) { timeout._rootIndex = Interlocked.Increment(ref _lastRootIndex); _root.Set(timeout._rootIndex, timeout); }
protected static void Root(RootedTimeout rootedTimeout) { rootedTimeout._rootIndex = Interlocked.Increment(ref _lastRootIndex); _root.Set(rootedTimeout._rootIndex, rootedTimeout); }
/// <summary> /// Sets the item at the specified index. /// </summary> /// <param name="index">The index.</param> /// <param name="item">The item.</param> /// <param name="isNew">if set to <c>true</c> the index was not previously used.</param> /// <returns> /// <c>true</c> if the item was set; otherwise, <c>false</c>. /// </returns> /// <exception cref="System.ArgumentOutOfRangeException">index;index must be greater or equal to 0 and less than capacity</exception> public bool Set(int index, T item, out bool isNew) { return(_wrapped.Set(index, item, out isNew)); }