diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-05-09 12:08:55 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-05-09 12:08:55 -0700 |
commit | 8a7a4963a6cdf0a0d8b7145aefb4a40f5f26c673 (patch) | |
tree | d624f4fede1507921bf4cd856a44ff012ab80c11 /tree.c | |
parent | 4c6c110dfc3f10777fb7c9334c054d3407358af0 (diff) | |
download | txr-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.c | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -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)); |