diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2019-10-16 00:05:08 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2019-10-16 00:05:08 -0700 |
commit | 337ffc1e586d48b5fe6a334a6fd61587961fe261 (patch) | |
tree | 1bc2179b76884142de6d00a6361fe6029ba6b99f | |
parent | c59462de5168b4050ff8517e8215a7692949e85b (diff) | |
download | txr-337ffc1e586d48b5fe6a334a6fd61587961fe261.tar.gz txr-337ffc1e586d48b5fe6a334a6fd61587961fe261.tar.bz2 txr-337ffc1e586d48b5fe6a334a6fd61587961fe261.zip |
tree: introduce copy-tnode.
* lib.c (copy): Handle TNOD casee via copy_tnode.
* tree.c (copy_tnode): New function.
(tree_init): copy-tnode intrinsic registered.
* tree.h (copy_tnode): Declared.
* txr.1: copy function documented as handling tnode type via
copy-tnode. That function is documented.
-rw-r--r-- | lib.c | 2 | ||||
-rw-r--r-- | tree.c | 8 | ||||
-rw-r--r-- | tree.h | 1 | ||||
-rw-r--r-- | txr.1 | 19 |
4 files changed, 30 insertions, 0 deletions
@@ -10072,6 +10072,8 @@ val copy(val seq) return copy_buf(seq); case FUN: return copy_fun(seq); + case TNOD: + return copy_tnode(seq); case COBJ: if (seq->co.cls == hash_s) return copy_hash(seq); @@ -119,6 +119,13 @@ val key(val node) return node->tn.key; } +val copy_tnode(val node) +{ + val obj = (type_check(lit("copy-tnode"), node, TNOD), make_obj()); + obj->tn = node->tn; + return obj; +} + static ucnum tn_size(val node) { return 1 + if3(node->tn.right, tn_size(node->tn.right), 0) + @@ -677,6 +684,7 @@ void tree_init(void) reg_fun(intern(lit("left"), user_package), func_n1(left)); reg_fun(intern(lit("right"), user_package), func_n1(right)); reg_fun(intern(lit("key"), user_package), func_n1(key)); + reg_fun(intern(lit("copy-tnode"), user_package), func_n1(copy_tnode)); reg_fun(tree_s, func_n4o(tree, 0)); reg_fun(tree_construct_s, func_n2(tree_construct)); reg_fun(intern(lit("treep"), user_package), func_n1(treep)); @@ -34,6 +34,7 @@ val tnodep(val obj); val left(val node); val right(val node); val key(val node); +val copy_tnode(val node); val tree(val keys, val key_fn, val less_fn, val equal_fn); val treep(val obj); val tree_insert_node(val tree, val node); @@ -28073,6 +28073,8 @@ the type of the argument, as follows: .meti (copy-carray << object ) .coIP random-state .meti (make-random-state << object ) +.coIP tnode +.meti (copy-tnode << object ) .RE .IP @@ -45230,6 +45232,23 @@ functions retrieve the corresponding fields of the object, which must be of type .codn tnode . +.coNP Function @ copy-tnode +.synb +.mets (copy-tnode << node ) +.syne +.desc +The +.code copy-tnode +function creates a new +.code tnode +objects, whose +.codn key , +.code left +and +.code right +fields are copied from +.codn node . + .coNP Function @ tree .synb .mets (tree >> [ elems >> [ keyfun >> [ lessfun <> [ equalfun ]]]]) |