コード例 #1
0
 private void addToStackBottom(Entry<V> e) {
   e.stackNext = stack;
   e.stackPrev = stack.stackPrev;
   e.stackPrev.stackNext = e;
   stack.stackPrev = e;
   stackSize++;
 }
コード例 #2
0
 private void addToStack(Entry<V> e) {
   e.stackPrev = stack;
   e.stackNext = stack.stackNext;
   e.stackNext.stackPrev = e;
   stack.stackNext = e;
   stackSize++;
   e.topMove = stackMoveCounter++;
 }
コード例 #3
0
    /**
     * Create a new cache segment.
     *
     * @param maxMemory the maximum memory to use
     * @param stackMoveDistance the number of other entries to be moved to the top of the stack
     *     before moving an entry to the top
     * @param len the number of hash table buckets (must be a power of 2)
     */
    Segment(long maxMemory, int stackMoveDistance, int len) {
      setMaxMemory(maxMemory);
      this.stackMoveDistance = stackMoveDistance;

      // the bit mask has all bits set
      mask = len - 1;

      // initialize the stack and queue heads
      stack = new Entry<V>();
      stack.stackPrev = stack.stackNext = stack;
      queue = new Entry<V>();
      queue.queuePrev = queue.queueNext = queue;
      queue2 = new Entry<V>();
      queue2.queuePrev = queue2.queueNext = queue2;

      @SuppressWarnings("unchecked")
      Entry<V>[] e = new Entry[len];
      entries = e;
    }
コード例 #4
0
 /**
  * Remove the entry from the stack. The head itself must not be removed.
  *
  * @param e the entry
  */
 private void removeFromStack(Entry<V> e) {
   e.stackPrev.stackNext = e.stackNext;
   e.stackNext.stackPrev = e.stackPrev;
   e.stackPrev = e.stackNext = null;
   stackSize--;
 }