T - the element typepublic class ComparingHashSet<T>
extends java.lang.Object
Note since the new string hashing behavior is hidden under sun.misc, this class implements an older hashing code which might be exploited with well crafted strings.
The implementation is not thread safe.
| Modifier and Type | Class and Description |
|---|---|
protected static class |
ComparingHashSet.Entry
The set entry.
|
| Modifier and Type | Field and Description |
|---|---|
protected Func2<? super T,? super T,java.lang.Boolean> |
comparer
The comparer function.
|
protected int |
count
The current element count.
|
protected ComparingHashSet.Entry[] |
entries
The contained entries.
|
protected double |
loadFactor
The load factor before the table is resized.
|
protected int |
threshold
The load count before the table is resized.
|
| Constructor and Description |
|---|
ComparingHashSet()
Default constructor with capacity 16, load factor of 0.75 and nullsafe equals() comparer.
|
ComparingHashSet(Func2<? super T,? super T,java.lang.Boolean> comparer)
Constructor with capacity 16, load factor of 0.75 and the given comparer.
|
ComparingHashSet(int capacity)
Constructor with the capacity, load factor of 0.75 and nullsafe equals() comparer.
|
ComparingHashSet(int capacity,
double loadFactor,
Func2<? super T,? super T,java.lang.Boolean> comparer)
Initializes the set with the given capacity, load factor
and comparer.
|
ComparingHashSet(int capacity,
Func2<? super T,? super T,java.lang.Boolean> comparer)
Constructor with the given capacity, load factor of 0.75 and the given comparer.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(T item)
Tries to add the given item to this set.
|
protected void |
addEntry(int hash,
java.lang.Object item,
int idx)
Adds a new entry to the set, resizing
the container as necessary.
|
boolean |
isEmpty() |
protected void |
resize(int newSize)
Resize the container and remap all its entries.
|
int |
size() |
protected final Func2<? super T,? super T,java.lang.Boolean> comparer
protected ComparingHashSet.Entry[] entries
protected int count
protected double loadFactor
protected int threshold
public ComparingHashSet()
public ComparingHashSet(int capacity)
capacity - the initial capacity.public ComparingHashSet(@Nonnull
Func2<? super T,? super T,java.lang.Boolean> comparer)
comparer - the comparer function.public ComparingHashSet(int capacity,
@Nonnull
Func2<? super T,? super T,java.lang.Boolean> comparer)
capacity - the initial capacity.comparer - the comparer function.public ComparingHashSet(int capacity,
double loadFactor,
@Nonnull
Func2<? super T,? super T,java.lang.Boolean> comparer)
capacity - the initial capacity, will be rounded up to the next power of
2, minimum 16loadFactor - the load factor where after the underlying table is resizedcomparer - the content comparerpublic boolean add(T item)
item - the item to add.protected void addEntry(int hash,
java.lang.Object item,
int idx)
hash - the hash of the itemitem - the itemidx - the indexprotected void resize(int newSize)
newSize - the new sizepublic boolean isEmpty()
public int size()