Ordered key-value container implemented as an AVL tree.
Known issue: constructing an AVLMap fails compilation with «copy», Name was not found. The module also uses unavailable names isMoved and move in insert, recursive in clear, ASSIGN, debugPrint, and each, times in debugPrint, and print and printList in debugPrint without importing them; the API remains unavailable until the module is repaired. Its clear implementation frees node storage without destroying stored key and value objects; repair that cleanup before using managed keys or values.
AVLMap
Construct with key and value schemas in front of AVLMap: Int32 Int32 AVLMap.
Fields
AVL_MAP: static empty-Tuplemarker.keyType: staticRefto the key schema.valueType: staticRefto the value schema.nodeType: staticRefto the nodeDict. The node has fieldsvalue,key,balance,left, andright;asNodeinterprets a node address as aRefto this node.root: root-node address stored asNatx; this is the only field with run-time storage.
Methods
INIT (--): initializes an empty map.ASSIGN (other --): replaces the map contents with a cloned copy ofother.DIE (--): callsclear; it frees node storage without destroying stored key and value objects.
find
(key -- result) Returns the lookup result for one key.insert
(key value --) Inserts one new key-value pair.erase
(key --) Removes the pair at one key.clear
(--) Removes all pairs and resets the root.debugPrint
(--) Prints one debug view of the tree.Ordering and key semantics
- Keys are compared through
=and<. insertrequires an absent key;eraserequires a present key.insertanderasecheck these preconditions withassert; run-time checks are omitted when the selectedDEBUGdefinition is off, for example with-ndebug, so callers must not rely on rejection in that case.debugPrintvisits the stored pairs in ascending key order.- The module has no size field or method.
- A newly initialized map stores
0nxinrootand therefore has no nodes.
Storage and lifetime
- Each valid
insertallocates one new node;insertis unavailable in the current module, so see the known issue for its unresolved names. erasedestroys and frees exactly one stored node.clearfrees every stored node's storage without destroying the stored key and value objects (theirDIEis not run) and resetsrootto the empty state;DIEandASSIGNuseclear.ASSIGNdeep-clones the whole tree. The new map does not share node storage with the source map.- A stored-value
Reffromfind, whensuccessisTRUE, or fromeachis mutable only through a mutable map path such as@m(throughmit is immutable), and when mutable, writing through it replaces the stored value. - Value refs remain valid across
insertanderaseof another key. Erasing the referenced pair invalidates its ref;clear,ASSIGN, andDIEinvalidate all value refs.
find result and returned refs
each (source body --)
Pops a map (or a view of it) and a body and calls the body once per stored pair in ascending key order; the tree structure is unchanged, but the body may replace stored values only through a mutable source map.
sourcemust provide theAVL_MAPmarker field.- The body receives one record with fields
keyandvalue. key: immutable borrowedRefto the stored key, not a copy.value:Refto the stored value; for its mutability and validity, see Storage and lifetime.
See also
- HashTable: Hash-based map module.
- algorithm: Collection interfaces, comparison helpers, iteration adapters, and view slicing utilities.
- control: Foundational schema aliases, low-level runtime bindings, predicates, stack helpers, control combinators, and numeric utilities.
- Array: Growable array.
- Pool: Pooled storage with reusable numeric keys.