11/*
2- * Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
3131#include " utilities/growableArray.hpp"
3232#include " utilities/macros.hpp"
3333#include " utilities/powerOfTwo.hpp"
34+ #include < type_traits>
3435
3536// A Treap is a self-balanced binary tree where each node is equipped with a
3637// priority. It adds the invariant that the priority of a parent P is strictly larger
@@ -228,7 +229,9 @@ class Treap {
228229 : _allocator(),
229230 _root(nullptr ),
230231 _prng_seed(_initial_seed),
231- _node_count(0 ) {}
232+ _node_count(0 ) {
233+ static_assert (std::is_trivially_destructible<K>::value, " must be" );
234+ }
232235
233236 ~Treap () {
234237 this ->remove_all ();
@@ -266,6 +269,7 @@ class Treap {
266269 if (second_split.right != nullptr ) {
267270 // The key k existed, we delete it.
268271 _node_count--;
272+ second_split.right ->_value .~V ();
269273 _allocator.free (second_split.right );
270274 }
271275 // Merge together everything
@@ -283,6 +287,7 @@ class Treap {
283287 if (head == nullptr ) continue ;
284288 to_delete.push (head->_left );
285289 to_delete.push (head->_right );
290+ head->_value .~V ();
286291 _allocator.free (head);
287292 }
288293 _root = nullptr ;
0 commit comments