Package com.tangosol.util
Class OpenHashSet<E>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractSet<E>
-
- com.tangosol.util.OpenHashSet<E>
-
- Type Parameters:
E
- the type of elements that can be managed by this set
- All Implemented Interfaces:
Iterable<E>
,Collection<E>
,Set<E>
public class OpenHashSet<E> extends AbstractSet<E>
An implementation ofSet
that is optimized for memory footprint. Specifically, instead of delegating to aHashMap
which instantiates an "Entry" object for each element (as theHashSet
does, which references those entries in a linked list fashion with the head of the linked list stored in the hash bucket array, this implementation stores its elements using an open hashing algorithm, i.e. the elements are stored directly in the hash bucket array.This implementation is explicitly NOT thread-safe.
- Since:
- 12.2.1
- Author:
- cp 2013.01.15
-
-
Constructor Summary
Constructors Constructor Description OpenHashSet()
Default constructor.OpenHashSet(int initialCapacity)
Create a OpenHashSet pre-sized to hold the specified number of elements.OpenHashSet(Collection<? extends E> coll)
Create a OpenHashSet that will initially contain the contents of the passed Collection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(E e)
void
clear()
boolean
contains(Object o)
protected E
getElement(int n)
Expose the indexed element storage to sub-classes in a range-unsafe manner.Iterator<E>
iterator()
boolean
remove(Object o)
int
size()
Object[]
toArray()
<T> T[]
toArray(T[] a)
-
Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
-
Methods inherited from class java.util.AbstractCollection
addAll, containsAll, isEmpty, retainAll, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.Set
addAll, containsAll, isEmpty, retainAll, spliterator
-
-
-
-
Constructor Detail
-
OpenHashSet
public OpenHashSet()
Default constructor.
-
OpenHashSet
public OpenHashSet(int initialCapacity)
Create a OpenHashSet pre-sized to hold the specified number of elements.- Parameters:
initialCapacity
- the initial capacity requirement for the hash set
-
OpenHashSet
public OpenHashSet(Collection<? extends E> coll)
Create a OpenHashSet that will initially contain the contents of the passed Collection. In other words, this is a "copy constructor".- Parameters:
coll
- the Collection whose contents this
-
-
Method Detail
-
size
public int size()
- Specified by:
size
in interfaceCollection<E>
- Specified by:
size
in interfaceSet<E>
- Specified by:
size
in classAbstractCollection<E>
-
contains
public boolean contains(Object o)
- Specified by:
contains
in interfaceCollection<E>
- Specified by:
contains
in interfaceSet<E>
- Overrides:
contains
in classAbstractCollection<E>
-
add
public boolean add(E e)
- Specified by:
add
in interfaceCollection<E>
- Specified by:
add
in interfaceSet<E>
- Overrides:
add
in classAbstractCollection<E>
-
remove
public boolean remove(Object o)
- Specified by:
remove
in interfaceCollection<E>
- Specified by:
remove
in interfaceSet<E>
- Overrides:
remove
in classAbstractCollection<E>
-
clear
public void clear()
- Specified by:
clear
in interfaceCollection<E>
- Specified by:
clear
in interfaceSet<E>
- Overrides:
clear
in classAbstractCollection<E>
-
toArray
public Object[] toArray()
- Specified by:
toArray
in interfaceCollection<E>
- Specified by:
toArray
in interfaceSet<E>
- Overrides:
toArray
in classAbstractCollection<E>
-
toArray
public <T> T[] toArray(T[] a)
- Specified by:
toArray
in interfaceCollection<E>
- Specified by:
toArray
in interfaceSet<E>
- Overrides:
toArray
in classAbstractCollection<E>
-
getElement
protected E getElement(int n)
Expose the indexed element storage to sub-classes in a range-unsafe manner.- Parameters:
n
- an element index- Returns:
- the value stored at the specified index; note that a null value is not differentiable from an empty element, since both are returned as null
-
-