コード例 #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);
 }