ValuesView

public struct ValuesView[K, V] where K: Hashable { /* private fields */ }

Lazy Iterable view over the values of a dictionary.

Returned by Dictionary.values. 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 v in dict.values { print(v) } let sum = dict.values.iter().sum();

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)

Internal — constructs a view from a bucket pointer and capacity. Use Dictionary.values to obtain a view.

ImplementsIterable

Associated Types

type Item = V

Iterable element type — V.

type TargetIterator = ValuesIterator[K, V]

Concrete iterator type returned by iter().

Methods

public func iter() -> ValuesIterator[K, V]

Returns a fresh ValuesIterator[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