diff --git a/ecmascript/tagged_tree.cpp b/ecmascript/tagged_tree.cpp index 17c4c9d8a1..79d88a1869 100644 --- a/ecmascript/tagged_tree.cpp +++ b/ecmascript/tagged_tree.cpp @@ -481,6 +481,11 @@ JSHandle TaggedTree::Shrink(const JSThread *thread, const JSHa int length = ELEMENTS_START_INDEX + static_cast(newCapacity) * (Derived::ENTRY_SIZE); JSHandle newTree = AdjustTaggedTree(thread, tree, length); + JSTaggedValue fn = tree->GetCompare(); + JSHandle compareFn = JSHandle(thread, fn); + if (!compareFn->IsUndefined() && !compareFn->IsNull()) { + newTree->SetCompare(thread, compareFn.GetTaggedValue()); + } newTree->SetCapacity(thread, newCapacity); return newTree; } diff --git a/test/moduletest/container/container_treeset.js b/test/moduletest/container/container_treeset.js index d245cddf50..20bd9cbdac 100644 --- a/test/moduletest/container/container_treeset.js +++ b/test/moduletest/container/container_treeset.js @@ -240,5 +240,55 @@ if (globalThis["ArkPrivate"] != undefined) { } else { print("Test TreeSet fail: " + flag); } + let treeSet = new fastset((first,second) =>{ + return first > second + }); + let insertArr = [ + 643, + 811, + 807, + 378, + 226, + 195, + 599, + 641, + 494, + 964, + 156, + 419, + 977, + 20, + 788, + 596 + ] + let addItem = function(obj){ + treeSet.add(obj) + } + let removeItem = function(){ + const first = treeSet.getFirstValue() + treeSet.remove(first) + } + for(let i = 0;i < insertArr.length;i++) { + addItem(insertArr[i]) + } + removeItem() + removeItem() + removeItem() + removeItem() + removeItem() + addItem(664) + removeItem() + removeItem() + removeItem() + removeItem() + removeItem() + removeItem() + removeItem() + removeItem() + let resArr = [] + treeSet.forEach(element => { + resArr.push(element) + }); + print(resArr) } export let treesetRes = "Test TreeSet done"; \ No newline at end of file diff --git a/test/moduletest/container/expect_output.txt b/test/moduletest/container/expect_output.txt index aabdae6890..c9bfa80310 100644 --- a/test/moduletest/container/expect_output.txt +++ b/test/moduletest/container/expect_output.txt @@ -25,6 +25,7 @@ Test Stack success!!! Test TreeMap success!!! Test TreeMap set After Clear Success Test TreeSet success!!! +226,195,156,20 Test Vector success!!! Test ArrayList Test Deque done