示例#1
0
文件: Deque.cs 项目: Erhannis/Jibu
        static private int CalculateNewCapacity(DequeFixed <T> d)
        {
            int newCapacity = d.Capacity;

            if (d.Count > newCapacity / 2)   //More than half full
            {
                newCapacity *= 2;
            }
            return(newCapacity);
        }
示例#2
0
文件: Deque.cs 项目: Erhannis/Jibu
 //This is only thread safe when called from the thread that owns the Deque.
 public void Push(T w)
 {
     if (!deque.Push(w))
     {
         DequeFixed <T> old   = deque;
         DequeFixed <T> other = new DequeFixed <T>(CalculateNewCapacity(deque));
         deque = other;
         MoveElements(old, other);
         other.Push(w);
     }
 }
示例#3
0
文件: Deque.cs 项目: Erhannis/Jibu
 static private void MoveElements(DequeFixed <T> old, DequeFixed <T> cur)
 {
     while (true)
     {
         T move = old.Steal();
         if (move == null)
         {
             break;
         }
         else
         {
             cur.Push(move);
         }
     }
 }
示例#4
0
文件: Deque.cs 项目: Erhannis/Jibu
 public Deque(int initialSize)
 {
     deque = new DequeFixed <T>(initialSize);
 }