This package implements linear maps based on the singly-linked list structure. Note that this is only practical for maps of short size (e.g., containing only a few dozens keys).
stadef map = map_vtype
absvtype
map_vtype (key:t@ype, itm:vt@ype+) = ptr
fun{key:t0p}
equal_key_key (x1: key, x2: key):<> bool
fun{key:t0p}
compare_key_key (x1: key, x2: key):<> int
fun{}
linmap_nil {key:t0p;itm:vt0p} ():<> map (key, itm)
fun{}
linmap_make_nil {key:t0p;itm:vt0p} ():<!wrt> map (key, itm)
fun{
} linmap_is_nil
{key:t0p;itm:vt0p} (map: !map (key, INV(itm))):<> bool
fun{
} linmap_isnot_nil
{key:t0p;itm:vt0p} (map: !map (key, INV(itm))):<> bool
fun{
key:t0p;itm:vt0p
} linmap_size (map: !map (key, INV(itm))):<> size_t
fun{ key:t0p;itm:t0p } linmap_search ( !map (key, INV(itm)), key, res: &itm? >> opt (itm, b) ) : #[b:bool] bool(b) (*found*) // endfun
fun{
key:t0p;itm:vt0p
} linmap_search_ref
(map: !map (key, INV(itm)), k0: key): cPtr0 (itm)
fun{
key:t0p;itm:t0p
} linmap_search_opt
(map: !map (key, INV(itm)), k0: key): Option_vt (itm)
fun{ key:t0p;itm:vt0p } linmap_insert ( &map (key, INV(itm)) >> _, key, itm, res: &itm? >> opt (itm, b) ) : #[b:bool] bool(b) // endfun
fun{
key:t0p;itm:vt0p
} linmap_insert_opt
(map: &map (key, INV(itm)) >> _, k0: key, x0: itm): Option_vt (itm)
fun{
key:t0p;itm:vt0p
} linmap_insert_any
(map: &map (key, INV(itm)) >> _, k0: key, x0: itm): void
fun{ key:t0p;itm:vt0p } linmap_takeout ( &map (key, INV(itm)) >> _, key, res: &itm? >> opt (itm, b) ) : #[b:bool] bool(b) // endfun
fun{
key:t0p;itm:vt0p
} linmap_takeout_opt
(map: &map (key, INV(itm)) >> _, k0: key): Option_vt (itm)
fun{
key:t0p;itm:t0p
} linmap_remove (
map: &map (key, INV(itm)) >> _, k0: key): bool
fun{
key:t0p;itm:vt0p
} linmap_foreach (map: !map (key, INV(itm))): void
fun
{key:t0p
;itm:vt0p}
{env:vt0p}
linmap_foreach_env
(map: !map (key, INV(itm)), env: &(env) >> _): void
fun
{key:t0p
;itm:vt0p}
{env:vt0p}
linmap_foreach$fwork
(k: key, x: &itm >> _, env: &(env) >> _): void
fun{
key:t0p;itm:t0p
} linmap_free (map: map (key, INV(itm))):<!wrt> void
fun{
key:t0p;itm:vt0p
} linmap_freelin (map: map (key, INV(itm))):<!wrt> void
fun{
itm:vt0p
} linmap_freelin$clear (x: &itm >> _?):<!wrt> void
fun{ key:t0p;itm:vt0p } linmap_free_ifnil ( map: !map (key, INV(itm)) >> opt (map (key, itm), b) ) :<!wrt> #[b:bool] bool(b) (*~freed*) // endfun
fun
{key:t0p
;itm:vt0p}
linmap_listize
(map: map (key, INV(itm))):<!wrt> List_vt @(key, itm)
fun
{key:t0p
;itm:vt0p}
{ki2:vt0p}
linmap_flistize (map: map (key, INV(itm))): List_vt (ki2)
fun
{key:t0p
;itm:vt0p}
{ki2:vt0p}
linmap_flistize$fopr (k: key, x: itm): ki2
fun{
key,itm:t0p
} linmap_listize1
(map: !map (key, INV(itm))):<!wrt> List_vt @(key, itm)
absvtype
linmap_node_vtype
(key:t@ype, itm:vt@ype+, l:addr) = ptr(l)
stadef mynode = linmap_node_vtype // HX: local shorthand
vtypedef mynode (key:t0p, itm:vt0p) = [l:addr] mynode (key, itm, l)
vtypedef mynode0 (key:t0p, itm:vt0p) = [l:addr | l >= null] mynode (key, itm, l)
vtypedef mynode1 (key:t0p, itm:vt0p) = [l:addr | l > null] mynode (key, itm, l)
fun{
key:t0p;itm:vt0p
} mynode_make_keyitm
(k: key, x: itm):<!wrt> mynode1 (key, itm)
fun{
key:t0p;itm:vt0p
} mynode_get_key
(nx: !mynode1 (key, INV(itm))):<> key
fun{
key:t0p;itm:vt0p
} mynode_getref_itm
(nx: !mynode1 (key, INV(itm))):<> cPtr1 (itm)
fun{
key:t0p;itm:vt0p
} mynode_getfree_itm (nx: mynode1 (key, INV(itm))):<!wrt> itm
fun{ key:t0p;itm:vt0p } mynode_free_keyitm ( nx: mynode1(key, INV(itm)), k0: &key? >> _, x0: &itm? >> _ ) :<!wrt> void // end of [mynode_free_keyitm]
fun{ key:t0p;itm:vt0p } linmap_search_ngc (map: !map (key, INV(itm)), k0: key): Ptr0(*mynode*)
fun{ key:t0p;itm:vt0p } linmap_insert_ngc ( map: &map (key, INV(itm)) >> _, nx: mynode1 (key, itm) ) : mynode0 (key, itm) // endfun
fun{
key:t0p;itm:vt0p
} linmap_takeout_ngc
(map: &map (key, INV(itm)) >> _, k0: key): mynode0 (key, itm)
This page is created with ATS by Hongwei Xi and also maintained by Hongwei Xi. |