scala.collection.immutable

class HashMap

[source: scala/collection/immutable/HashMap.scala]

@serializable

class HashMap[A, +B]
extends Map[A, B] with ImmutableMapTemplate[A, B, HashMap[A, B]] with HashTable[A]
This class implements immutable maps using a hash table. It is optimized for sequential accesses where the last updated table is accessed most often. It supports with reasonable efficiency accesses to previous versions of the table by keeping a change log that's regularly compacted. It needs to synchronize most methods, so it is less suitable for highly concurrent accesses.
Notes
the builder of a hash map returns specialized representations EmptyMap,Map1,..., Map4 for maps of size <= 4.
Author
Martin Odersky
Version
2.0, 19/01/2007
Type Summary
type Entry
Value Summary
protected var deltaSize : Int
protected var later : HashMap[A, B]
protected var oldKey : A
protected var oldValue : Option[B]
Values and Variables inherited from HashTable
loadFactorDenum, table, tableSize, threshold
Method Summary
override def + [B1 >: B](kv : (A, B1)) : HashMap[A, B1]
Add a key/value pair to this map.
override def + [B1 >: B](elem1 : (A, B1), elem2 : (A, B1), elems : (A, B1)*) : HashMap[A, B1]
Adds two or more elements to this collection and returns either the collection itself (if it is mutable), or a new collection with the added elements.
def - (key : A) : HashMap[A, B]
Removes a key from this map, returning a new map
override def empty : HashMap[A, B]
def get (key : A) : Option[B]
Check if this map maps key to a value and return the value as an option if it exists, None if not.
def iterator : Iterator[(A, B)]
An iterator yielding all key/value mappings of this map.
override def size : Int
Returns the size of this hash table.
override def updated [B1 >: B](key : A, value : B1) : HashMap[A, B1]
Add a key/value pair to this map.
Methods inherited from HashTable
loadFactor, initialSize, initialThreshold, findEntry, addEntry, removeEntry, entriesIterator, entries, clear, elemEquals, elemHashCode, improve, index
Methods inherited from Map
hashCode, withDefault, withDefaultValue
Methods inherited from ImmutableMapTemplate
++, ++, transform, filterNot, update
Methods inherited from MapTemplate
newBuilder, isEmpty, getOrElse, apply, contains, isDefinedAt, keySet, keysIterator, keys, valueIterable, valuesIterator, values, default, filterKeys, mapValues, mapElements, addString, equals, stringPrefix, toString
Methods inherited from Subtractable
-, --, --
Methods inherited from PartialFunction
orElse, andThen
Methods inherited from Function1
compose
Methods inherited from Iterable
companion
Methods inherited from IterableTemplate
elements, foreach, foldRight, reduceRight, toIterable, head, takeRight, dropRight, sameElements, toStream, view, view, first, firstOption, toSeq, projection
Methods inherited from TraversableClass
genericBuilder, unzip, flatten, transpose
Methods inherited from TraversableTemplate
thisCollection, nonEmpty, hasDefiniteSize, ++, ++, map, flatMap, filter, filterMap, remove, partition, groupBy, forall, exists, count, find, foldLeft, /:, :\, reduceLeft, reduceLeftOption, reduceRightOption, headOption, tail, last, lastOption, init, take, drop, slice, takeWhile, dropWhile, span, splitAt, copyToBuffer, copyToArray, copyToArray, toArray, toList, toSequence, toSet, mkString, mkString, mkString, addString, addString
Methods inherited from AnyRef
getClass, clone, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized
Methods inherited from Any
==, !=, isInstanceOf, asInstanceOf
Type Details
type Entry

Value Details
protected var later : HashMap[A, B]

protected var oldKey : A

protected var oldValue : Option[B]

protected var deltaSize : Int

Method Details
override def empty : HashMap[A, B]
Overrides
Map.empty

def get(key : A) : Option[B]
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.

override def updated[B1 >: B](key : A, value : B1) : HashMap[A, B1]
Add a key/value pair to this map.
Parameters
key - the key
value - the value
Returns
A new map with the new binding added to this map
Overrides
Map.updated, ImmutableMapTemplate.updated

override def +[B1 >: B](kv : (A, B1)) : HashMap[A, B1]
Add a key/value pair to this map.
Parameters
kv - the key/value pair
Returns
A new map with the new binding added to this map
Overrides
Map.+, ImmutableMapTemplate.+

override def +[B1 >: B](elem1 : (A, B1), elem2 : (A, B1), elems : (A, B1)*) : HashMap[A, B1]
Adds two or more elements to this collection and returns either the collection itself (if it is mutable), or a new collection with the added elements.
Parameters
elem1 - the first element to add.
elem2 - the second element to add.
elems - the remaining elements to add.
Overrides
ImmutableMapTemplate.+

def -(key : A) : HashMap[A, B]
Removes a key from this map, returning a new map
Parameters
key - the key to be removed
Returns
A new map without a binding for key

override def size : Int
Returns the size of this hash table.
Overrides
HashTable.size

def iterator : Iterator[(A, B)]
An iterator yielding all key/value mappings of this map.