Exemplo n.º 1
0
        /// <summary>
        /// Attempts to removes the specified key.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="offset">The offset from the default index.</param>
        /// <returns>The index where the value was set; -1 otherwise.</returns>
        public int Remove(TKey key, int offset)
        {
            int index = Index(key, offset);
            KeyValuePair <TKey, TValue> entry;

            if (_entries.TryGet(index, out entry))
            {
                if (_keyComparer.Equals(entry.Key, key))
                {
                    if (_entries.RemoveAt(index))
                    {
                        return(index);
                    }
                    else
                    {
                        return(-1);
                    }
                }
                else
                {
                    return(-1);
                }
            }
            else
            {
                return(-1);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Attempts to removes the specified item.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="offset">The offset from the default index.</param>
        /// <returns>The index where the item was set; -1 otherwise.</returns>
        public int Remove(T item, int offset)
        {
            int index = Index(item, offset);
            T   entry;

            if (_entries.TryGet(index, out entry))
            {
                if (_comparer.Equals(entry, item))
                {
                    if (_entries.RemoveAt(index))
                    {
                        return(index);
                    }
                    else
                    {
                        return(-1);
                    }
                }
                else
                {
                    return(-1);
                }
            }
            else
            {
                return(-1);
            }
        }
Exemplo n.º 3
0
        protected static void UnRoot(Timeout timeout)
        {
            var rootIndex = Interlocked.Exchange(ref timeout._rootIndex, -1);

            if (rootIndex != -1)
            {
                _root.RemoveAt(rootIndex);
            }
        }
Exemplo n.º 4
0
        private static void UnRoot(RootedTimeout rootedTimeout)
        {
            var rootIndex = Interlocked.Exchange(ref rootedTimeout._rootIndex, -1);

            if (rootIndex != -1)
            {
                _root.RemoveAt(rootIndex);
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Attempts to retrieve and remove the next item from the back.
 /// </summary>
 /// <param name="item">The item.</param>
 /// <returns>
 ///   <c>true</c> if the item was taken; otherwise, <c>false</c>.
 /// </returns>
 public bool TryDequeue(out T item)
 {
     if (_bucket.Count > 0)
     {
         var preCount = Interlocked.Decrement(ref _preCount);
         if (preCount >= 0)
         {
             var index = (Interlocked.Increment(ref _indexDequeue) - 1) & (_capacity - 1);
             if (_bucket.RemoveAt(index, out item))
             {
                 return(true);
             }
         }
         Interlocked.Increment(ref _preCount);
     }
     item = default(T);
     return(false);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Removes the item at the specified index.
 /// </summary>
 /// <param name="index">The index.</param>
 /// <returns>
 ///   <c>true</c> if the item was removed; 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 RemoveAt(int index)
 {
     return(_bucket.RemoveAt(index));
 }
Exemplo n.º 7
0
 /// <summary>
 /// Removes the item at the specified index.
 /// </summary>
 /// <param name="index">The index.</param>
 /// <returns>
 ///   <c>true</c> if the item was removed; 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 RemoveAt(int index)
 {
     return(_wrapped.RemoveAt(index));
 }