RosettaCodeData/Task/Collections/M2000-Interpreter/collections-3.m2000

29 lines
1014 B
Plaintext

Module Maps {
\\ Inventory as pairs of keys/values
\\ keys has to be unique
\\ Empty string "" can be used as key
\\ Search, Add and Delete in O(1)
\\ if we use delete we lost the order
\\ keys can be numbers or strings, either can exist in same inventory. Values can be anything (including objects)
\\ 0 can be used for string
\\ Keys must be unique
\\ a variable which hold an inventory is a pointer type
Inventory A=10:="A",20:="B",40:="C"
Print A$(10)="A", A$("20")="B"
\\ split search from retrieval, using key one time
If Exist(A,40) Then Print Eval$(A)="C"
k=Each(A)
While k {
\\ print keys as strings and values
Print Eval$(k, k^), Eval$(k)
}
\\ We can use Sort to sort as numbers or text
Append A, 5:="First"
Sort A as number
\\ Print can print an inventory using columns
Print A ' First A B C
Sort A as text
Print A ' A B C First
}
Maps