fr.univNantes.intcolls
Class ConcurrentBinaryIntSet

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<java.lang.Integer>
          extended by fr.univNantes.intcolls.BinaryIntSet
              extended by fr.univNantes.intcolls.ConcurrentBinaryIntSet
All Implemented Interfaces:
java.lang.Iterable<java.lang.Integer>, java.util.Collection<java.lang.Integer>, java.util.NavigableSet<java.lang.Integer>, java.util.Set<java.lang.Integer>, java.util.SortedSet<java.lang.Integer>

public class ConcurrentBinaryIntSet
extends BinaryIntSet

Concurrent version of BinaryIntSet.

Concurrency is enforced by the following features :

Author:
Pierre-Olivier Terrisse.
See Also:
BinaryIntSet

Field Summary
private  java.util.concurrent.atomic.AtomicInteger size
          Size of the set (number of elements)
 
Fields inherited from class fr.univNantes.intcolls.BinaryIntSet
blockCapacity, blockMask, blocks, blockShift, DEFAULT_BLOCK_CAPACITY
 
Constructor Summary
ConcurrentBinaryIntSet()
          Constructor of the set with default block capacity
ConcurrentBinaryIntSet(BinaryIntSet is)
          Contructor of the set with another collection of the same type
ConcurrentBinaryIntSet(java.util.Collection<java.lang.Integer> coll)
          Contructor of the set with another collection of Integers
ConcurrentBinaryIntSet(int blockCapacity)
          Constructor of the set
 
Method Summary
 boolean addAll(java.util.Collection<? extends java.lang.Integer> coll)
          Adds all of the elements in the specified collection to this collection
 boolean addInt(int value)
          Adds an interger element to this collection
 void clear()
          Removes all the values from the set
 boolean containsInt(int value)
          Returns true if this collection contains a certain value
 int countBetween(int fromValue, int toValue)
          Counts values between 2 given values
 int countHigher(int value)
          Counts values strictly higher than a given value
 int countLower(int value)
          Counts values strictly lower than a given value
 boolean equals(java.lang.Object obj)
          Indicates whether some other object is "equal to" this one.
 java.lang.Integer first()
          Returns the first (lowest) element currently in this set.
 int hashCode()
          Returns a hash code value for the set
(package private)  boolean hasHigher(int value, BinaryIntSetIterator.Context context)
          Returns true if the set has a higher value
(package private)  boolean hasLower(int value, BinaryIntSetIterator.Context context)
          Returns true if the set has a lower value
(package private)  int higherInt(int e, BinaryIntSetIterator.Context context)
          Returns the least element in this set strictly greater than the given element
 java.lang.Integer last()
          Returns the last (hightest) element currently in this set.
(package private)  int lowerInt(int e, BinaryIntSetIterator.Context context)
          Returns the greatest element in this set strictly less than the given element
 boolean removeAll(java.util.Collection<?> coll)
          Removes all of the elements in the specified collection to this collection
 boolean removeInt(int value)
          Removes an element from the collection
 boolean retainAll(java.util.Collection<?> is1)
          Retains only the elements in this collection that are contained in the specified collection
 void setSlotValue(int blockNum, int slotNum, long slotVal)
          Low level method : sets a slot value.
 int size()
          Returns the number of elements contained in the collection
 int sum()
          Returns the sum of all elements
 
Methods inherited from class fr.univNantes.intcolls.BinaryIntSet
add, addAll, ceiling, comparator, contains, descendingIterator, descendingSet, floor, fromBooleanArray, getBlockWithContext, getSlotValue, headSet, headSet, higher, iterator, lower, pollFirst, pollLast, remove, removeAll, retainAll, subSet, subSet, tailSet, tailSet, toBooleanArray
 
Methods inherited from class java.util.AbstractCollection
containsAll, isEmpty, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
containsAll, isEmpty, toArray, toArray
 

Field Detail

size

private final java.util.concurrent.atomic.AtomicInteger size
Size of the set (number of elements)

Constructor Detail

ConcurrentBinaryIntSet

public ConcurrentBinaryIntSet(int blockCapacity)
Constructor of the set

Parameters:
blockCapacity - capacity of blocks in number of slots. Must be a power of 2.

ConcurrentBinaryIntSet

public ConcurrentBinaryIntSet()
Constructor of the set with default block capacity


ConcurrentBinaryIntSet

public ConcurrentBinaryIntSet(java.util.Collection<java.lang.Integer> coll)
Contructor of the set with another collection of Integers

Parameters:
coll - another collection of Integers

ConcurrentBinaryIntSet

public ConcurrentBinaryIntSet(BinaryIntSet is)
Contructor of the set with another collection of the same type

Parameters:
is - another collection of Integers
Method Detail

addInt

public boolean addInt(int value)
Adds an interger element to this collection

Overrides:
addInt in class BinaryIntSet
Parameters:
value - value to add
Returns:
true if the collection was modified

removeInt

public boolean removeInt(int value)
Removes an element from the collection

Overrides:
removeInt in class BinaryIntSet
Parameters:
value - element to remove
Returns:
true if the collection was modified

addAll

public boolean addAll(java.util.Collection<? extends java.lang.Integer> coll)
Adds all of the elements in the specified collection to this collection

Specified by:
addAll in interface java.util.Collection<java.lang.Integer>
Specified by:
addAll in interface java.util.Set<java.lang.Integer>
Overrides:
addAll in class BinaryIntSet
Parameters:
coll - another IntCollection
Returns:
true if this integer set changed after the operation

removeAll

public boolean removeAll(java.util.Collection<?> coll)
Removes all of the elements in the specified collection to this collection

Specified by:
removeAll in interface java.util.Collection<java.lang.Integer>
Specified by:
removeAll in interface java.util.Set<java.lang.Integer>
Overrides:
removeAll in class BinaryIntSet
Parameters:
coll - another integer collection
Returns:
true if this integer set changed after the operation

retainAll

public boolean retainAll(java.util.Collection<?> is1)
Retains only the elements in this collection that are contained in the specified collection

Specified by:
retainAll in interface java.util.Collection<java.lang.Integer>
Specified by:
retainAll in interface java.util.Set<java.lang.Integer>
Overrides:
retainAll in class BinaryIntSet
Parameters:
is1 - another collection
Returns:
true if this collection changed

size

public int size()
Returns the number of elements contained in the collection

Specified by:
size in interface java.util.Collection<java.lang.Integer>
Specified by:
size in interface java.util.Set<java.lang.Integer>
Overrides:
size in class BinaryIntSet
Returns:
the size of the collection

containsInt

public boolean containsInt(int value)
Returns true if this collection contains a certain value

Overrides:
containsInt in class BinaryIntSet
Parameters:
value - value to search in this collection
Returns:
true if this collection contains the value

clear

public void clear()
Removes all the values from the set

Specified by:
clear in interface java.util.Collection<java.lang.Integer>
Specified by:
clear in interface java.util.Set<java.lang.Integer>
Overrides:
clear in class BinaryIntSet

equals

public boolean equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this one.

Specified by:
equals in interface java.util.Collection<java.lang.Integer>
Specified by:
equals in interface java.util.Set<java.lang.Integer>
Overrides:
equals in class BinaryIntSet
Parameters:
obj - the reference object with which to compare.
Returns:
true if this object is the same as the obj argument; false otherwise.

hashCode

public int hashCode()
Returns a hash code value for the set

Specified by:
hashCode in interface java.util.Collection<java.lang.Integer>
Specified by:
hashCode in interface java.util.Set<java.lang.Integer>
Overrides:
hashCode in class BinaryIntSet
Returns:
an integer value that must be consistant with equals()

sum

public int sum()
Returns the sum of all elements

Overrides:
sum in class BinaryIntSet
Returns:
the sum

first

public java.lang.Integer first()
Returns the first (lowest) element currently in this set.

Specified by:
first in interface java.util.SortedSet<java.lang.Integer>
Overrides:
first in class BinaryIntSet
Returns:
the first (lowest) element currently in this set
Throws:
java.util.NoSuchElementException - - if this set is empty

last

public java.lang.Integer last()
Returns the last (hightest) element currently in this set.

Specified by:
last in interface java.util.SortedSet<java.lang.Integer>
Overrides:
last in class BinaryIntSet
Returns:
the last (hightest) element currently in this set
Throws:
java.util.NoSuchElementException - - if this set is empty

higherInt

int higherInt(int e,
              BinaryIntSetIterator.Context context)
Returns the least element in this set strictly greater than the given element

Overrides:
higherInt in class BinaryIntSet
Parameters:
e - an element
context - iterator's context if any, null otherwise
Returns:
the least element greater than e or Integer.MIN_VALUE if not such element

hasHigher

boolean hasHigher(int value,
                  BinaryIntSetIterator.Context context)
Returns true if the set has a higher value

Overrides:
hasHigher in class BinaryIntSet
Parameters:
value - a value
context - iterator's context if any, null otherwise
Returns:
true if the set contains a higher value

lowerInt

int lowerInt(int e,
             BinaryIntSetIterator.Context context)
Returns the greatest element in this set strictly less than the given element

Overrides:
lowerInt in class BinaryIntSet
Parameters:
e - an element
context - iterator's context if any, null otherwise
Returns:
the greatest element less than e or Integer.MAX_VALUE if not such element

hasLower

boolean hasLower(int value,
                 BinaryIntSetIterator.Context context)
Returns true if the set has a lower value

Overrides:
hasLower in class BinaryIntSet
Parameters:
value - a value
context - iterator's context if any, null otherwise
Returns:
true if the set contains a lower value

countLower

public int countLower(int value)
Counts values strictly lower than a given value

Overrides:
countLower in class BinaryIntSet
Parameters:
value - a value

countHigher

public int countHigher(int value)
Counts values strictly higher than a given value

Overrides:
countHigher in class BinaryIntSet
Parameters:
value - a value

countBetween

public int countBetween(int fromValue,
                        int toValue)
Counts values between 2 given values

Overrides:
countBetween in class BinaryIntSet
Parameters:
fromValue - first value, including
toValue - second value, not including
Returns:
number of values between fromValue and toValue

setSlotValue

public void setSlotValue(int blockNum,
                         int slotNum,
                         long slotVal)
Low level method : sets a slot value. Possibly a new block is created.

Overrides:
setSlotValue in class BinaryIntSet
Parameters:
blockNum - block number
slotNum - slot number
slotVal - slot value