com.knowgate.cache
Class ExpireableCache.MyHeap

java.lang.Object
  extended by com.knowgate.cache.ExpireableCache.MyHeap
Enclosing class:
ExpireableCache

protected class ExpireableCache.MyHeap
extends java.lang.Object

Implement a simple heap that just returns the smallest long variable/Object key pair.


Method Summary
protected  void decrease(int cur_pos)
          Lower an element in the heap structure Note that the cur_pos is actually one larger than the position in the array!
protected  void increase(int cur_pos)
          Lift an element in the heap structure Note that the cur_pos is actually one larger than the position in the array!
 void insert(java.lang.Object key, long value)
          Insert a key/value pair Reorganize Heap afterwards
 java.lang.Object next()
          Return and delete the key with the lowest long value.
 long peek()
          Return timestamp with the lowest value.
 void remove(java.lang.Object key)
          Remove an Object from the Heap.
 int size()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

size

public int size()

insert

public void insert(java.lang.Object key,
                   long value)
Insert a key/value pair Reorganize Heap afterwards


peek

public long peek()
          throws java.lang.ArrayIndexOutOfBoundsException
Return timestamp with the lowest value. Does not delete key nor reorganize heap.

Throws:
java.lang.ArrayIndexOutOfBoundsException

next

public java.lang.Object next()
                      throws java.lang.ArrayIndexOutOfBoundsException
Return and delete the key with the lowest long value. Reorganize Heap.

Throws:
java.lang.ArrayIndexOutOfBoundsException

remove

public void remove(java.lang.Object key)
Remove an Object from the Heap. Unfortunately not (yet) of very good complexity since we are doing a simple linear search here.

Parameters:
key - The key to remove from the heap

increase

protected void increase(int cur_pos)
Lift an element in the heap structure Note that the cur_pos is actually one larger than the position in the array!


decrease

protected void decrease(int cur_pos)
Lower an element in the heap structure Note that the cur_pos is actually one larger than the position in the array!