Class IntIterableRangeSet
- java.lang.Object
-
- org.chocosolver.util.objects.setDataStructures.iterable.IntIterableRangeSet
-
- All Implemented Interfaces:
Iterable<Integer>
,ISet
,IntIterableSet
public class IntIterableRangeSet extends Object implements IntIterableSet
Concrete implementation ofIntIterableSet
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.
- Since:
- 14/01/2016.
- Author:
- Charles Prud'homme
-
-
Constructor Summary
Constructors Constructor Description IntIterableRangeSet()
Create an interval-based ordered setIntIterableRangeSet(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 valuesIntIterableRangeSet(int a, int b)
Create an interval-based ordered set initialized to [a,b]
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(int e)
Add element to the setboolean
addAll(int... values)
Adds all of the elements in the array to this set.boolean
addAll(IntIterableRangeSet set)
boolean
addAll(IntIterableSet set)
Adds all of the elements in the specified set to this set.boolean
addBetween(int a, int b)
int
cardinality()
void
clear()
Remove all elements from the setvoid
compact()
Compact the array in memoryboolean
contains(int o)
Test the existence of element in the setIntIterableRangeSet
copyFrom(IntIterableRangeSet me)
IntIterableRangeSet
duplicate()
Returns a carbon-copy of this setIntIterableRangeSet
flip()
Turn this into the complement of this.IntIterableRangeSet
flip(int lb, int ub)
Turn this into the complement of this.void
forEachValueIn(IntConsumer c)
Apply the operation c on each value in this setvoid
forEachValueOut(IntConsumer c)
int
getNbRanges()
SetType
getSetType()
ISetIterator
iterator()
Use the following loop to iterate over this set without autoboxing.int
max()
int
maxOfRange(int r)
int
min()
int
minOfRange(int r)
void
minus(int x)
subtract the value x to all integers stored in this setISetIterator
newIterator()
Creates a new iterator object, for nested loops only.int
nextValue(int e)
int
nextValueOut(int e)
void
plus(int x)
add the value x to all integers stored in this setint
previousValue(int e)
int
previousValueOut(int e)
int
rangeOf(int x)
By convention, range are numbered starting from 1 (not 0).protected int
rangeOf(int x, int fromIndex, int toIndex)
By convention, range are numbered starting from 1 (not 0).boolean
remove(int e)
Remove the first occurrence of element from the setboolean
removeAll(IntIterableRangeSet 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(IntIterableRangeSet set)
boolean
retainAll(IntIterableSet set)
Retains only the elements in this set that are contained in the specified set.boolean
retainBetween(int f, int t)
int
size()
void
times(int x)
multiply by x to all integers stored in this setint[]
toArray()
Copies the set in an array if integersString
toSmartString()
String
toString()
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Field Detail
-
MIN
public static final int MIN
- See Also:
- Constant Field Values
-
MAX
public static final int MAX
- See Also:
- Constant Field Values
-
ELEMENTS
protected int[] ELEMENTS
Store elements
-
SIZE
protected int SIZE
Used size inELEMENTS
. To get the number of range simply divide by 2.
-
CARDINALITY
protected int CARDINALITY
Total number of elements in the set
-
-
Constructor Detail
-
IntIterableRangeSet
public IntIterableRangeSet()
Create an interval-based ordered set
-
IntIterableRangeSet
public IntIterableRangeSet(int a, int b)
Create an interval-based ordered set initialized to [a,b]- Parameters:
a
- lower bound of the intervalb
- upper bound of the interval
-
IntIterableRangeSet
public IntIterableRangeSet(int e)
Create an interval-based ordered set initialized to singleton {e}- Parameters:
e
- singleton value
-
IntIterableRangeSet
public IntIterableRangeSet(int[] values)
Create an interval-based ordered set initialized to an array of values- Parameters:
values
- some values
-
-
Method Detail
-
toSmartString
public String toSmartString()
-
getNbRanges
public int getNbRanges()
- Returns:
- number of ranges in this
-
cardinality
public int cardinality()
-
minOfRange
public int minOfRange(int r)
-
maxOfRange
public int maxOfRange(int r)
-
min
public int min()
-
max
public int max()
-
add
public boolean add(int e)
Description copied from interface:ISet
Add element to the set
-
addAll
public boolean addAll(int... values)
Description copied from interface:IntIterableSet
Adds all of the elements in the array to this set.- Specified by:
addAll
in interfaceIntIterableSet
- Parameters:
values
- array containing elements to be added to this set- Returns:
true
if this set changed as a result of the call
-
addAll
public boolean addAll(IntIterableSet set)
Description copied from interface:IntIterableSet
Adds all of the elements in the specified set to this set.- Specified by:
addAll
in interfaceIntIterableSet
- Parameters:
set
- set containing elements to be added to this set- Returns:
true
if this set changed as a result of the call
-
addAll
public boolean addAll(IntIterableRangeSet set)
-
retainAll
public boolean retainAll(IntIterableSet set)
Description copied from interface:IntIterableSet
Retains only the elements in this set that are contained in the specified set. In other words, removes from this set all of its elements that are not contained in the specified set.- Specified by:
retainAll
in interfaceIntIterableSet
- Parameters:
set
- set containing elements to be retained in this set- Returns:
- true if this set changed as a result of the call
-
retainAll
public boolean retainAll(IntIterableRangeSet set)
-
remove
public boolean remove(int e)
Description copied from interface:ISet
Remove the first occurrence of element from the set
-
removeAll
public boolean removeAll(IntIterableSet set)
Description copied from interface:IntIterableSet
Removes all of this set's elements that are also contained in the specified set. After this call returns, this set will contain no elements in common with the specified set.- Specified by:
removeAll
in interfaceIntIterableSet
- Parameters:
set
- set containing elements to be removed from this set- Returns:
- true if this set changed as a result of the call
-
removeAll
public boolean removeAll(IntIterableRangeSet set)
-
clear
public void clear()
Description copied from interface:ISet
Remove all elements from the set
-
getSetType
public SetType getSetType()
- Specified by:
getSetType
in interfaceISet
- Returns:
- the implementation type of this set
-
addBetween
public boolean addBetween(int a, int b)
-
removeBetween
public boolean removeBetween(int f, int t)
Description copied from interface:IntIterableSet
Removes all values between f (inclusive) and t (inclusive)- Specified by:
removeBetween
in interfaceIntIterableSet
- Parameters:
f
- first value to removet
- last value to remove- Returns:
- true if this set changed as a result of the call
-
retainBetween
public boolean retainBetween(int f, int t)
-
nextValue
public int nextValue(int e)
- Specified by:
nextValue
in interfaceIntIterableSet
- Parameters:
e
- (exclusive)- Returns:
- the value after 'aValue' or
Integer.MAX_VALUE
-
nextValueOut
public int nextValueOut(int e)
- Specified by:
nextValueOut
in interfaceIntIterableSet
- Parameters:
e
- (exclusive)- Returns:
- the value outside thisn after 'aValue'
-
previousValue
public int previousValue(int e)
- Specified by:
previousValue
in interfaceIntIterableSet
- Parameters:
e
- (exclusive)- Returns:
- the value before 'aValue' or or
Integer.MIN_VALUE
-
previousValueOut
public int previousValueOut(int e)
- Specified by:
previousValueOut
in interfaceIntIterableSet
- Parameters:
e
- (exclusive)- Returns:
- the value outside this, before'aValue'
-
contains
public boolean contains(int o)
Description copied from interface:ISet
Test the existence of element in the set
-
duplicate
public IntIterableRangeSet duplicate()
Description copied from interface:IntIterableSet
Returns a carbon-copy of this set- Specified by:
duplicate
in interfaceIntIterableSet
- Returns:
- a carbon-copy of this set
-
copyFrom
public IntIterableRangeSet copyFrom(IntIterableRangeSet me)
-
size
public int size()
-
newIterator
public ISetIterator newIterator()
Description copied from interface:ISet
Creates a new iterator object, for nested loops only.- Specified by:
newIterator
in interfaceISet
- Returns:
- a new iterator for this set
-
plus
public void plus(int x)
add the value x to all integers stored in this set- Specified by:
plus
in interfaceIntIterableSet
- Parameters:
x
- value to add
-
iterator
public ISetIterator iterator()
Description copied from interface:ISet
Use the following loop to iterate over this set without autoboxing.// 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 overISet
(preferISet.newIterator()
)
-
minus
public void minus(int x)
subtract the value x to all integers stored in this set- Specified by:
minus
in interfaceIntIterableSet
- Parameters:
x
- value to add
-
times
public void times(int x)
multiply by x to all integers stored in this set- Parameters:
x
- value to add
-
rangeOf
public int rangeOf(int x)
By convention, range are numbered starting from 1 (not 0).- Parameters:
x
- a value- Returns:
- the range index if the value is in the set or -range point - 1 otherwise where range point corresponds to the range directly greater than the key
-
rangeOf
protected int rangeOf(int x, int fromIndex, int toIndex)
By convention, range are numbered starting from 1 (not 0).- Parameters:
x
- a value- Returns:
- the range index if the value is in the set or -range point - 1 otherwise where range point corresponds to the range directly greater than the key
-
compact
public void compact()
Compact the array in memory
-
flip
public IntIterableRangeSet flip()
Turn this into the complement of this. calling :set.flip().flip()
goes back to the original set.
-
flip
public IntIterableRangeSet flip(int lb, int ub)
Turn this into the complement of this. calling :set.flip().flip()
goes back to the original set.- Returns:
- this turned into its complement, based on lb, ub
-
forEachValueIn
public void forEachValueIn(IntConsumer c)
Apply the operation c on each value in this set- Parameters:
c
- an operation
-
forEachValueOut
public void forEachValueOut(IntConsumer c)
- Parameters:
c
- an operation
-
-