Argentum standard library has three hash maps: Map, SharedMap, WeakMap.
Most of design details of Maps are similar to Arrays:
- They are not built in the language.
- On indexation they return optional type, indicating if element exists in the map.
- Their semantics reflects one of pointers.
- They are of variable size and initially empty.
- They can be frozen and turned into shared-immutable.
These maps are unordered key-value containers, where:
- keys are always shared immutable objects
- values are own, shared or weak pointers respectively.
Internally they are implemented as flat, open addressed, 2n grow, linear probe, robin hood hashing maps.
using sys { Map }
class Pt{
x = 0; y = 0;
call(ax, int, ay int) this { x:= ax; y := ay }
}
m = Map(String, Pt)
("Alpha", Pt(1, 2))
("Bravo", Pt(-1, 42));
log(m["Aplha"]
? "Pt({_.x}, {_.y})"
: "Not found");
// It prints Pt(1, 2)
Why keys are always immutable
TBD
User types as keys
TBD