|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectkodkod.util.ints.AbstractSparseSequence<V>
kodkod.util.ints.RangeSequence<V>
public final class RangeSequence<V>
A tree-based sparse sequence implementation. Unlike TreeSequence
,
this is not a general-purpose sparse sequence implementation. In particular,
the entries with consecutive indices and the same value are not stored explicitly. As a result,
methods
that return an IndexedEntry
may re-use the same object.
Specifically, the last assertion in the following code snippet may fail.
// let s be a range sequence abstractly represented as { 0->v, 1->v, 2->v } IndexedEntrye1 = s.predecessor(2); assert e1.index()==1; // this will work IndexedEntry e2 = s.predecessor(1); assert e1.index()==1; // this may fail, as e1 may be == to e2
The entries returned by this implementation's AbstractSparseSequence.iterator()
are unique
to that iterator (but not necessarily independent of each other). For example,
// let s be a range sequence abstractly represented as { 0->v, 1->v, 2->v } Iterator> iter1 = s.iterator(); IndexedEntry e1 = iter1.next(); assert e1.index()==0; // this will work iter1.next(); assert e1.index()==0; // this may fail, as the previous call may have changed the state of e1 Iterator > iter2 = s.iterator(); IndexedEntry e2 = iter2.next(); iter1.next(); assert e2.index()==0; // this will work
This implementation is a good choice when the client expects the usage pattern with many consecutive indices mapped to the same value, and when there is no need for entry uniqueness.
Constructor Summary | |
---|---|
RangeSequence()
Constructs an empty RangeSequence. |
Method Summary | |
---|---|
IndexedEntry<V> |
ceil(int index)
Returns the entry whose index is the ceiling of the given index in this sequence. |
void |
clear()
Removes all entries from this sequences. |
RangeSequence<V> |
clone()
Returns a copy of this sparse sequence. |
boolean |
containsIndex(int index)
Returns true if this sparse sequence has an entry for the given index; otherwise returns false. |
IndexedEntry<V> |
first()
Returns the first element in this sequence, if any. |
IndexedEntry<V> |
floor(int index)
Returns the entry whose index is the floor of the given index in this sequence. |
V |
get(int index)
Returns the value to which this sequence maps the given index. |
java.util.Iterator<IndexedEntry<V>> |
iterator(int from,
int to)
Returns an iterator over the entries in this sequence, whose indeces are between from and to. |
IndexedEntry<V> |
last()
Returns the last element in this sequence, if any. |
V |
put(int index,
V value)
Throws an UnsupportedOperationException. |
V |
remove(int index)
Removes the entry with the given index, if it exists, and returns the value previously stored at the index. |
int |
size()
Returns the number of entries in this sequence. |
Methods inherited from class kodkod.util.ints.AbstractSparseSequence |
---|
contains, equals, hashCode, indices, isEmpty, iterator, putAll, toString, values |
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public RangeSequence()
no this.entries' |
Method Detail |
---|
public java.util.Iterator<IndexedEntry<V>> iterator(int from, int to)
iterator
in interface SparseSequence<V>
SparseSequence.iterator(int, int)
public int size()
size
in interface SparseSequence<V>
SparseSequence.size()
public void clear()
clear
in interface SparseSequence<V>
clear
in class AbstractSparseSequence<V>
SparseSequence.clear()
no this.entries' |
public V put(int index, V value)
put
in interface SparseSequence<V>
put
in class AbstractSparseSequence<V>
SparseSequence.put(int, Object)
public V get(int index)
get
in interface SparseSequence<V>
SparseSequence.get(int)
public V remove(int index)
remove
in interface SparseSequence<V>
remove
in class AbstractSparseSequence<V>
SparseSequence.remove(int)
this.entries' = this.entries - index->E |
public boolean containsIndex(int index)
containsIndex
in interface SparseSequence<V>
containsIndex
in class AbstractSparseSequence<V>
SparseSequence.containsIndex(int)
public IndexedEntry<V> first()
first
in interface SparseSequence<V>
first
in class AbstractSparseSequence<V>
SparseSequence.first()
public IndexedEntry<V> last()
last
in interface SparseSequence<V>
last
in class AbstractSparseSequence<V>
SparseSequence.last()
public IndexedEntry<V> ceil(int index)
ceil
in interface SparseSequence<V>
ceil
in class AbstractSparseSequence<V>
SparseSequence.ceil(int)
public IndexedEntry<V> floor(int index)
floor
in interface SparseSequence<V>
floor
in class AbstractSparseSequence<V>
SparseSequence.floor(int)
public RangeSequence<V> clone()
clone
in interface SparseSequence<V>
clone
in class AbstractSparseSequence<V>
SparseSequence.clone()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |