fr.univNantes.intcolls
Class ConcurrentBinaryLongSet

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

public class ConcurrentBinaryLongSet
extends BinaryLongSet

Concurrent version of BinaryLongSet

Concurrency is enforced by the following features :

Author:
Pierre-Olivier Terrisse.
See Also:
BinaryLongSet

Field Summary
private  java.util.concurrent.atomic.AtomicInteger size
          Size of the set (number of elements)
 
Fields inherited from class fr.univNantes.intcolls.BinaryLongSet
blockCapacity, blockMask, blocks, blockShift, DEFAULT_BLOCK_CAPACITY
 
Constructor Summary
ConcurrentBinaryLongSet()
          Constructor of the set with default block capacity
ConcurrentBinaryLongSet(BinaryLongSet is)
          Contructor of the set with another collection of the same type
ConcurrentBinaryLongSet(java.util.Collection<java.lang.Long> coll)
          Contructor of the set with another collection of Integers
ConcurrentBinaryLongSet(int blockCapacity)
          Constructor of the set
 
Method Summary
 boolean addAll(java.util.Collection<? extends java.lang.Long> coll)
          Adds all of the elements in the specified collection to this collection
 boolean addLong(long value)
          Adds an interger element to this collection
 void clear()
          Removes all the values from the set
 boolean containsLong(long value)
          Returns true if this collection contains a certain value
 long countBetween(long fromValue, long toValue)
          Counts values between 2 given values
 long countHigher(long value)
          Counts values strictly higher than a given value
 long countLower(long 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.Long first()
          Returns the first (lowest) element currently in this set.
 int hashCode()
          Returns a hash code value for the set
(package private)  boolean hasHigher(long value, BinaryLongSetIterator.Context context)
          Returns true if the set has a higher value
(package private)  boolean hasLower(long value, BinaryLongSetIterator.Context context)
          Returns true if the set has a lower value
(package private)  long higherLong(long e, BinaryLongSetIterator.Context context)
          Returns the least element in this set strictly greater than the given element
 java.lang.Long last()
          Returns the last (hightest) element currently in this set.
(package private)  long lowerLong(long e, BinaryLongSetIterator.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 removeLong(long 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(long 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.BinaryLongSet
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

ConcurrentBinaryLongSet

public ConcurrentBinaryLongSet(int blockCapacity)
Constructor of the set

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

ConcurrentBinaryLongSet

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


ConcurrentBinaryLongSet

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

Parameters:
coll - another collection of Integers

ConcurrentBinaryLongSet

public ConcurrentBinaryLongSet(BinaryLongSet is)
Contructor of the set with another collection of the same type

Parameters:
is - another collection of Integers
Method Detail

addLong

public boolean addLong(long value)
Adds an interger element to this collection

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

removeLong

public boolean removeLong(long value)
Removes an element from the collection

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

addAll

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

Specified by:
addAll in interface java.util.Collection<java.lang.Long>
Specified by:
addAll in interface java.util.Set<java.lang.Long>
Overrides:
addAll in class BinaryLongSet
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.Long>
Specified by:
removeAll in interface java.util.Set<java.lang.Long>
Overrides:
removeAll in class BinaryLongSet
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.Long>
Specified by:
retainAll in interface java.util.Set<java.lang.Long>
Overrides:
retainAll in class BinaryLongSet
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.Long>
Specified by:
size in interface java.util.Set<java.lang.Long>
Overrides:
size in class BinaryLongSet
Returns:
the size of the collection

containsLong

public boolean containsLong(long value)
Returns true if this collection contains a certain value

Overrides:
containsLong in class BinaryLongSet
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.Long>
Specified by:
clear in interface java.util.Set<java.lang.Long>
Overrides:
clear in class BinaryLongSet

equals

public boolean equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this one. Note (for Netbeans users) : hashCode() is not overriden

Specified by:
equals in interface java.util.Collection<java.lang.Long>
Specified by:
equals in interface java.util.Set<java.lang.Long>
Overrides:
equals in class BinaryLongSet
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.Long>
Specified by:
hashCode in interface java.util.Set<java.lang.Long>
Overrides:
hashCode in class BinaryLongSet
Returns:
an integer value that must be consistant with equals()

sum

public int sum()
Returns the sum of all elements

Overrides:
sum in class BinaryLongSet
Returns:
the sum

first

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

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

last

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

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

higherLong

long higherLong(long e,
                BinaryLongSetIterator.Context context)
Returns the least element in this set strictly greater than the given element

Overrides:
higherLong in class BinaryLongSet
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(long value,
                  BinaryLongSetIterator.Context context)
Returns true if the set has a higher value

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

lowerLong

long lowerLong(long e,
               BinaryLongSetIterator.Context context)
Returns the greatest element in this set strictly less than the given element

Overrides:
lowerLong in class BinaryLongSet
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(long value,
                 BinaryLongSetIterator.Context context)
Returns true if the set has a lower value

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

countLower

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

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

countHigher

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

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

countBetween

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

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

setSlotValue

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

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