Package fj.data
Class HashMap<K,V>
java.lang.Object
fj.data.HashMap<K,V>
- All Implemented Interfaces:
Iterable<K>
A mutable hash map providing O(1) lookup.
- Version:
- %build.number%
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a hash map with the given equality and hashing strategy.Construct a hash map with the given equality and hashing strategy.Construct a hash map with the given equality and hashing strategy. -
Method Summary
Modifier and TypeMethodDescriptionstatic <K,
V> HashMap <K, V> arrayHashMap
(Equal<K> equal, Hash<K> hash, P2<K, V>... entries) Converts the array to a HashMapstatic <K,
V> HashMap <K, V> arrayHashMap
(P2<K, V>... entries) Converts the array to a HashMapvoid
clear()
Clear all entries from this hash map.boolean
Determines if the given key value exists in this hash map.void
Deletes the entry in the hash map that corresponds to the given key.boolean
Compare two key values for equality using the underlying equality strategy.void
void
foreachDoEffect
(Effect1<P2<K, V>> effect) static <K,
V> HashMap <K, V> static <K,
V> HashMap <K, V> get()
A curried version ofget(Object)
.Returns a potential value that the given key maps to.Deletes the entry in the hash map that corresponds to the given key and returns any associated value.int
Compute the hash of the given key value using the underlying hashing strategy.static <K,
V> HashMap <K, V> hashMap()
Construct a hash map that usesObject.equals(java.lang.Object)
andObject.hashCode()
.static <K,
V> HashMap <K, V> Construct a hash map.boolean
isEmpty()
Determines if this hash map has any entries.static <K,
V> HashMap <K, V> iterableHashMap
(Equal<K> equal, Hash<K> hash, Iterable<P2<K, V>> entries) Converts the Iterable to a HashMapstatic <K,
V> HashMap <K, V> iterableHashMap
(Iterable<P2<K, V>> entries) Converts the Iterable to a HashMapiterator()
Returns an iterator for this map's keys.static <K,
V> HashMap <K, V> iteratorHashMap
(Equal<K> equal, Hash<K> hash, Iterator<P2<K, V>> entries) Converts the Iterator to a HashMapstatic <K,
V> HashMap <K, V> iteratorHashMap
(Iterator<P2<K, V>> entries) Converts the Iterator to a HashMapkeys()
Returns all key entries in this hash map.<A,
B> HashMap <A, B> <A,
B> HashMap <A, B> <A,
B> HashMap <A, B> <A,
B> HashMap <A, B> void
Inserts the given key and value association into the hash map.int
size()
Returns the number of entries in this hash map.toArray()
Collection
<P2<K, V>> Projects an immutable collection of this hash map.toList()
toMap()
toOption()
toStream()
values()
Returns all values in this hash map.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
m
-
e
-
h
-
-
Constructor Details
-
HashMap
Construct a hash map with the given equality and hashing strategy.- Parameters:
e
- The equality strategy.h
- The hashing strategy.
-
HashMap
-
HashMap
Construct a hash map with the given equality and hashing strategy.- Parameters:
e
- The equality strategy.h
- The hashing strategy.initialCapacity
- The initial capacity.
-
HashMap
-
HashMap
Construct a hash map with the given equality and hashing strategy.- Parameters:
e
- The equality strategy.h
- The hashing strategy.initialCapacity
- The initial capacity.loadFactor
- The load factor.
-
-
Method Details
-
iterator
Returns an iterator for this map's keys. This method exists to permit the use in afor
-each loop. -
hashMap
Construct a hash map that usesObject.equals(java.lang.Object)
andObject.hashCode()
.- Returns:
- A new hash map that uses
Object.equals(java.lang.Object)
andObject.hashCode()
.
-
hashMap
Construct a hash map.- Returns:
- A new hash map.
-
eq
Compare two key values for equality using the underlying equality strategy.- Parameters:
k1
- One key value to compare.k2
- The other key value to compare.- Returns:
true
if the two key values are equal,false
otherwise.
-
hash
Compute the hash of the given key value using the underlying hashing strategy.- Parameters:
k
- The key value to computer the hash of.- Returns:
- The hash of the given key value.
-
get
Returns a potential value that the given key maps to.- Parameters:
k
- The key to look up in the hash map.- Returns:
- A potential value for the given key.
-
get
A curried version ofget(Object)
.- Returns:
- A curried version of
get(Object)
.
-
clear
public void clear()Clear all entries from this hash map. -
contains
Determines if the given key value exists in this hash map.- Parameters:
k
- The key value to look for in this hash map.- Returns:
true
if this hash map contains the given key,false
otherwise.
-
keys
Returns all key entries in this hash map.- Returns:
- All key entries in this hash map.
-
values
Returns all values in this hash map.- Returns:
- All values in this hash map.
-
isEmpty
public boolean isEmpty()Determines if this hash map has any entries.- Returns:
true
if this hash map has no entries,false
otherwise.
-
size
public int size()Returns the number of entries in this hash map.- Returns:
- The number of entries in this hash map.
-
set
Inserts the given key and value association into the hash map.- Parameters:
k
- The key to insert.v
- The value to insert.
-
delete
Deletes the entry in the hash map that corresponds to the given key.- Parameters:
k
- The key to delete from this hash map.
-
getDelete
Deletes the entry in the hash map that corresponds to the given key and returns any associated value.- Parameters:
k
- The key to delete from this hash map.- Returns:
- The value that was associated with the given key, if there was one.
-
map
-
map
-
map
-
map
-
mapKeys
-
mapKeys
-
mapValues
-
foreachDoEffect
-
foreach
-
toList
-
toCollection
Projects an immutable collection of this hash map.- Returns:
- An immutable collection of this hash map.
-
toStream
-
toOption
-
toArray
-
toMap
-
fromMap
-
fromMap
-
iterableHashMap
public static <K,V> HashMap<K,V> iterableHashMap(Equal<K> equal, Hash<K> hash, Iterable<P2<K, V>> entries) Converts the Iterable to a HashMap -
iterableHashMap
Converts the Iterable to a HashMap -
arrayHashMap
Converts the array to a HashMap -
arrayHashMap
@SafeVarargs public static <K,V> HashMap<K,V> arrayHashMap(Equal<K> equal, Hash<K> hash, P2<K, V>... entries) Converts the array to a HashMap -
iteratorHashMap
public static <K,V> HashMap<K,V> iteratorHashMap(Equal<K> equal, Hash<K> hash, Iterator<P2<K, V>> entries) Converts the Iterator to a HashMap -
iteratorHashMap
Converts the Iterator to a HashMap
-