|
x-engine-c v0.2.13
The C engine for x-lang
|
Association list interface. More...
#include "x-obj.h"Go to the source code of this file.
Functions | |
Linear Association List | |
Extend and search association lists using linear traversal. | |
| x_obj_t * | x_alist_extend (x_obj_t *p_base, x_obj_t *p_args) |
| x_obj_t * | x_alist_assoc (x_obj_t *p_base, x_obj_t *p_args) |
BST Association List | |
Binary-search-tree index over alist entries, keyed by symbol pointer. Node structure: | |
| x_obj_t * | x_alist_bst_lookup (x_obj_t *p_base, x_obj_t *p_tree, x_obj_t *p_sym) |
| x_obj_t * | x_alist_bst_insert (x_obj_t *p_base, x_obj_t *p_tree, x_obj_t *p_entry) |
Association list interface.
Provides linear and BST-backed association list operations for the environment model. An alist is a list of (key . value) entries; the BST variant indexes those entries by symbol pointer for faster lookup.
Look up a symbol in an alist by linear scan.
Linear alist lookup by pointer identity on the key's first field.
Walks the alist front-to-back, comparing (first (first (first entry))) against (first obj). Returns the first matching entry, or NULL.
| p_base | x_obj_t* – Base (execution context) |
| p_args | x_obj_t* – (key . (alist)) |
Insert an entry into a BST alist.
In-place BST insert into the global env tree.
MUTATES the tree in place; every environment whose chain reaches the root sees the new entry, which is required: a top-level (def ...) must become visible to fn closures created before it. The key is the symbol object: an entry for the SAME object replaces the old one, and an entry for a same-spelled but different object – one interned in another base – is another name and gets its own node, to the right of the first, the side lookup takes for an equal spelling that is not the same object. The returned root equals the input root except when the tree was empty (the caller must then store the returned first node).
| p_base | x_obj_t* – Base (execution context) |
| p_tree | x_obj_t* – Existing BST root, or NULL for empty |
| p_entry | x_obj_t* – (symbol . value) entry to insert |
p_tree was empty)Find an entry in a BST alist by symbol pointer.
BST lookup by symbol identity.
Searches the tree for the entry whose key IS p_sym. A hit is pointer equality and nothing else: names are found by identity, not by spelling, so a same-spelled symbol interned in another base is another name and misses. The spelling only steers the walk – smaller to the left, greater to the right, and an equal spelling that is not the same object counts as greater, which is where x_alist_bst_insert put it. Node structure: (entry . (left . right)).
| p_base | x_obj_t* – Base (execution context) |
| p_tree | x_obj_t* – BST root node, or NULL |
| p_sym | x_obj_t* – Symbol to look up |
Prepend an entry to an alist.
Prepend an association to an alist.
Conses p_assoc onto the front of p_alist, returning the new list.
| p_base | x_obj_t* – Base (execution context) |
| p_args | x_obj_t* – (assoc . alist) |