scala.collection.mutable

class OpenHashMap

[source: scala/collection/mutable/OpenHashMap.scala]

class OpenHashMap[Key, Value](initialSize : Int)
extends Map[Key, Value]
A mutable hash map based on an open hashing scheme. The precise scheme is undefined, but it should make a reasonable effort to ensure that an insert with consecutive hash codes is not unneccessarily penalised. In particular, mappings of consecutive integer keys should work without significant performance loss.
Author
David MacIver
Since
2.7
Additional Constructor Summary
def this : OpenHashMap[Key, Value]
Method Summary
def += (kv : (Key, Value)) : OpenHashMap[Key, Value]
Add a new key/value mapping this map.
def -= (key : Key) : OpenHashMap[Key, Value]
Delete a key from this map if it is present.
override def clone : OpenHashMap[Key, Value]
This method creates and returns a copy of the receiver object.
override def elements : Iterator[(Key, Value)]
override def empty : OpenHashMap[Key, Value]
override def foreach [U](f : ((Key, Value)) => U) : Unit
Loop over the key, value mappings of this map. The behaviour of modifying the map during an iteration is as follows:
  • Deleting a mapping is always permitted.
  • Changing the value of mapping which is already present is permitted.
  • Anything else is not permitted. It will usually, but not always, throw an exception.
def get (key : Key) : Option[Value]
Check if this map maps key to a value and return the value as an option if it exists, None if not.
protected def hashOf (key : Key) : Int
def iterator : Iterator[(Key, Value)]
An iterator over the elements of this map. Use of this iterator follows the same contract for concurrent modification as the foreach method.
override def put (key : Key, value : Value) : Option[Value]
Adds a new mapping from key to value to the map. If the map already contains a mapping for key, it will be overridden.
override def remove (key : Key) : Option[Value]
If given key is defined in this map, remove it and return associated value as an Option. If key is not present return None.
override def retain (f : (Key, Value) => Boolean) : OpenHashMap[Key, Value]
Retain only those mappings for which the predicate p returns true.
override def size : Int
The number of elements in this collection
override def stringPrefix : java.lang.String
Defines the prefix of this object's toString representation. !!! todo: remove stringPrefix overrides where possible
override def transform (f : (Key, Value) => Value) : OpenHashMap[Key, Value]
This function transforms all the values of mappings contained in this map with function f.
override def update (key : Key, value : Value) : Unit
Adds a new mapping from key to value to the map. If the map already contains a mapping for key, it will be overridden.
Methods inherited from MapLike
newBuilder, updated, cached, +, +, ++, ++, -, removeKey, clear, getOrElseUpdate, result, -, --, --
Methods inherited from Shrinkable
-=, --=, --=
Methods inherited from Builder
sizeHint, mapResult
Methods inherited from Growable
+=, ++=, ++=
Methods inherited from MapLikeBase
+
Methods inherited from MapLike
isEmpty, getOrElse, apply, contains, isDefinedAt, keySet, keysIterator, keys, valuesIterable, valuesIterator, values, default, filterKeys, mapValues, mapElements, +, ++, ++, addString, toString, hashCode, equals
Methods inherited from PartialFunction
orElse, andThen
Methods inherited from Function1
compose
Methods inherited from Iterable
companion
Methods inherited from IterableLike
thisCollection, toCollection, forall, exists, find, foldRight, reduceRight, toIterable, head, take, slice, takeWhile, takeRight, dropRight, copyToArray, zip, zipAll, zipWithIndex, sameElements, toStream, canEqual, view, view, first, firstOption, projection
Methods inherited from GenericTraversableTemplate
genericBuilder, unzip, flatten, transpose
Methods inherited from TraversableLike
repr, nonEmpty, hasDefiniteSize, ++, ++, map, flatMap, filter, filterNot, partialMap, remove, partition, groupBy, count, foldLeft, /:, :\, reduceLeft, reduceLeftOption, reduceRightOption, sum, product, min, max, headOption, tail, last, lastOption, init, drop, dropWhile, span, splitAt, copyToBuffer, copyToArray, toArray, toList, toSeq, toIndexedSeq, toSet, mkString, mkString, mkString, addString, addString, withFilter
Methods inherited from AnyRef
getClass, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized
Methods inherited from Any
==, !=, isInstanceOf, asInstanceOf
Additional Constructor Details
def this : OpenHashMap[Key, Value]

Method Details
override def empty : OpenHashMap[Key, Value]
Overrides
Map.empty

override def size : Int
The number of elements in this collection

protected def hashOf(key : Key) : Int

override def update(key : Key, value : Value) : Unit
Adds a new mapping from key to value to the map. If the map already contains a mapping for key, it will be overridden.
Parameters
key - The key to update
value - The new value
Returns
An option consisting of value associated previously associated with `key` in the map, or None if `key` was not yet defined in the map.

def +=(kv : (Key, Value)) : OpenHashMap[Key, Value]
Add a new key/value mapping this map.
Parameters
kv - the key/value pair.
Returns
the map itself

def -=(key : Key) : OpenHashMap[Key, Value]
Delete a key from this map if it is present.
Parameters
key - the key to be removed
Notes
same as `delete`.

override def put(key : Key, value : Value) : Option[Value]
Adds a new mapping from key to value to the map. If the map already contains a mapping for key, it will be overridden.
Parameters
key - The key to update
value - The new value

override def remove(key : Key) : Option[Value]
If given key is defined in this map, remove it and return associated value as an Option. If key is not present return None.
Parameters
key - the key to be removed

def get(key : Key) : Option[Value]
Check if this map maps key to a value and return the value as an option if it exists, None if not.
Parameters
key - the key of the mapping of interest.
Returns
the value of the mapping as an option, if it exists, or None.

def iterator : Iterator[(Key, Value)]
An iterator over the elements of this map. Use of this iterator follows the same contract for concurrent modification as the foreach method.

@deprecated("use `iterator' instead")

override def elements : Iterator[(Key, Value)]

override def clone : OpenHashMap[Key, Value]
This method creates and returns a copy of the receiver object.

The default implementation of the clone method is platform dependent.

Returns
a copy of the receiver object.


override def foreach[U](f : ((Key, Value)) => U) : Unit
Loop over the key, value mappings of this map. The behaviour of modifying the map during an iteration is as follows:
  • Deleting a mapping is always permitted.
  • Changing the value of mapping which is already present is permitted.
  • Anything else is not permitted. It will usually, but not always, throw an exception.
Parameters
f - The function to apply to each key, value mapping.

override def transform(f : (Key, Value) => Value) : OpenHashMap[Key, Value]
This function transforms all the values of mappings contained in this map with function f.
Parameters
f - The transformation to apply

override def retain(f : (Key, Value) => Boolean) : OpenHashMap[Key, Value]
Retain only those mappings for which the predicate p returns true.
Parameters
p - The test predicate

override def stringPrefix : java.lang.String
Defines the prefix of this object's toString representation. !!! todo: remove stringPrefix overrides where possible