summaryrefslogtreecommitdiffstats
path: root/tree.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-05-09 12:08:55 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-05-09 12:08:55 -0700
commit8a7a4963a6cdf0a0d8b7145aefb4a40f5f26c673 (patch)
treed624f4fede1507921bf4cd856a44ff012ab80c11 /tree.c
parent4c6c110dfc3f10777fb7c9334c054d3407358af0 (diff)
downloadtxr-8a7a4963a6cdf0a0d8b7145aefb4a40f5f26c673.tar.gz
txr-8a7a4963a6cdf0a0d8b7145aefb4a40f5f26c673.tar.bz2
txr-8a7a4963a6cdf0a0d8b7145aefb4a40f5f26c673.zip
tree: new make_similar_tree unction.
* tree.c (make_similar_tree): New function. (tree_init): Register make-similar-tree intrinsic * tree.h (make_similar_tree): Declared. * tests/010/tree.tl: New tests. * txr.1: Documented.
Diffstat (limited to 'tree.c')
-rw-r--r--tree.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/tree.c b/tree.c
index 9a7044f0..47bbe8d6 100644
--- a/tree.c
+++ b/tree.c
@@ -711,6 +711,18 @@ val copy_search_tree(val tree)
return ntree;
}
+val make_similar_tree(val tree)
+{
+ val self = lit("make-similar-tree");
+ struct tree *ntr = coerce(struct tree *, malloc(sizeof *ntr));
+ struct tree *otr = coerce(struct tree *, cobj_handle(self, tree, tree_s));
+ val ntree = cobj(coerce(mem_t *, ntr), tree_s, &tree_ops);
+ *ntr = *otr;
+ ntr->root = nil;
+ ntr->size = ntr->max_size = 0;
+ return ntree;
+}
+
val treep(val obj)
{
return tnil(type(obj) == COBJ && obj->co.cls == tree_s);
@@ -834,6 +846,7 @@ void tree_init(void)
reg_fun(tree_s, func_n4o(tree, 0));
reg_fun(tree_construct_s, func_n2(tree_construct));
reg_fun(intern(lit("copy-search-tree"), user_package), func_n1(copy_search_tree));
+ reg_fun(intern(lit("make-similar-tree"), user_package), func_n1(make_similar_tree));
reg_fun(intern(lit("treep"), user_package), func_n1(treep));
reg_fun(intern(lit("tree-insert-node"), user_package), func_n2(tree_insert_node));
reg_fun(intern(lit("tree-insert"), user_package), func_n2(tree_insert));