Report a bug
If you spot a problem with this page, click here to create a Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using a local clone.

core.internal.newaa

template implementation of associative arrays.
Authors:
Martin Nowak, Steven Schveighoffer, Rainer Schuetze

Source core/internal/newaa.d

derived from rt/aaA.d

immutable int _aaVersion;
AA version for debuggers, bump whenever changing the layout
struct AA(K, V);
AA wrapper
V[K] _d_aaNew(K, V)();
Allocate associative array data. Called for new SomeAA expression.
Returns:
A new associative array.

Note not supported in CTFE

size_t _d_aaLen(K, V)(inout V[K] a);
Determine number of entries in associative array.

Note emulated by the compiler during CTFE

V* _d_aaGetY(K, V, T : V1[K1], K1, V1, K2)(auto ref scope T aa, auto ref K2 key, out bool found);
Lookup key in aa. Called only from implementation of (aa[key]) expressions when value is mutable.
Parameters:
T aa associative array
K2 key reference to the key value
bool found returns whether the key was found or a new entry was added
Returns:
if key was in the aa, a mutable pointer to the existing value. If key was not in the aa, a mutable pointer to newly inserted value which is set to zero
V* _aaGetX(K, V, K2, V2)(auto ref scope V[K] a, auto ref K2 key, out bool found, lazy V2 v2);
Lookup key in aa. Called only from implementation of require, update and d_aaGetY
Parameters:
V[K] a associative array
K2 key reference to the key value
bool found true if the value was found
V2 v2 if key not found, init new value to this (except if type noV2)
Returns:
if key was in the aa, a mutable pointer to the existing value. If key was not in the aa, a mutable pointer to newly inserted value which is set to v2 or is zero-initialized
auto _d_aaGetRvalueX(K, V, K2)(inout V[K] aa, auto ref scope K2 key);

auto _d_aaGetRvalueX(K, V, K2)(shared(V[K]) aa, auto ref scope K2 key);

auto _d_aaGetRvalueX(K, V, K2)(shared const(V[K]) aa, auto ref scope K2 key);

auto _d_aaGetRvalueX(K, V, K2)(immutable(V[K]) aa, auto ref scope K2 key);
Lookup key in aa. Called only from implementation of (aa[key]) expressions when value is not mutable.
Parameters:
V[K] aa associative array
K2 key key value
Returns:
pointer to value if present, null otherwise
auto _aaDup(T : V[K], K, V)(T a);
Creates a new associative array of the same size and copies the contents of the associative array into it.
Parameters:
T a The associative array.
auto _d_aaIn(T : V[K], K, V, K2)(inout T a, auto ref scope K2 key);
Lookup key in aa. Called only from implementation of (key in aa) expressions.
Parameters:
T a associative array opaque pointer
K2 key reference to the key value
Returns:
pointer to value if present, null otherwise
auto _d_aaDel(T : V[K], K, V, K2)(T a, auto ref K2 key);
Delete entry scope const AA, return true if it was present
void _aaClear(K, V)(V[K] a);
Remove all elements from AA.
V[K] _aaRehash(K, V)(V[K] a);
Rehash AA
auto _aaValues(K, V)(inout V[K] a);
Return a GC allocated array of all values
auto _aaKeys(K, V)(inout V[K] a);
Return a GC allocated array of all keys
int _d_aaApply(K, V, DG)(inout V[K] a, DG dg);
foreach opApply over all values

Note emulated by the compiler during CTFE

int _d_aaApply2(K, V, DG)(inout V[K] a, DG dg);
foreach opApply over all key/value pairs

Note emulated by the compiler during CTFE

Impl!(K, V)* _d_assocarrayliteralTX(K, V)(K[] keys, V[] vals);
Construct an associative array of type ti from corresponding keys and values. Called for an AA literal [k1:v1, k2:v2].
Parameters:
K[] keys array of keys
V[] vals array of values
Returns:
A new associative array opaque pointer, or null if keys is empty.
bool _aaEqual(T : AA!(K, V), K, V)(scope T aa1, scope T aa2);
compares 2 AAs for equality
bool _d_aaEqual(K, V)(scope const V[K] a1, scope const V[K] a2);
compares 2 AAs for equality (compiler hook)
bool _aaOpEqual(K, V)(scope AA!(K, V)* aa1, scope AA!(K, V)* aa2);
callback from TypeInfo_AssociativeArray.equals (ignore const for now)
hash_t _aaGetHash(K, V)(AA!(K, V)* paa);
compute a hash callback from TypeInfo_AssociativeArray.xtoHash (ignore scope const for now)
struct AARange(K, V);
aaRange implements a ForwardRange