Create the null associative array with no index universe. The first assignment to the array will determine its index universe.
Create the empty associative array with index universe I.
Set the value in A associated with index x to be y. If x is not coercible into the current index universe I of A, then an attempt is first made to lift the index universe of A to contain both I and x.
Given an index x coercible into the index universe I of A, return the value associated with x. If x is not in the keys of A, then an error is raised.
Given an index x coercible into the index universe I of A, return whether x is currently in the keys of A and if so, return also the value A[x].
(Procedure.) Destructively remove the value indexed by x from the array A. If x is not present as an index, then nothing happens (i.e., an error is not raised).
Given an associative array A, return the index universe I of A, in which the keys of A currently lie.
Given an associative array A, return the number of items stored in A.
Given an associative array A, return the current keys of A as a set. Warning: this constructs a new copy of the set of keys, so should only be called when that is needed. It is not meant to be used as a quick access function.
> A := AssociativeArray(); > A[1/2] := 7; > A[3/8] := "abc"; > A[3] := 3/8; > A[1/2]; 7 > IsDefined(A, 3); true 3/8 > IsDefined(A, 4); false > IsDefined(A, 3/8); true abc > Keys(A); { 3/8, 1/2, 3 } > for x in Keys(A) do x, A[x]; end for; 1/2 7 3/8 abc 3 3/8 > Remove(~A, 3/8); > IsDefined(A, 3/8); false > Keys(A); { 1/2, 3 } > Universe(A); Rational FieldWe repeat that an associative array can be indexed by elements of any structure. We now index an array by elements of the symmetric group S3.
> G := Sym(3); > A := AssociativeArray(G); > v := 1; for x in G do A[x] := v; v +:= 1; end for; > A; Associative Array with index universe GrpPerm: G, Degree 3, Order 2 * 3 > Keys(A); { (1, 3, 2), (2, 3), (1, 3), (1, 2, 3), (1, 2), Id(G) } > A[G!(1,3,2)]; 3