final class Map[A, B] extends Serializable
Map is a mutable hash map, with open addressing and double hashing.
Map provides constant-time membership tests and access, and amortized constant-time addition and removal. One underlying array stores keys, another stores values, and another tracks which buckets are used and defined.
The hashing mechanism is exactly the same as that used in debox.Set, which means that constructing a Set from the keys is relatively fast.
When the generic types are known (or the caller is specialized on them), Map[A, B] will store the keys and values in unboxed arrays.
One fundamental difference between debox.Map and Scala's various map types is that debox.Map does not claim to contain tuples, and most of methods handle keys and values as separate parameters, rather than item tuples. This means that methods like foreach() and mapKey() take Function2 instances rather than Function1 instances.
It also means that instead of generic Tuple2 => Tuple2 functions, Debox uses more specialized methods. For example:
// Scala version scalaMap.map { case (k, v) => (k, v + 3) }
// Debox versions deboxMap.mapValues(v => v + 3) // best deboxMap.mapItems((k, v) => (k, v + 3)) // allocs unnecessary tuples deboxMap.
This means that the Debox Map API has some real differences compared to Scala's API, so please check the methods you are using.
- Self Type
- Map[A, B]
- Alphabetic
- By Inheritance
- Map
- Serializable
- Serializable
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
++(rhs: Map[A, B])(implicit ev: Monoid[B]): Map[A, B]
Combine the two maps into a new map, using the provided CMonoid[B] to merge values for the same key.
Combine the two maps into a new map, using the provided CMonoid[B] to merge values for the same key.
This is an O(m+n) operation, where m and n are the size of the maps.
-
final
def
++=(rhs: Iterable[(A, B)])(implicit ev: Monoid[B]): Unit
Add the items from the given iterable to this map, combining values using the provided Monoid[B].
Add the items from the given iterable to this map, combining values using the provided Monoid[B].
This is an O(m) operation, where m is the size of the rhs.
-
final
def
++=(rhs: Map[A, B])(implicit ev: Monoid[B]): Unit
Add the items from the given map to this map, combining values using the provided Monoid[B].
Add the items from the given map to this map, combining values using the provided Monoid[B].
This is an O(m) operation, where m is the size of the rhs.
-
final
def
+=(kv: (A, B)): Unit
Given (key, value), update the map to bind value to key.
Given (key, value), update the map to bind value to key.
Unless the caller has already constrcuted the item tuple, it is usually better to say 'map(key) = value' directly to avoid allocating one.
This is an O(1) operation.
-
final
def
--=(rhs: Iterable[A]): Unit
Remove the keys in the given set from this iterable.
Remove the keys in the given set from this iterable.
On average, this is an O(m) operation, where m is the size of the rhs.
-
final
def
--=(rhs: Set[A]): Unit
Remove the keys in the given set from this map.
Remove the keys in the given set from this map.
On average, this is an O(m) operation, where m is the size of the lhs or rhs, whichever is smaller.
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
apply(key: A): B
Return the key's current value in the map, throwing an exception if the key is not found.
Return the key's current value in the map, throwing an exception if the key is not found.
On average, this is an O(1) operation; the (unlikely) worst-case is O(n).
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
- var buckets: Array[Byte]
-
final
def
clear(): Unit
Clears the map's internal state.
Clears the map's internal state.
After calling this method, the set's state is identical to that obtained by calling Map.empty[A, B].
The previous arrays are not retained, and will become available for garbage collection.
This is an O(1) operation, but may generate a lot of garbage if the set was previously large.
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
final
def
compact(): Unit2[A, B]
Compacts the map's internal arrays to reduce memory usage.
Compacts the map's internal arrays to reduce memory usage.
This operation should be used if a map has been shrunk (e.g. through --=) and is not likely to grow again.
This method will shrink the map to the smallest possible size that allows it to be <66% full. It returns a null of type Unit2[A, B] to trigger specialization without allocating an actual instance.
This is an O(n) operation, where n it the set's size.
-
final
def
contains(key: A): Boolean
Return whether the key is present in the Map or not.
Return whether the key is present in the Map or not.
On average, this is an O(1) operation; the (unlikely) worst-case is O(n).
-
final
def
containsItem(key: A, value: B): Boolean
Return whether the key is present in the Map with the given value or not.
Return whether the key is present in the Map with the given value or not.
On average, this is an O(1) operation; the (unlikely) worst-case is O(n).
-
final
def
copy(): Map[A, B]
Make a (shallow) copy of this map.
Make a (shallow) copy of this map.
This method creates a copy of the map with the same structure. However, the actual keys and values will not be copied.
This is an O(n) operation.
- implicit val cta: ClassTag[A]
- implicit val ctb: ClassTag[B]
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(rhs: Any): Boolean
Check if two Maps are equal.
Check if two Maps are equal.
Equal means the maps have the same types (which is checked using the ClassTag instances) and the same contents.
Comparing Maps with any of Scala's collection types will return false.
- Definition Classes
- Map → AnyRef → Any
-
def
exists(p: (A, B) ⇒ Boolean): Boolean
Return true if any item in the map satisfies the given predicate, false otherwise.
Return true if any item in the map satisfies the given predicate, false otherwise.
Note that if the map is empty, all predicates will return false.
On average, this is an O(n) operation, although true results may be returned more quickly.
-
final
def
filterInPlace(rhs: Set[A]): Unit
Remove all items whose keys are not in the provided set.
Remove all items whose keys are not in the provided set.
This method modifies the existing map.
On average, this is an O(m) operation, where m is the size of the lhs or rhs, whichever is smaller.
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
find(p: (A, B) ⇒ Boolean): Option[(A, B)]
For the given predicate, return Some(item) for an item that satisfies the predicate, or None otherwise.
For the given predicate, return Some(item) for an item that satisfies the predicate, or None otherwise.
The order that items are checked is non-deterministic. Thus, maps with the same keys and values may find different items first.
On average, this is an O(n) operation, although results may be returned more quickly.
-
def
findAll(p: (A, B) ⇒ Boolean): Map[A, B]
For the given predicate, return a map of all items that satisfy the predicate.
For the given predicate, return a map of all items that satisfy the predicate.
Maps with the same keys and values are guaranteed to return the same map from this method.
This is an O(n) operation, where n is the size of the map.
-
def
forall(p: (A, B) ⇒ Boolean): Boolean
Return true if every item in the map satisfies the given predicate, false otherwise.
Return true if every item in the map satisfies the given predicate, false otherwise.
Note that if the map is empty, all predicates will return true.
On average, this is an O(n) operation, although false results may be returned more quickly.
-
final
def
foreach(f: (A, B) ⇒ Unit): Unit
Run the provided function on each key and value.
Run the provided function on each key and value.
The order the keys and values are accessed is non-deterministic.
This is an O(n) operation, where n is the size of the map.
-
final
def
foreachKey(f: (A) ⇒ Unit): Unit
Run the provided function on each key.
Run the provided function on each key.
The order the keys are accessed is non-deterministic.
This is an O(n) operation, where n is the size of the map.
-
final
def
foreachValue(f: (B) ⇒ Unit): Unit
Run the provided function on each value.
Run the provided function on each value.
The order the values are accessed is non-deterministic.
This is an O(n) operation, where n is the size of the map.
-
final
def
get(key: A): Option[B]
Return the key's current value in the map as an Option, returning None if the key is not found.
Return the key's current value in the map as an Option, returning None if the key is not found.
On average, this is an O(1) operation; the (unlikely) worst-case is O(n).
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
getOrElse(key: A, fallback: B): B
Return the key's current value in the map, returning the given fallback value if the key is not found.
Return the key's current value in the map, returning the given fallback value if the key is not found.
Unlike Scala's method, this method is eager in its second parameters, so it should only be used if the default value is already available (or a literal, or very cheap).
In cases where a lazy parameter would be desired, you should use something like: myMap.get(key).getOrElse(default).
On average, this is an O(1) operation; the (unlikely) worst-case is O(n).
-
final
def
getOrElseUpdate(key: A, fallback: B): B
Return the key's current value in the map, returning the given fallback value and updating the key with that value if the key is not found.
Return the key's current value in the map, returning the given fallback value and updating the key with that value if the key is not found.
Unlike Scala's method, this method is eager in its second parameters, so it should only be used if the default value is already available (or a literal, or very cheap).
On average, this is an O(1) operation; the (unlikely) worst-case is O(n).
-
final
def
grow(): Unit2[A, B]
Grow the underlying array to best accomodate the map's size.
Grow the underlying array to best accomodate the map's size.
To preserve hashing access speed, the map's size should never be more than 66% of the underlying array's size. When this size is reached, the map needs to be updated (using this method) to have a larger array.
The underlying array's size must always be a multiple of 2, which means this method grows the array's size by 2x (or 4x if the map is very small). This doubling helps amortize the cost of resizing, since as the map gets larger growth will happen less frequently. This method returns a null of type Unit1[A] to trigger specialization without allocating an actual instance.
Growing is an O(n) operation, where n is the map's size.
-
def
hashCode(): Int
Hash the contents of the map to an Int value.
Hash the contents of the map to an Int value.
By xor'ing all the map's keys and values together, we can be sure that maps with the same contents will have the same hashCode regardless of the order those items appear.
This is an O(n) operation.
- Definition Classes
- Map → AnyRef → Any
-
final
def
isEmpty: Boolean
Return true if the Map is empty, false otherwise.
Return true if the Map is empty, false otherwise.
This is an O(1) operation.
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
def
iterator(): Iterator[(A, B)]
Return an iterator over this map's contents.
Return an iterator over this map's contents.
This method does not do any copying or locking. Thus, if the map is modified while the iterator is "live" the results will be undefined and probably bad. Also, since maps are not ordered, there is no guarantee elements will be returned in a particular order.
Use this.copy.iterator to get a "clean" iterator if needed.
Creating the iterator is an O(1) operation.
- var keys: Array[A]
-
final
def
keysSet: Set[A]
Return a new Set containing the current map's keys.
Return a new Set containing the current map's keys.
This method copies the underlying key array, but does not need to rehash the keys, so it is relatively fast (implemented using System.arraycopy). The keys themselves are not copied.
This is an O(n) operation, where n is the size of the map.
- var len: Int
- var limit: Int
-
def
loopUntil(p: (A, B) ⇒ Boolean): Int
Return the lowest index whose key/value satisfy the predicate, or -1 otherwise.
Return the lowest index whose key/value satisfy the predicate, or -1 otherwise.
The indices returned correspond to the map's internal arrays. Care should be taken.
On average, this is an O(n) operation, where n is the size of the map, although non-negative results may be returned more quickly.
-
def
loopWhile(p: (A, B) ⇒ Boolean): Int
Return the lowest index whose key/value do not satisfy the predicate, or -1 otherwise.
Return the lowest index whose key/value do not satisfy the predicate, or -1 otherwise.
The indices returned correspond to the map's internal arrays. Care should be taken.
On average, this is an O(n) operation, where n is the size of the map, although non-negative results may be returned more quickly.
-
final
def
mapItemsToMap[C, D](f: (A, B) ⇒ (C, D))(implicit arg0: ClassTag[C], arg1: ClassTag[D], ev: CMonoid[D]): Map[C, D]
Transform this map into another map.
Transform this map into another map.
This method uses a function to go from key and value to a pair, which will be added to the map.
If multiple invocations of the provided function return values with the same key, the given commutative monoid will be used to combine the values. This commutativity ensures that maps with the same keys and values will always produce the same result. However, if duplicate keys are produced, the resulting map will be smaller than this map.
On average, this is an O(n) operation, where n is the size of the map.
-
final
def
mapItemsToMapUnsafe[C, D](f: (A, B) ⇒ (C, D))(implicit arg0: ClassTag[C], arg1: ClassTag[D]): Map[C, D]
Transform this map into another map.
Transform this map into another map.
This method uses a function to go from key and value to a pair, which will be added to the map.
If multiple invocations of the provided function return values with the same key, it is non-deterministic what value the new map will have for the key. In these cases, two equal maps will produce different results, and the resulting map will be smaller than this map.
On average, this is an O(n) operation, where n is the size of the map.
-
final
def
mapKeys[C](f: (A) ⇒ C)(implicit arg0: ClassTag[C], ev: CMonoid[B]): Map[C, B]
Transform this map into another map.
Transform this map into another map.
This method uses a function to go from an existing key to a new key, and will add the new key with the existing value to the new map.
If multiple invocations of the provided function return values with the same key, the given commutative monoid will be used to combine the values. This commutativity ensures that maps with the same keys and values will always produce the same result. However, if duplicate keys are produced, the resulting map will be smaller than this map.
On average, this is an O(n) operation, where n is the size of the map.
-
final
def
mapKeysUnsafe[C](f: (A) ⇒ C)(implicit arg0: ClassTag[C]): Map[C, B]
Transform this map into another map.
Transform this map into another map.
This method uses a function to go from an existing key to a new key, and will add the new key with the existing value to the new map.
If multiple invocations of the provided function return the same key, it is non-deterministic what value the new map will have for the key. In these cases, two equal maps will produce different results, and the resulting map will be smaller than this map.
On average, this is an O(n) operation, where n is the size of the map.
-
final
def
mapToArray[C](f: (A, B) ⇒ C)(implicit arg0: ClassTag[C]): Array[C]
Transform this map into an array.
Transform this map into an array.
This method uses a function to go from key and value to an element to be stored in the array.
The order of the array is non-deterministic. Thus, maps that have the same keys and values may produce different arrays. The size of the array is guaranteed to be equal to the size of the map.
On average, this is an O(n) operation, where n is the size of the map.
-
final
def
mapToSet[C](f: (A, B) ⇒ C)(implicit arg0: ClassTag[C]): Set[C]
Transform this map into a set.
Transform this map into a set.
This method uses a function to go from key and value to an element to be added to a set.
Two maps with the same keys and values will always produce the same set. The size of the resulting set may be smaller than the map if several function invocations return the same result.
On average, this is an O(n) operation, where n is the size of the map.
-
final
def
mapValues[C](f: (B) ⇒ C)(implicit arg0: ClassTag[C]): Map[A, C]
Transform this map into another map.
Transform this map into another map.
This method uses a function to go from an existing value to a new value, and will add the existing key with the new value to the new map.
The new map will always be the same size as the existing map, and maps with equivalent keys and values will always produce equivalent maps.
On average, this is an O(n) operation, where n is the size of the map.
- var mask: Int
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
nonEmpty: Boolean
Return true if the Map is non-empty, false otherwise.
Return true if the Map is non-empty, false otherwise.
This is an O(1) operation.
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
remove(key: A): Unit
This method removes any value associated with key.
This method removes any value associated with key.
If there was no previous value, this method does nothing.
On average, this is an O(1) operation; the (unlikely) worst-case is O(n).
-
final
def
size: Int
Return the size of this Map as an Int.
Return the size of this Map as an Int.
Since Maps use arrays, their size is limited to what a 32-bit signed integer can represent.
This is an O(1) operation.
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
Return a string representation of the contents of the map.
Return a string representation of the contents of the map.
This is an O(n) operation.
- Definition Classes
- Map → AnyRef → Any
-
final
def
transformValues(f: (A, B) ⇒ B): Unit
Run the provided function on each value.
Run the provided function on each value.
The order the values are accessed is non-deterministic.
This is an O(n) operation, where n is the size of the map.
-
final
def
update(key: A, value: B): Unit
This method stores associates value with key.
This method stores associates value with key.
If a previous value was associated with the key, it is overwritten.
This method is usually invoked as map(key) = value, but can also be invoked as map.update(key, value).
On average, this is an amortized O(1) operation; the worst-case is O(n), which will happen when the map needs to be resized.
- var used: Int
- var vals: Array[B]
-
final
def
valuesArray: Array[B]
Return a new array containing the current map's values, in an unspecified order.
Return a new array containing the current map's values, in an unspecified order.
This method is not a true function, in that map values which are equivalent (have the same keys and values) may return differently-ordered arrays.
To get an unordered set of the values, use valuesSet. To get a sorted valuesArray, use sortedValuesArray.
This is an O(n) operation, where n is the size of the map.
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )