|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbyucc.jhdl.base.list.VectorList
This is a variation of the original byucc.jhdl.base.list.LinkedList, that provides improved efficiency of memory usage and access time by utilizing java.util.Vector. Since Vector includes capacityIncrement, but only uses it when 'growing' the data array with methods like addElement(), I use (or is that abuse) this field instead of spending more memory on another field to keep track of the current element. VectorLists are ideal for small lists, and favors insert. Large lists, however, are better implemented with LinkedLists, since the cost of resizing the vector and the wasted space are worse than the savings in speed of insert and traversal. Traversal is O(1), insert is between O(1) and O(log n) since every time the list doubles a larger chunk of memory must be allocated and the vector's data relocated, append is O(n log n) by the same reasoning, random access could be added as O(1), inList, deleteCurrent, delete, intersect, and appendList are O(n); but for small lists, almost all of these methods are faster than their counterparts in LinkedList.
Constructor Summary | |
VectorList()
|
Method Summary | |
protected void |
append(java.lang.Object elt)
Appends element to list, for FIFO behavior; not as efficient as insert. |
protected void |
appendList(VectorList lst)
Appends contents of argument to calling list (this), in same order. |
boolean |
atEnd()
Checks if more elements remain for list traversal. |
boolean |
delete(java.lang.Object elt)
Deletes all occurances of element within a list, and reinitializes list. |
void |
deleteAll()
Erases the list. |
void |
deleteCurrent()
Deletes element at current position in list. |
int |
elementCount()
Returns size of list. |
boolean |
empty()
Checks if the list has elements. |
protected VectorList |
filter(Predicate pred)
Filters a list in place, preserving only the elements for which Predicate.accept() returns true. |
protected java.lang.Object |
getElt()
Returns element at current list position, or null if at list end. |
void |
init()
Initializes the list so that the current pointer is on the list head (if the list is built with insert(), this is the most recent insert()). |
boolean |
inList(java.lang.Object o)
Checks if object appears in the list. |
protected void |
insert(java.lang.Object elt)
Inserts element in the list in chronological order, for LIFO behavior. |
protected void |
insertAfterCurrent(java.lang.Object elt)
Inserts element after current element of list, appending if current is at end of list. |
protected void |
insertBeforeCurrent(java.lang.Object elt)
Inserts element before current pointer, appending if at the end of the list. |
protected void |
insertList(VectorList lst)
Inserts contents of argument to calling list (this), in reverse order. |
protected VectorList |
intersect(VectorList ret_list,
VectorList lst)
Returns the intersection of argument and calling list (this), without modifying either calling list or argument. |
java.util.Iterator |
iterator()
|
protected void |
merge(VectorList other_list)
|
void |
next()
Advances the current pointer to the next element. |
void |
prev()
Advances the current pointer to the previous element. |
int |
size()
Returns the size of the list |
java.lang.String |
toString()
Prints out a representation of the contents of this list |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public VectorList()
Method Detail |
public void init()
init
in interface List
public java.util.Iterator iterator()
public final boolean empty()
public void next()
next
in interface List
public void prev()
prev
in interface List
protected final java.lang.Object getElt()
public boolean atEnd()
atEnd
in interface List
public final boolean inList(java.lang.Object o)
inList
in interface List
o
- object to look for.
public final void deleteCurrent()
protected final void insert(java.lang.Object elt)
elt
- the object to insert.protected final void append(java.lang.Object elt)
elt
- the object to append.protected final void insertAfterCurrent(java.lang.Object elt)
elt
- the object to insert.protected final void insertBeforeCurrent(java.lang.Object elt)
elt
- the object to insertprotected final VectorList intersect(VectorList ret_list, VectorList lst)
ret_list
- The empty list that will be returned with the result (must be passed a list, because reflection cannot always generate the correct list type)lst
- the second list of intersection.
protected final void appendList(VectorList lst)
lst
- The list to append, will not be modified.
protected final void insertList(VectorList lst)
for (lst.init(); !lst.atEnd(); lst.next())
this.insert(lst.getElt());
. Override for typed List inserts.
lst
- The list to insert, will not be modified, but will be read in reverse order.
public final void deleteAll()
public final boolean delete(java.lang.Object elt)
elt
- the element to delete.
public final int elementCount()
elementCount
in interface List
protected void merge(VectorList other_list)
public java.lang.String toString()
protected VectorList filter(Predicate pred)
pred
- the predicate for determining list membership
public int size()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |