|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jgroup.util.IntList
public final class IntList
The IntList
class represents ordered lists of integers.
This class has been optimized to maintain list of integers
containing long sequence of consecutive numbers. It is particularly
useful for maintaining list of received ack numbers, that are
normally consecutive (except in the case of connectivity problems).
The list is maintained by a chain of integer pairs; in each pair, the first integer represents the beginning of a consecutive sequence, while the second integer represents the end of a consecutive sequence.
For example, a list of this type:
1 2 3 4 5 7 8 9 10 11 13 14 15 16 17 18 19 20 21 22 23is mantained in this way:
(1-5),(7-11),(13-23)thus saving both memory and time to scan a list searching for a number.
IntList
contains methods to add, lookup and remove
integers, and to merge the contents of other IntList
s.
Implementation note: As mentioned, IntList
is based on a
linked list of pairs. Each of these pairs are IntList
objects, to avoid the need to introduce a inner class to hold pairs.
For this reason, each integer list starts with an "empty"
IntList
containing no pair. The first pair of an
IntList
l is contained in l.next
.
Constructor Summary | |
---|---|
IntList()
Build an empty IntList . |
Method Summary | |
---|---|
void |
clean()
Clear the content of this IntList . |
boolean |
contains(int key)
Returns true if value key is contained in this
IntList . |
IntList |
copy()
Deep clone this IntList . |
int |
getFirst()
Returns the first element of the list, or -1 if the list is empty. |
int |
getLast()
Returns the last element of the list, or -1 if the list is empty. |
int |
getMaxConsecutive()
Returns the end value of the first consecutive sequence of integers contained in the list. |
void |
insert(int key)
Insert value key in the IntList . |
boolean |
isEmpty()
Returns true if the list is empty; false otherwise. |
void |
merge(IntList addend)
Merge IntList addend to the IntList . |
void |
readExternal(java.io.ObjectInput in)
Restores the content of this object from the marshalled data contained in the specified input stream. |
void |
remove(int key)
Remove value key from the IntList . |
void |
remove(int start,
int stop)
Remove range from start to stop . |
void |
remove(IntList removed)
Remove IntList removed from the IntList . |
int |
removeFirst()
Returns and removes the first element of the list; -1 is returned if the list is empty. |
IntList |
split(int key)
Split the IntList at position key ,
leaving the upper part in this IntList , while
returning the lower part of the list, key inclusive. |
int[] |
toIntArray()
Return an int array containing the values contained
in this IntList . |
java.lang.String |
toString()
Returns a string representation of this object |
void |
writeExternal(java.io.ObjectOutput out)
Write the contents of this IntList to
the object output stream out . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public IntList()
IntList
.
Method Detail |
---|
public int getFirst()
public int getLast()
public boolean isEmpty()
public int getMaxConsecutive()
1 2 3 4 5 7 8 9 10 11this methods return 5. If the list is empty, it returns -1.
public boolean contains(int key)
key
is contained in this
IntList
.
public void insert(int key)
key
in the IntList
.
public void merge(IntList addend)
IntList addend
to the IntList
.
public IntList split(int key)
IntList
at position key
,
leaving the upper part in this IntList
, while
returning the lower part of the list, key
inclusive.
key
- the position in the list to make the split.
public void remove(int start, int stop)
start
to stop
. If
stop
is zero, the remainder of the list is deleted.
public int removeFirst()
public void remove(int key)
key
from the IntList
.
public void remove(IntList removed)
IntList removed
from the IntList
.
public int[] toIntArray()
int
array containing the values contained
in this IntList
.
public void clean()
IntList
.
public IntList copy()
IntList
.
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
IntList
to
the object output stream out
. The external
format of the string is the following: each pair is
written to the stream, terminated by -1.
writeExternal
in interface java.io.Externalizable
out
- the stream to be written
java.io.IOException
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
readExternal
in interface java.io.Externalizable
in
- the stream to be read
java.io.IOException
java.lang.ClassNotFoundException
public java.lang.String toString()
toString
in class java.lang.Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |