ae.utils.aa

Associative Array utility functions

Members

Aliases

HashSet
alias HashSet(T) = HashCollection!(T, void, false, false)

Helper/wrapper for void[0]T

MultiAA
alias MultiAA(K, V) = HashCollection!(K, V, false, true)

An object which acts mostly as an associative array, with the added property of being able to hold keys with multiple values. These are only exposed explicitly and through iteration

OrderedMap
alias OrderedMap(K, V) = HashCollection!(K, V, true, false)

An associative array which retains the order in which elements were added.

OrderedSet
alias OrderedSet(T) = HashCollection!(T, void, true, false)

An ordered set of T, which retains the order in which elements are added.

update
alias update = updatePolyfill

Work around https://issues.dlang.org/show_bug.cgi?id=15795

update
alias update = updateVoid

Work around https://issues.dlang.org/show_bug.cgi?id=15795

updateVoid
alias updateVoid = object.update
Undocumented in source.

Functions

aaGet
auto ref aaGet(AA aa, K key)

Get a value from an AA, and throw an exception (not an error) if not found

addNew
bool addNew(V[K] aa, K key, V value)
bool addNew(HashCollection!(K, V, ordered, multi) aa, K key, V value)

If key is not in aa, add it with the given value, and return true. Otherwise, return false.

getOrAdd
V getOrAdd(V[K] aa, K key, V defaultValue)
V getOrAdd(V[K] aa, K key)

If key is not in aa, add it with defaultValue. Returns a reference to the value corresponding to key.

merge
V[K] merge(V[K] target, V[K] source)

Merge source into target. Return target.

nonNull
V[K] nonNull(V[K] aa)

Ensure that arr is non-null if empty.

orderedMap
auto orderedMap(R input)

Like assocArray

orderedMap
auto orderedMap(R input)
Undocumented in source. Be warned that the author may not have intended to support it.
orderedSet
auto orderedSet(R r)

Construct an ordered set from the range r.

pairs
deprecated KeyValuePair!(K, V)[] pairs(V[K] aa)

Get key/value pairs from AA

require
V require(V[K] aa, K key, V value)

Polyfill for object.require

sortedPairs
KeyValuePair!(K, V)[] sortedPairs(V[K] aa)

Get key/value pairs from AA, sorted by keys

sortedValues
V[] sortedValues(V[K] aa)

Get values from AA, sorted by keys

toAA
auto toAA(R r)

Slurp a range of two elements (or two-element struct/class) into an AA.

toSet
auto toSet(R r)

Construct a set from the range r.

updatePolyfill
void updatePolyfill(V[K] aa, K key, C create, U update)

Polyfill for object.update

updateVoid
void updateVoid(V[K] aa, K key, C create, U update)

Polyfill for object.update with void update function

Structs

HashCollection
struct HashCollection(K, V, bool ordered, bool multi)

Base type for ordered/unordered single-value/multi-value map/set

KeyValuePair
struct KeyValuePair(K, V)

Key/value pair

Meta

License

This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

Authors

Vladimir Panteleev <ae@cy.md>