From 626a5ce0fa875f4a23bcf4d175b2e45949c2b0f5 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Mon, 10 May 2021 06:59:53 -0700 Subject: diff/isec: reset hash/tree iter instead making new. * lib.c (seq_iter_rewind): Use hash_reset and tree_reset to rewind the existing iterator rather than allocating a new one. * tests/010/hash.tl: New file, covering uni, diff and isec for hash tables. * tests/010/tree.tl: New tests. --- lib.c | 4 ++-- tests/010/hash.tl | 6 ++++++ tests/010/tree.tl | 5 +++++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 tests/010/hash.tl diff --git a/lib.c b/lib.c index 6145c4f3..5419494e 100644 --- a/lib.c +++ b/lib.c @@ -740,10 +740,10 @@ static void seq_iter_rewind(seq_iter_t *it, val self) it->ui.index = 0; break; case SEQ_HASHLIKE: - it->ui.iter = hash_begin(it->inf.obj); + it->ui.iter = hash_reset(it->ui.iter, it->inf.obj); break; case SEQ_TREELIKE: - it->ui.iter = tree_begin(it->inf.obj); + it->ui.iter = tree_reset(it->ui.iter, it->inf.obj); break; default: break; diff --git a/tests/010/hash.tl b/tests/010/hash.tl new file mode 100644 index 00000000..b8c386e2 --- /dev/null +++ b/tests/010/hash.tl @@ -0,0 +1,6 @@ +(load "../common") + +(mtest + (uni #H(() ("a") ("b")) #H(() ("b") ("c"))) (("a") ("b") ("c")) + (diff #H(() ("a") ("b")) #H(() ("b") ("c"))) (("a")) + (isec #H(() ("a") ("b")) #H(() ("b") ("c"))) (("b"))) diff --git a/tests/010/tree.tl b/tests/010/tree.tl index 86a21167..c2fe5382 100644 --- a/tests/010/tree.tl +++ b/tests/010/tree.tl @@ -127,3 +127,8 @@ tr #T((identity < =) 1 2 3) (copy-search-tree tr) #T((identity < =) 1 2 3) (make-similar-tree tr) #T((identity < =)))) + +(mtest + (uni #T(() "a" "b") #T(() "b" "c")) ("a" "b" "c") + (diff #T(() "a" "b") #T(() "b" "c")) ("a") + (isec #T(() "a" "b") #T(() "b" "c")) ("b")) -- cgit v1.2.3