Explicit instantiation of the Buffer
trait to reduce class file size in subclasses.
Explicit instantiation of the Iterable
trait to reduce class file size in subclasses.
Explicit instantiation of the Map
trait to reduce class file size in subclasses.
Explicit instantiation of the Seq
trait to reduce class file size in subclasses.
Explicit instantiation of the Set
trait to reduce class file size in subclasses.
This class implements mutable maps with AnyRef
keys based on a hash table with open addressing.
Basic map operations on single entries, including contains
and get
, are typically significantly faster with AnyRefMap
than HashMap. Note that numbers and characters are not handled specially in AnyRefMap; only plain equals
and hashCode
are used in comparisons.
Methods that traverse or regenerate the map, including foreach
and map
, are not in general faster than with HashMap
. The methods foreachKey
, foreachValue
, mapValuesNow
, and transformValues
are, however, faster than alternative ways to achieve the same functionality.
Maps with open addressing may become less efficient at lookup after repeated addition/removal of elements. Although AnyRefMap
makes a decent attempt to remain efficient regardless, calling repack
on a map that will no longer have elements removed but will be used heavily may save both time and storage space.
This map is not intended to contain more than 229 entries (approximately 500 million). The maximum capacity is 230, but performance will degrade rapidly as 230 is approached.
An implementation of the Buffer
class using an array to represent the assembled sequence internally. Append, update and random access take constant time (amortized time). Prepends and removes are linear in the buffer size.
the type of this arraybuffer's elements.
1
"Scala's Collection Library overview" section on Array Buffers
for more information.
A builder class for arrays.
the type of the elements for the builder.
2.8
An implementation of a double-ended queue that internally uses a resizable circular buffer Append, prepend, removeFirst, removeLast and random-access (indexed-lookup and indexed-replacement) take amortized constant time. In general, removals and insertions at i-th index are O(min(i, n-i)) and thus insertions and removals from end/beginning are fast.
the type of this ArrayDeque's elements.
2.13
Subclasses must override the ofArray
protected method to return a more specific type.
A collection representing Array[T]
. Unlike ArrayBuffer
it is always backed by the same underlying Array
, therefore it is not growable or shrinkable.
type of the elements in this wrapped array.
2.8
A class for mutable bitsets.
Bitsets are sets of non-negative integers which are represented as variable-size arrays of bits packed into 64-bit words. The memory footprint of a bitset is determined by the largest number stored in it.
"Scala's Collection Library overview" section on Mutable Bitsets
for more information.
Base trait for collection builders.
After calling result()
the behavior of a Builder (which is not also a scala.collection.mutable.ReusableBuilder) is undefined. No further methods should be called. It is common for mutable collections to be their own non-reusable Builder, in which case result()
simply returns this
.
scala.collection.mutable.ReusableBuilder for Builders which can be reused after calling result()
A trait for cloneable collections.
Type of the collection, covariant and with reference types as upperbound.
2.8
This class implements mutable maps using a hashtable with red-black trees in the buckets for good worst-case performance on hash collisions. An Ordering
is required for the element type. Equality as determined by the Ordering
has to be consistent with equals
and hashCode
. Universal equality of numeric types is not supported (similar to AnyRefMap
).
2.13
"Scala's Collection Library overview" section on Hash Tables
for more information.
The canonical builder for collections that are growable, i.e. that support an efficient +=
method which adds an element to the collection.
GrowableBuilders can produce only a single instance of the collection they are growing.
2.8
This class implements mutable maps using a hashtable.
the type of the keys contained in this hash map.
the type of the values assigned to keys in this hash map.
1
"Scala's Collection Library overview" section on Hash Tables
for more information.
This class implements mutable sets using a hashtable.
1
"Scala's Collection Library overview" section on Hash Tables
for more information.
This class implements mutable maps using a hashtable. The iterator and all traversal methods of this class visit elements in the order they were inserted.
the type of the keys contained in this hash map.
the type of the values assigned to keys in this hash map.
This class implements mutable sets using a hashtable. The iterator and all traversal methods of this class visit elements in the order they were inserted.
the type of the elements contained in this set.
1
A Buffer
implementation backed by a list. It provides constant time prepend and append. Most other operations are linear.
the type of this list buffer's elements.
1
"Scala's Collection Library overview" section on List Buffers
for more information.
This class implements mutable maps with Long
keys based on a hash table with open addressing.
Basic map operations on single entries, including contains
and get
, are typically substantially faster with LongMap
than HashMap. Methods that act on the whole map, including foreach
and map
are not in general expected to be faster than with a generic map, save for those that take particular advantage of the internal structure of the map: foreachKey
, foreachValue
, mapValuesNow
, and transformValues
.
Maps with open addressing may become less efficient at lookup after repeated addition/removal of elements. Although LongMap
makes a decent attempt to remain efficient regardless, calling repack
on a map that will no longer have elements removed but will be used heavily may save both time and storage space.
This map is not intended to contain more than 229 entries (approximately 500 million). The maximum capacity is 230, but performance will degrade rapidly as 2^30 is approached.
A trait for mutable maps with multiple values assigned to a key.
This class is typically used as a mixin. It turns maps which map K
to Set[V]
objects into multimaps that map K
to V
objects.
// first import all necessary types from package `collection.mutable` import collection.mutable.{ HashMap, MultiMap, Set } // to create a `MultiMap` the easiest way is to mixin it into a normal // `Map` instance val mm = new HashMap[Int, Set[String]] with MultiMap[Int, String] // to add key-value pairs to a multimap it is important to use // the method `addBinding` because standard methods like `+` will // overwrite the complete key-value pair instead of adding the // value to the existing key mm.addBinding(1, "a") mm.addBinding(2, "b") mm.addBinding(1, "c") // mm now contains `Map(2 -> Set(b), 1 -> Set(c, a))` // to check if the multimap contains a value there is method // `entryExists`, which allows to traverse the including set mm.entryExists(1, _ == "a") == true mm.entryExists(1, _ == "b") == false mm.entryExists(2, _ == "b") == true // to remove a previous added value there is the method `removeBinding` mm.removeBinding(1, "a") mm.entryExists(1, _ == "a") == false
This class implements priority queues using a heap. To prioritize elements of type A there must be an implicit Ordering[A] available at creation.
If multiple elements have the same priority in the ordering of this PriorityQueue, no guarantees are made regarding the order in which elements are returned by dequeue
or dequeueAll
. In particular, that means this class does not guarantee first in first out behaviour that may be incorrectly inferred from the Queue part of the name of this class.
Only the dequeue
and dequeueAll
methods will return elements in priority order (while removing elements from the heap). Standard collection methods including drop
, iterator
, and toString
will remove or traverse the heap in whichever order seems most convenient.
Therefore, printing a PriorityQueue
will not reveal the priority order of the elements, though the highest-priority element will be printed first. To print the elements in order, one must duplicate the PriorityQueue
(by using clone
, for instance) and then dequeue them:
type of the elements in this priority queue.
val pq = collection.mutable.PriorityQueue(1, 2, 5, 3, 7) println(pq) // elements probably not in order println(pq.clone.dequeueAll) // prints ArraySeq(7, 5, 3, 2, 1)
1
Queue
objects implement data structures that allow to insert and retrieve elements in a first-in-first-out (FIFO) manner.
2.13
ReusableBuilder
is a marker trait that indicates that a Builder
can be reused to build more than one instance of a collection. In particular, calling result()
followed by clear()
will produce a collection and reset the builder to begin building a new collection of the same type.
In general no method other than clear()
may be called after result()
. It is up to subclasses to implement and to document other allowed sequences of operations (e.g. calling other methods after result()
in order to obtain different snapshots of a collection under construction).
the type of elements that get added to the builder.
the type of collection that it produced.
2.12
A generic trait for ordered mutable maps. Concrete classes have to provide functionality for the abstract methods in SeqMap
.
Note that when checking for equality SeqMap does not take into account ordering.
the type of the keys contained in this linked map.
the type of the values associated with the keys in this linked map.
2.13
2.13
This trait forms part of collections that can be reduced using a -=
operator.
2.8
A stack implements a data structure which allows to store and retrieve objects in a last-in-first-out (LIFO) fashion.
type of the elements contained in this stack.
(Changed in version 2.13.0) Stack is now based on an ArrayDeque instead of a linked list
2.13
A builder for mutable sequence of characters. This class provides an API mostly compatible with java.lang.StringBuilder
, except where there are conflicts with the Scala collections API (such as the reverse
method.)
This Builder can be reused after calling result()
without an intermediate call to clear()
in order to build multiple related results.
2.7
A mutable sorted map implemented using a mutable red-black tree as underlying data structure.
the type of the keys contained in this tree map.
the type of the values associated with the keys.
2.12
A mutable sorted set implemented using a mutable red-black tree as underlying data structure.
the type of the keys contained in this tree set.
2.10
A buffer that stores elements in an unrolled linked list.
Unrolled linked lists store elements in linked fixed size arrays.
Unrolled buffers retain locality and low memory overhead properties of array buffers, but offer much more efficient element addition, since they never reallocate and copy the internal array.
However, they provide O(n/m)
complexity random access, where n
is the number of elements, and m
the size of internal array chunks.
Ideal to use when:
concat
)Better than singly linked lists for random access, but should still be avoided for such a purpose.
A hash map with references to entries which are weakly reachable. Entries are removed from this map when the key is no longer (strongly) referenced. This class wraps java.util.WeakHashMap
.
type of keys contained in this map
type of values associated with the keys
2.8
"Scala's Collection Library overview" section on Weak Hash Maps
for more information.
Factory object for the ArrayBuffer
class.
This object provides a set of operations to create mutable.ArrayBuffer
values.
A companion object for array builders.
2.8
This object provides a set of operations to create ArrayDeque
values.
A companion object used to create instances of ArraySeq
.
This object provides a set of operations to create mutable.CollisionProofHashMap
values.
This object provides a set of operations to create mutable.HashMap
values.
This object provides a set of operations to create mutable.HashSet
values.
This object provides a set of operations to create mutable.Iterable
values.
This object provides a set of operations to create LinkedHashMap
values.
This object provides a set of operations to create LinkedHashSet
values.
This object provides a set of operations to create mutable.Map
values.
This object provides a set of operations to create Queue
values.
This object provides a set of operations to create mutable.Seq
values.
This object provides a set of operations to create mutable.Set
values.
This object provides a set of operations to create mutable.Sortedset
values.
This object provides a set of operations to create Stack
values.
This object provides a set of operations to create mutable.TreeMap values.
This object provides a set of operations to create mutable.TreeSet
values.
This object provides a set of operations to create WeakHashMap
values.
© 2002-2019 EPFL, with contributions from Lightbend.
Licensed under the Apache License, Version 2.0.
https://www.scala-lang.org/api/2.13.0/scala/collection/mutable/index.html