!8270 BugFix treeset remove firstValue

Merge pull request !8270 from 王笑佳/master
This commit is contained in:
openharmony_ci 2024-07-22 05:43:30 +00:00 committed by Gitee
commit 9175348584
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 56 additions and 0 deletions

View File

@ -481,6 +481,11 @@ JSHandle<Derived> TaggedTree<Derived>::Shrink(const JSThread *thread, const JSHa
int length = ELEMENTS_START_INDEX + static_cast<int>(newCapacity) * (Derived::ENTRY_SIZE);
JSHandle<Derived> newTree = AdjustTaggedTree(thread, tree, length);
JSTaggedValue fn = tree->GetCompare();
JSHandle<JSTaggedValue> compareFn = JSHandle<JSTaggedValue>(thread, fn);
if (!compareFn->IsUndefined() && !compareFn->IsNull()) {
newTree->SetCompare(thread, compareFn.GetTaggedValue());
}
newTree->SetCapacity(thread, newCapacity);
return newTree;
}

View File

@ -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";

View File

@ -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