Class/Object

debox

Map

Related Docs: object Map | package debox

Permalink

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]
Linear Supertypes
Serializable, Serializable, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Map
  2. Serializable
  3. Serializable
  4. AnyRef
  5. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Map(ks: Array[A], vs: Array[B], bs: Array[Byte], n: Int, u: Int)(implicit cta: ClassTag[A], ctb: ClassTag[B])

    Permalink
    Attributes
    protected[debox]

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ++(rhs: Map[A, B])(implicit ev: Monoid[B]): Map[A, B]

    Permalink

    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.

  4. final def ++=(rhs: Iterable[(A, B)])(implicit ev: Monoid[B]): Unit

    Permalink

    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.

  5. final def ++=(rhs: Map[A, B])(implicit ev: Monoid[B]): Unit

    Permalink

    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.

  6. final def +=(kv: (A, B)): Unit

    Permalink

    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.

  7. final def --=(rhs: Iterable[A]): Unit

    Permalink

    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.

  8. final def --=(rhs: Set[A]): Unit

    Permalink

    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.

  9. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  10. final def apply(key: A): B

    Permalink

    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).

  11. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  12. var buckets: Array[Byte]

    Permalink
  13. final def clear(): Unit

    Permalink

    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.

  14. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  15. final def compact(): Unit2[A, B]

    Permalink

    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.

  16. final def contains(key: A): Boolean

    Permalink

    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).

  17. final def containsItem(key: A, value: B): Boolean

    Permalink

    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).

  18. final def copy(): Map[A, B]

    Permalink

    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.

  19. implicit val cta: ClassTag[A]

    Permalink
  20. implicit val ctb: ClassTag[B]

    Permalink
  21. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  22. def equals(rhs: Any): Boolean

    Permalink

    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
  23. def exists(p: (A, B) ⇒ Boolean): Boolean

    Permalink

    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.

  24. final def filterInPlace(rhs: Set[A]): Unit

    Permalink

    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.

  25. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  26. def find(p: (A, B) ⇒ Boolean): Option[(A, B)]

    Permalink

    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.

  27. def findAll(p: (A, B) ⇒ Boolean): Map[A, B]

    Permalink

    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.

  28. def forall(p: (A, B) ⇒ Boolean): Boolean

    Permalink

    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.

  29. final def foreach(f: (A, B) ⇒ Unit): Unit

    Permalink

    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.

  30. final def foreachKey(f: (A) ⇒ Unit): Unit

    Permalink

    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.

  31. final def foreachValue(f: (B) ⇒ Unit): Unit

    Permalink

    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.

  32. final def get(key: A): Option[B]

    Permalink

    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).

  33. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  34. final def getOrElse(key: A, fallback: B): B

    Permalink

    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).

  35. final def getOrElseUpdate(key: A, fallback: B): B

    Permalink

    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).

  36. final def grow(): Unit2[A, B]

    Permalink

    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.

  37. def hashCode(): Int

    Permalink

    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
  38. final def isEmpty: Boolean

    Permalink

    Return true if the Map is empty, false otherwise.

    Return true if the Map is empty, false otherwise.

    This is an O(1) operation.

  39. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  40. def iterator(): Iterator[(A, B)]

    Permalink

    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.

  41. var keys: Array[A]

    Permalink
  42. final def keysSet: Set[A]

    Permalink

    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.

  43. var len: Int

    Permalink
  44. var limit: Int

    Permalink
  45. def loopUntil(p: (A, B) ⇒ Boolean): Int

    Permalink

    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.

  46. def loopWhile(p: (A, B) ⇒ Boolean): Int

    Permalink

    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.

  47. final def mapItemsToMap[C, D](f: (A, B) ⇒ (C, D))(implicit arg0: ClassTag[C], arg1: ClassTag[D], ev: CMonoid[D]): Map[C, D]

    Permalink

    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.

  48. final def mapItemsToMapUnsafe[C, D](f: (A, B) ⇒ (C, D))(implicit arg0: ClassTag[C], arg1: ClassTag[D]): Map[C, D]

    Permalink

    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.

  49. final def mapKeys[C](f: (A) ⇒ C)(implicit arg0: ClassTag[C], ev: CMonoid[B]): Map[C, B]

    Permalink

    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.

  50. final def mapKeysUnsafe[C](f: (A) ⇒ C)(implicit arg0: ClassTag[C]): Map[C, B]

    Permalink

    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.

  51. final def mapToArray[C](f: (A, B) ⇒ C)(implicit arg0: ClassTag[C]): Array[C]

    Permalink

    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.

  52. final def mapToSet[C](f: (A, B) ⇒ C)(implicit arg0: ClassTag[C]): Set[C]

    Permalink

    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.

  53. final def mapValues[C](f: (B) ⇒ C)(implicit arg0: ClassTag[C]): Map[A, C]

    Permalink

    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.

  54. var mask: Int

    Permalink
  55. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  56. final def nonEmpty: Boolean

    Permalink

    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.

  57. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  58. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  59. final def remove(key: A): Unit

    Permalink

    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).

  60. final def size: Int

    Permalink

    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.

  61. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  62. def toString(): String

    Permalink

    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
  63. final def transformValues(f: (A, B) ⇒ B): Unit

    Permalink

    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.

  64. final def update(key: A, value: B): Unit

    Permalink

    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.

  65. var used: Int

    Permalink
  66. var vals: Array[B]

    Permalink
  67. final def valuesArray: Array[B]

    Permalink

    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.

  68. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  69. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  70. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Serializable

Inherited from Serializable

Inherited from AnyRef

Inherited from Any

Ungrouped