From 337ffc1e586d48b5fe6a334a6fd61587961fe261 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 16 Oct 2019 00:05:08 -0700 Subject: 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. --- lib.c | 2 ++ tree.c | 8 ++++++++ tree.h | 1 + txr.1 | 19 +++++++++++++++++++ 4 files changed, 30 insertions(+) diff --git a/lib.c b/lib.c index ea7f7495..81f3d06d 100644 --- a/lib.c +++ b/lib.c @@ -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); diff --git a/tree.c b/tree.c index 22cac379..43330c06 100644 --- a/tree.c +++ b/tree.c @@ -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)); diff --git a/tree.h b/tree.h index 94270b4b..0f056429 100644 --- a/tree.h +++ b/tree.h @@ -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); diff --git a/txr.1 b/txr.1 index ad97ed52..5bc31393 100644 --- a/txr.1 +++ b/txr.1 @@ -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 ]]]]) -- cgit v1.2.3