KeysView
public struct KeysView[K, V] where K: Hashable { /* private fields */ }Lazy Iterable view over the keys of a dictionary.
Returned by Dictionary.keys. Constructing the view is O(1) — it
stores the bucket pointer and capacity. The view is invalidated by
any mutation that may reallocate.
Examples
let dict = ["a": 1, "b": 2];
for k in dict.keys { print(k) }
let arr = Array(from: dict.keys);
Representation
(buckets, capacity) — a pointer into the source dictionary's
bucket array plus the total slot count.
Memory Model
Value type that borrows the source dictionary's buffer.
Initializers
init(buckets: Pointer[Bucket[K, V]], capacity: Int64)
init(buckets: Pointer[Bucket[K, V]], capacity: Int64)Internal — constructs a view from a bucket pointer and capacity.
Use Dictionary.keys to obtain a view.
ImplementsIterable
Associated Types
type Item = K
type Item = KIterable element type — K.
type TargetIterator = KeysIterator[K, V]
type TargetIterator = KeysIterator[K, V]Concrete iterator type returned by iter().
Methods
public func iter() -> KeysIterator[K, V]
public func iter() -> KeysIterator[K, V]Returns a fresh KeysIterator[K, V] over the view.
Each call returns a new iterator starting at the beginning of the bucket array.
Defined in lang/std/collections/dictionary.ks