|
Scala Library
|
|
scala/collection/mutable/MapLike.scala]
trait
MapLike[A, B, +This <: MapLike[A, B, This] with Map[A, B]]
extends MapLikeBase[A, B, This] with Builder[(A, B), This] with Shrinkable[A]
A generic template for mutable maps from keys of type A to
values of type B.
To implement a concrete mutable map, you need to provide implementations of the following methods:
def get(key: A): Option[B]
def iterator: Iterator[(A, B)]
def += (kv: (A, B)): this.type
def -= (key: A): this.type
If you wish that methods like, take,
drop, filter return the same kind of map, you
should also override:
def empty: This
If you to avoid the unncessary construction of an Option
object, you could also override apply, update,
and delete.
It is also good idea to override methods foreach and
size for efficiency.
| Method Summary | |
def
|
+
(kv : (A, B)) : MapLike[A, B, This]
Add a new key/value mapping and return the map itself.
|
def
|
+
(elem1 : (A, B), elem2 : (A, B), elems : (A, B)*) : MapLike[A, B, This]
Adds two or more key/value mappings and return the map itself.
with the added elements.
|
def
|
++
(iter : Iterator[(A, B)]) : MapLike[A, B, This]
Adds a number of elements provided by an iterator
via its
iterator method and returns
the collection itself. |
def
|
++
(iter : Traversable[(A, B)]) : MapLike[A, B, This]
Adds a number of elements provided by a traversable object
via its
iterator method and returns
either the collection itself (if it is mutable), or a new collection
with the added elements. |
abstract def
|
+=
(kv : (A, B)) : MapLike[A, B, This]
Add a new key/value mapping this map.
|
override def
|
-
(elem1 : A, elem2 : A, elems : A*) : This
Removes two or more elements from this collection and returns
the collection itself.
|
override def
|
-
(key : A) : This
Delete a key from this map if it is present and return the map itself.
|
override def
|
--
(iter : Iterator[A]) : This
Removes a number of elements provided by an iterator and returns
the collection itself.
|
override def
|
--
(iter : Traversable[A]) : This
Removes a number of elements provided by a Traversable object and returns
the collection itself.
|
abstract def
|
-=
(key : A) : MapLike[A, B, This]
Delete a key from this map if it is present.
|
def
|
cached
(key : A, op : => B) : B
If given key is already in this map, returns associated value
Otherwise, computes value from given expression `op`, stores with key
in map and returns that value.
|
def
|
clear
: Unit
Removes all elements from the set. After this operation is completed,
the set will be empty.
|
override def
|
clone
: This
This method creates and returns a copy of the receiver object.
|
def
|
getOrElseUpdate
(key : A, default : => B) : B
Check if this map maps
key to a value.
Return that value if it exists, otherwise put default
as that key's value and return it. |
protected[this] override def
|
newBuilder : Builder[(A, B), This] |
def
|
put
(key : A, value : B) : Option[B]
Adds a new mapping from
key
to value to the map. If the map already contains a
mapping for key, it will be overridden. |
def
|
remove
(key : A) : Option[B]
If given key is defined in this map, remove it and return associated value as an Option.
If key is not present return None.
|
def
|
removeKey
(key : A) : Option[B]
If given key is defined in this map, remove it and return associated value as an Option.
If key is not present return None.
|
def
|
result
: This
The result when this map is used as a builder
|
def
|
retain
(p : (A, B) => Boolean) : MapLike[A, B, This]
Retain only those mappings for which the predicate
p returns true. |
def
|
transform
(f : (A, B) => B) : MapLike[A, B, This]
This function transforms all the values of mappings contained
in this map with function
f. |
def
|
update
(key : A, value : B) : 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. |
override def
|
updated
[B1 >: B](key : A, value : B1) : Map[A, B1]
Create a new map consisting of all elements of the current map
plus the given mapping from
key to value. |
| Methods inherited from Shrinkable | |
| -=, --=, --= |
| Methods inherited from Builder | |
| sizeHint, mapResult |
| Methods inherited from Growable | |
| +=, ++=, ++= |
| Methods inherited from MapLikeBase | |
| + |
| Methods inherited from MapLike | |
| empty (abstract), get (abstract), iterator (abstract), isEmpty, getOrElse, apply, contains, isDefinedAt, keySet, keysIterator, keys, valuesIterable, valuesIterator, values, default, filterKeys, mapValues, mapElements, +, ++, ++, addString, stringPrefix, toString, hashCode, equals |
| Methods inherited from IterableLike | |
| thisCollection, toCollection, elements, foreach, 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 TraversableLike | |
| repr, nonEmpty, size, 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 PartialFunction | |
| orElse, andThen |
| Methods inherited from Function1 | |
| compose |
| Methods inherited from AnyRef | |
| getClass, notify, notifyAll, wait, wait, wait, finalize, ==, !=, eq, ne, synchronized |
| Methods inherited from Any | |
| ==, !=, isInstanceOf, asInstanceOf |
| Method Details |
A common implementation of newBuilder for all mutable maps
in terms of empty.
Overrides MapLike implementation for better efficiency.
key
to value to the map. If the map already contains a
mapping for key, it will be overridden.key - The key to updatevalue - The new valuekey
to value to the map. If the map already contains a
mapping for key, it will be overridden.key - The key to updatevalue - The new valuekv - the key/value pair.key to value.key - The key to advalue - The new value
def
+(kv : (A, B)) : MapLike[A, B, This]
kv - the key/value mapping to be added
def
+(elem1 : (A, B), elem2 : (A, B), elems : (A, B)*) : MapLike[A, B, This]
elem1 - the first element to add.elem2 - the second element to add.elems - the remaining elements to add.
def
++(iter : Traversable[(A, B)]) : MapLike[A, B, This]
iterator method and returns
either the collection itself (if it is mutable), or a new collection
with the added elements.iter - the traversable object.
def
++(iter : Iterator[(A, B)]) : MapLike[A, B, This]
iterator method and returns
the collection itself.iter - the iteratorkey - the key to be removedkey - the key to be removedoverride
def
-(key : A) : This
key - the key to be removed
def
removeKey(key : A) : Option[B]
key - the key to be removed
def
clear : Unit
key to a value.
Return that value if it exists, otherwise put default
as that key's value and return it.f.f - The transformation to apply
def
retain(p : (A, B) => Boolean) : MapLike[A, B, This]
p returns true.p - The test predicateoverride
def
clone : This
The default implementation of the clone method is platform dependent.
def
result : This
override
def
-(elem1 : A, elem2 : A, elems : A*) : This
elem1 - the first element to remove.elem2 - the second element to remove.elems - the remaining elements to remove.override
def
--(iter : Traversable[A]) : This
iter - the Traversable object.override
def
--(iter : Iterator[A]) : This
iter - the iterator|
Scala Library
|
|