public class IntIterableRangeSet extends Object implements IntIterableSet
IntIterableSet wherein values are stored in range set.
A range is made of two ints, the lower bound and the upper bound of the range.
A range can be a singleton, in that case, the lb and the ub are equal.
If the upper bound of range A is equal to lower bound of range B, then the two ranges can be merged into a single one.
Project: choco.
| Modifier and Type | Field and Description |
|---|---|
protected int |
CARDINALITY
Total number of elements in the set
|
protected int[] |
ELEMENTS
Store elements
|
protected int |
SIZE
Used size in
ELEMENTS. |
| Constructor and Description |
|---|
IntIterableRangeSet()
Create an interval-based ordered set
|
IntIterableRangeSet(int e)
Create an interval-based ordered set initialized to singleton {e}
|
IntIterableRangeSet(int[] values)
Create an interval-based ordered set initialized to an array of values
|
IntIterableRangeSet(int a,
int b)
Create an interval-based ordered set initialized to [a,b]
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(int e)
Add element to the set
|
boolean |
addAll(int... values)
Adds all of the elements in the array to this set.
|
boolean |
addAll(IntIterableSet set)
Adds all of the elements in the specified set to this set.
|
void |
clear()
Remove all elements from the set
|
boolean |
contains(int o)
Test the existence of element in the set
|
IntIterableSet |
duplicate()
Returns a carbon-copy of this set
|
SetType |
getSetType() |
ISetIterator |
iterator()
Use the following loop to iterate over this set without autoboxing.
|
int |
max() |
int |
min() |
void |
minus(int x)
subtract the value x to all integers stored in this set
|
ISetIterator |
newIterator()
Creates a new iterator object, for nested loops only.
|
int |
nextValue(int e) |
void |
plus(int x)
add the value x to all integers stored in this set
|
int |
previousValue(int e) |
protected int |
rangeOf(int x)
By convention, range are numbered starting from 1 (not 0).
|
boolean |
remove(int e)
Remove the first occurrence of element from the set
|
boolean |
removeAll(IntIterableSet set)
Removes all of this set's elements that are also contained in the
specified set.
|
boolean |
removeBetween(int f,
int t)
Removes all values between f (inclusive) and t (inclusive)
|
boolean |
retainAll(IntIterableSet set)
Retains only the elements in this set that are contained in the
specified set.
|
int |
size() |
void |
times(int x)
multiply by x to all integers stored in this set
|
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitisEmpty, toArrayforEach, spliteratorprotected int[] ELEMENTS
protected int SIZE
ELEMENTS.
To get the number of range simply divide by 2.protected int CARDINALITY
public IntIterableRangeSet()
public IntIterableRangeSet(int a,
int b)
a - lower bound of the intervalb - upper bound of the intervalpublic IntIterableRangeSet(int e)
e - singleton valuepublic IntIterableRangeSet(int[] values)
values - some valuespublic int min()
public int max()
public boolean add(int e)
ISetpublic boolean addAll(int... values)
IntIterableSetaddAll in interface IntIterableSetvalues - array containing elements to be added to this settrue if this set changed as a result of the callpublic boolean addAll(IntIterableSet set)
IntIterableSetaddAll in interface IntIterableSetset - set containing elements to be added to this settrue if this set changed as a result of the callpublic boolean retainAll(IntIterableSet set)
IntIterableSetretainAll in interface IntIterableSetset - set containing elements to be retained in this setpublic boolean remove(int e)
ISetpublic boolean removeAll(IntIterableSet set)
IntIterableSetremoveAll in interface IntIterableSetset - set containing elements to be removed from this setpublic void clear()
ISetpublic SetType getSetType()
getSetType in interface ISetpublic boolean removeBetween(int f,
int t)
IntIterableSetremoveBetween in interface IntIterableSetf - first value to removet - last value to removepublic int nextValue(int e)
nextValue in interface IntIterableSete - (exclusive)public int previousValue(int e)
previousValue in interface IntIterableSete - (exclusive)public boolean contains(int o)
ISetpublic IntIterableSet duplicate()
IntIterableSetduplicate in interface IntIterableSetpublic int size()
public ISetIterator newIterator()
ISetnewIterator in interface ISetpublic void plus(int x)
plus in interface IntIterableSetx - value to addpublic ISetIterator iterator()
ISet
// more readable but with autoboxing
for(int value:set){
...
}
// more verbose but without autoboxing
ISetIterator iter = set.primitiveIterator();
while(iter.hasNext()){
int k = iter.next();
...
}
Do not use this iterator to make nested loops over ISet (prefer ISet.newIterator())public void minus(int x)
minus in interface IntIterableSetx - value to addpublic void times(int x)
x - value to addprotected int rangeOf(int x)
x - a valueCopyright © 2017. All rights reserved.