diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-12-18 13:22:11 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-12-18 13:22:11 -0800 |
commit | 8248110871d18e9ceed422076de5e36bf212e127 (patch) | |
tree | 811a88bc0646c39aad677ba2b045acfdd396e058 /tests | |
parent | 236a11759c4f0ccdd809621a990da2e0ae138def (diff) | |
download | txr-8248110871d18e9ceed422076de5e36bf212e127.tar.gz txr-8248110871d18e9ceed422076de5e36bf212e127.tar.bz2 txr-8248110871d18e9ceed422076de5e36bf212e127.zip |
tree: bugfix wrong tree-count.
When duplicate keys are inserted in the default way with
replacement, the tree size must not be incremented.
* tree.c (tr_insert): Increment the tr->size and maintain
tr->max_size here. In the case of replacing an existing node,
do not touch the count.
* tests/010/tree.tl: Add test cases covering duplicate
insertion and tree-count.
(tree_insert_node): Remove unconditional size increment.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/010/tree.tl | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/tests/010/tree.tl b/tests/010/tree.tl index 898fd91d..79bab793 100644 --- a/tests/010/tree.tl +++ b/tests/010/tree.tl @@ -216,3 +216,13 @@ (let* ((items (make-items)) (tr (tree items : : : t))) (vtest (vec-list [mapcar .label tr]) [mapcar .label items])) + +(let ((tr (tree))) + (mtest + (tree-insert tr 1) #N(1 nil nil) + (tree-insert tr 1) #N(1 nil nil) + (tree-insert tr 1) #N(1 nil nil)) + (tree-insert tr 2) + (test (tree-count tr) 2) + (tree-insert tr 1 t) + (test (tree-count tr) 3)) |