com.devexperts.util
Class LongHashSet

java.lang.Object
  extended by java.util.AbstractCollection<E>
      extended by java.util.AbstractSet<Long>
          extended by com.devexperts.util.AbstractLongSet
              extended by com.devexperts.util.LongHashSet
All Implemented Interfaces:
LongCollection, LongSet, Serializable, Cloneable, Iterable<Long>, Collection<Long>, Set<Long>

public final class LongHashSet
extends AbstractLongSet
implements Cloneable, Serializable

This class implements the LongSet interface, backed by a hash table (actually a LongHashMap instance). It makes no guarantees as to the iteration order of the set; in particular, it does not guarantee that the order will remain constant over time.

Note that this implementation is not synchronized. If multiple threads access a set concurrently, and at least one of the threads modifies the set, it must be synchronized externally. This is typically accomplished by synchronizing on some object that naturally encapsulates the set. If no such object exists, the set should be "wrapped" using the Collections.synchronizedSet(java.util.Set) method. This is best done at creation time, to prevent accidental unsynchronized access to the set.

The iterators returned by this class's iterator method are fail-fast: if the set is modified at any time after the iterator is created, in any way except through the iterator's own remove method, the Iterator throws a ConcurrentModificationException. Thus, in the face of concurrent modification, the iterator fails quickly and cleanly, rather than risking arbitrary, non-deterministic behavior at an undetermined time in the future.

See Also:
Serialized Form

Constructor Summary
LongHashSet()
          Constructs a new, empty set.
LongHashSet(Collection<? extends Long> c)
          Constructs a new set containing all elements from the specified collection.
LongHashSet(int capacity)
          Constructs a new set with a specified capacity.
 
Method Summary
 boolean add(long key)
          Ensures that this collection contains the specified element.
 void clear()
           
 void clearAndCompact()
          Removes all elements and frees all memory.
 void clearAndCompact(int capacity)
          Removes all elements and compacts memory usage of this hashtable, but requested capacity is retained.
 Object clone()
          Returns a shallow copy of this set: the elements themselves are not cloned.
 void compact()
          Compacts memory usage of this hashtable.
 void compact(int capacity)
          Compacts memory usage of this hashtable, but requested capacity is retained.
 boolean contains(long key)
          Returns true if this collection contains the specified element.
 void ensureCapacity(int capacity)
          Makes sure that no rehashes or memory reallocations will be needed until size() <= capacity.
 boolean isEmpty()
           
 LongIterator longIterator()
          Returns an iterator over the elements in this collection.
 boolean remove(long key)
          Removes a single instance of the specified element from this collection, if it is present.
 int size()
           
 
Methods inherited from class com.devexperts.util.AbstractLongSet
add, addAll, contains, containsAll, iterator, remove, removeAll, retainAll, toLongArray
 
Methods inherited from class java.util.AbstractSet
equals, hashCode
 
Methods inherited from class java.util.AbstractCollection
toArray, toArray, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Set
equals, hashCode, toArray, toArray
 

Constructor Detail

LongHashSet

public LongHashSet()
Constructs a new, empty set.


LongHashSet

public LongHashSet(Collection<? extends Long> c)
Constructs a new set containing all elements from the specified collection.


LongHashSet

public LongHashSet(int capacity)
Constructs a new set with a specified capacity.

Method Detail

longIterator

public LongIterator longIterator()
Description copied from interface: LongCollection
Returns an iterator over the elements in this collection.

Specified by:
longIterator in interface LongCollection
Specified by:
longIterator in class AbstractLongSet
See Also:
Collection.iterator()

size

public int size()
Specified by:
size in interface Collection<Long>
Specified by:
size in interface Set<Long>
Specified by:
size in class AbstractLongSet

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection<Long>
Specified by:
isEmpty in interface Set<Long>
Overrides:
isEmpty in class AbstractCollection<Long>

contains

public boolean contains(long key)
Description copied from interface: LongCollection
Returns true if this collection contains the specified element.

Specified by:
contains in interface LongCollection
Specified by:
contains in class AbstractLongSet
See Also:
Collection.contains(Object)

add

public boolean add(long key)
Description copied from interface: LongCollection
Ensures that this collection contains the specified element.

Specified by:
add in interface LongCollection
Overrides:
add in class AbstractLongSet
See Also:
Collection.add(Object)

remove

public boolean remove(long key)
Description copied from interface: LongCollection
Removes a single instance of the specified element from this collection, if it is present.

Specified by:
remove in interface LongCollection
Specified by:
remove in class AbstractLongSet
See Also:
Collection.remove(Object)

clear

public void clear()
Specified by:
clear in interface Collection<Long>
Specified by:
clear in interface Set<Long>
Specified by:
clear in class AbstractLongSet

clone

public Object clone()
Returns a shallow copy of this set: the elements themselves are not cloned.

Overrides:
clone in class Object

ensureCapacity

public void ensureCapacity(int capacity)
Makes sure that no rehashes or memory reallocations will be needed until size() <= capacity.

See Also:
LongHashMap.ensureCapacity(int)

compact

public void compact()
Compacts memory usage of this hashtable. The hashtable's capacity is decreased to the minimum needed size.

See Also:
LongHashMap.compact()

compact

public void compact(int capacity)
Compacts memory usage of this hashtable, but requested capacity is retained. #see LongHashMap#compact(int)


clearAndCompact

public void clearAndCompact()
Removes all elements and frees all memory.

See Also:
LongHashMap.clearAndCompact()

clearAndCompact

public void clearAndCompact(int capacity)
Removes all elements and compacts memory usage of this hashtable, but requested capacity is retained.

See Also:
LongHashMap.clearAndCompact(int)


Copyright © 2013 Devexperts. All Rights Reserved.