public class CharCharMap extends Object implements Serializable, Cloneable
Instances of this class use a hash table to represent a map. The table is filled up to a specified load factor, and then doubled in size to accommodate new entries. If the table is emptied below one fourth of the load factor, it is halved in size. However, halving is not performed when deleting entries from an iterator, as it would interfere with the iteration process.
Note that clear() does not modify the hash table size. Rather, a family of trimming methods lets you control the size of the table; this is particularly useful if
you reuse instances of this class.
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
containsNullKey
Whether this set contains the key zero.
|
static int |
DEFAULT_INITIAL_SIZE
The initial default size of a hash table.
|
static float |
DEFAULT_LOAD_FACTOR
The default load factor of a hash table.
|
protected char |
defRetValue
The default return value for
get(), put() and remove(). |
protected float |
f
The acceptable load factor.
|
protected char[] |
key
The array of keys.
|
protected regexodus.ds.CharCharMap.KeySet |
keys
Cached set of keys.
|
protected int |
mask
The mask for wrapping a position counter.
|
protected int |
maxFill
Threshold after which we rehash.
|
protected int |
n
The current table size.
|
protected int |
size
Number of entries in the set (including the key zero, if present).
|
protected char[] |
value
The array of values.
|
| Constructor and Description |
|---|
CharCharMap()
Creates a new hash map with initial expected 16 entries and 0.75f as load factor.
|
CharCharMap(char[] k,
char[] v)
Creates a new hash map with 0.75f as load factor using the elements of two parallel arrays.
|
CharCharMap(char[] k,
char[] v,
float f)
Creates a new hash map using the elements of two parallel arrays.
|
CharCharMap(int expected)
Creates a new hash map with 0.75f as load factor.
|
CharCharMap(int expected,
float f)
Creates a new hash map.
|
| Modifier and Type | Method and Description |
|---|---|
static int |
arraySize(int expected,
float f)
Returns the least power of two smaller than or equal to 230 and larger than or equal to
Math.ceil( expected / f ). |
void |
clear() |
CharCharMap |
clone()
Returns a deep copy of this map.
|
boolean |
containsKey(char k) |
boolean |
containsValue(char v) |
char |
defaultReturnValue() |
void |
defaultReturnValue(char rv) |
char |
get(char k) |
int |
growthFactor()
Deprecated.
Since
fastutil 6.1.0, hash tables are doubled when they are too full. |
void |
growthFactor(int growthFactor)
Deprecated.
Since
fastutil 6.1.0, hash tables are doubled when they are too full. |
int |
hashCode()
Returns a hash code for this map.
|
boolean |
isEmpty() |
regexodus.ds.CharCharMap.KeySet |
keySet() |
static int |
maxFill(int n,
float f)
Returns the maximum number of entries that can be filled before rehashing.
|
static long |
maxFill(long n,
float f)
Returns the maximum number of entries that can be filled before rehashing.
|
char |
put(char k,
char v) |
protected void |
rehash(int newN)
Rehashes the map.
|
char |
remove(char k) |
protected void |
shiftKeys(int pos)
Shifts left entries with the specified hash code, starting at the specified position, and empties the resulting free entry.
|
int |
size() |
boolean |
trim()
Rehashes the map, making the table as small as possible.
|
boolean |
trim(int n)
Rehashes this map if the table is too large.
|
protected transient char[] key
protected transient char[] value
protected transient int mask
protected transient boolean containsNullKey
protected transient int n
protected transient int maxFill
f.protected int size
protected final float f
protected transient volatile regexodus.ds.CharCharMap.KeySet keys
protected char defRetValue
get(), put() and remove().public static final int DEFAULT_INITIAL_SIZE
public static final float DEFAULT_LOAD_FACTOR
public CharCharMap(int expected, float f)
The actual table size will be the least power of two greater than expected/f.
expected - the expected number of elements in the hash set.f - the load factor.public CharCharMap(int expected)
expected - the expected number of elements in the hash map.public CharCharMap()
public CharCharMap(char[] k, char[] v, float f)
k - the array of keys of the new hash map.v - the array of corresponding values in the new hash map.f - the load factor.IllegalArgumentException - if k and v have different lengths.public CharCharMap(char[] k, char[] v)
k - the array of keys of the new hash map.v - the array of corresponding values in the new hash map.IllegalArgumentException - if k and v have different lengths.public void defaultReturnValue(char rv)
public char defaultReturnValue()
public char put(char k, char v)
protected final void shiftKeys(int pos)
pos - a starting position.public char remove(char k)
public char get(char k)
public boolean containsKey(char k)
public boolean containsValue(char v)
public void clear()
public int size()
public boolean isEmpty()
@Deprecated public void growthFactor(int growthFactor)
fastutil 6.1.0, hash tables are doubled when they are too full.growthFactor - unused.@Deprecated public int growthFactor()
fastutil 6.1.0, hash tables are doubled when they are too full.growthFactor(int)public regexodus.ds.CharCharMap.KeySet keySet()
public boolean trim()
This method rehashes the table to the smallest size satisfying the load factor. It can be used when the set will not be changed anymore, so to optimize access speed and size.
If the table size is already the minimum possible, this method does nothing.
trim(int)public boolean trim(int n)
Let N be the smallest table size that can hold max(n, entries, still satisfying the load factor. If the current table size is smaller than or equal to
N, this method does nothing. Otherwise, it rehashes this map in a table of size N.
size())
This method is useful when reusing maps. Clearing a map leaves the table size untouched. If you are reusing a map many times, you can call this method with a typical size to avoid keeping around a very large table just because of a few large transient maps.
n - the threshold for the trimming.trim()protected void rehash(int newN)
This method implements the basic rehashing strategy, and may be overriden by subclasses implementing different rehashing strategies (e.g., disk-based rehashing). However, you should not override this method unless you understand the internal workings of this class.
newN - the new sizepublic CharCharMap clone()
This method performs a deep copy of this hash map, but with primitive keys and values it doesn't matter much.
public int hashCode()
This method overrides the generic method provided by the superclass. Since equals() is not overriden, it is important that the value returned by this method is the same value as
the one returned by the overriden method.
public static int maxFill(int n, float f)
n - the size of the backing array.f - the load factor.public static long maxFill(long n, float f)
n - the size of the backing array.f - the load factor.public static int arraySize(int expected, float f)
Math.ceil( expected / f ).expected - the expected number of elements in a hash table.f - the load factor.IllegalArgumentException - if the necessary size is larger than 230.Copyright © 2016. All rights reserved.