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
Concret implementation ofIntIterableSetwherein 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
-
-
Field Summary
Fields Modifier and Type Field Description protected intCARDINALITYTotal number of elements in the setprotected int[]ELEMENTSStore elementsprotected intSIZEUsed size inELEMENTS.
-
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 booleanadd(int e)Add element to the setbooleanaddAll(int... values)Adds all of the elements in the array to this set.booleanaddAll(IntIterableSet set)Adds all of the elements in the specified set to this set.booleanaddBetween(int a, int b)voidclear()Remove all elements from the setbooleancontains(int o)Test the existence of element in the setIntIterableSetduplicate()Returns a carbon-copy of this setSetTypegetSetType()ISetIteratoriterator()Use the following loop to iterate over this set without autoboxing.intmax()intmin()voidminus(int x)subtract the value x to all integers stored in this setISetIteratornewIterator()Creates a new iterator object, for nested loops only.intnextValue(int e)voidplus(int x)add the value x to all integers stored in this setintpreviousValue(int e)protected intrangeOf(int x)By convention, range are numbered starting from 1 (not 0).booleanremove(int e)Remove the first occurrence of element from the setbooleanremoveAll(IntIterableSet set)Removes all of this set's elements that are also contained in the specified set.booleanremoveBetween(int f, int t)Removes all values between f (inclusive) and t (inclusive)booleanretainAll(IntIterableSet set)Retains only the elements in this set that are contained in the specified set.intsize()voidtimes(int x)multiply by x to all integers stored in this setStringtoSmartString()StringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.chocosolver.util.objects.setDataStructures.ISet
isEmpty, toArray
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Field Detail
-
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()
-
min
public int min()
-
max
public int max()
-
add
public boolean add(int e)
Description copied from interface:ISetAdd element to the set
-
addAll
public boolean addAll(int... values)
Description copied from interface:IntIterableSetAdds all of the elements in the array to this set.- Specified by:
addAllin interfaceIntIterableSet- Parameters:
values- array containing elements to be added to this set- Returns:
trueif this set changed as a result of the call
-
addAll
public boolean addAll(IntIterableSet set)
Description copied from interface:IntIterableSetAdds all of the elements in the specified set to this set.- Specified by:
addAllin interfaceIntIterableSet- Parameters:
set- set containing elements to be added to this set- Returns:
trueif this set changed as a result of the call
-
retainAll
public boolean retainAll(IntIterableSet set)
Description copied from interface:IntIterableSetRetains 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:
retainAllin interfaceIntIterableSet- Parameters:
set- set containing elements to be retained in this set- Returns:
- true if this set changed as a result of the call
-
remove
public boolean remove(int e)
Description copied from interface:ISetRemove the first occurrence of element from the set
-
removeAll
public boolean removeAll(IntIterableSet set)
Description copied from interface:IntIterableSetRemoves 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:
removeAllin interfaceIntIterableSet- Parameters:
set- set containing elements to be removed from this set- Returns:
- true if this set changed as a result of the call
-
addBetween
public boolean addBetween(int a, int b)
-
clear
public void clear()
Description copied from interface:ISetRemove all elements from the set
-
getSetType
public SetType getSetType()
- Specified by:
getSetTypein interfaceISet- Returns:
- the implementation type of this set
-
removeBetween
public boolean removeBetween(int f, int t)Description copied from interface:IntIterableSetRemoves all values between f (inclusive) and t (inclusive)- Specified by:
removeBetweenin interfaceIntIterableSet- Parameters:
f- first value to removet- last value to remove- Returns:
- true if this set changed as a result of the call
-
nextValue
public int nextValue(int e)
- Specified by:
nextValuein interfaceIntIterableSet- Parameters:
e- (exclusive)- Returns:
- the value after aValue
-
previousValue
public int previousValue(int e)
- Specified by:
previousValuein interfaceIntIterableSet- Parameters:
e- (exclusive)- Returns:
- the value before aValue
-
contains
public boolean contains(int o)
Description copied from interface:ISetTest the existence of element in the set
-
duplicate
public IntIterableSet duplicate()
Description copied from interface:IntIterableSetReturns a carbon-copy of this set- Specified by:
duplicatein interfaceIntIterableSet- Returns:
- a carbon-copy of this set
-
size
public int size()
-
newIterator
public ISetIterator newIterator()
Description copied from interface:ISetCreates a new iterator object, for nested loops only.- Specified by:
newIteratorin 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:
plusin interfaceIntIterableSet- Parameters:
x- value to add
-
iterator
public ISetIterator iterator()
Description copied from interface:ISetUse 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:
minusin 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
protected 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
-
-