From 95f4c1532aa4fe7f0ec8f733f7e79c85d2c09b52 Mon Sep 17 00:00:00 2001 From: Ryan Liptak Date: Mon, 2 Oct 2023 23:07:28 -0700 Subject: [PATCH] Treap: do not set key to undefined in `remove` to allow re-use of removed nodes --- lib/std/heap/general_purpose_allocator.zig | 2 -- lib/std/treap.zig | 1 - 2 files changed, 3 deletions(-) diff --git a/lib/std/heap/general_purpose_allocator.zig b/lib/std/heap/general_purpose_allocator.zig index 6071a8961e..2870dcee5a 100644 --- a/lib/std/heap/general_purpose_allocator.zig +++ b/lib/std/heap/general_purpose_allocator.zig @@ -913,8 +913,6 @@ pub fn GeneralPurposeAllocator(comptime config: Config) type { // save the node for destruction/insertion into in empty_buckets var node = entry.node.?; entry.set(null); - // restore the node's key since Treap.remove sets it to undefined - node.key = bucket; if (self.cur_buckets[bucket_index] == bucket) { self.cur_buckets[bucket_index] = null; } diff --git a/lib/std/treap.zig b/lib/std/treap.zig index 98e85928d5..383dc1802a 100644 --- a/lib/std/treap.zig +++ b/lib/std/treap.zig @@ -225,7 +225,6 @@ pub fn Treap(comptime Key: type, comptime compareFn: anytype) type { link.* = null; // clean up after ourselves - node.key = undefined; node.priority = 0; node.parent = null; node.children = [_]?*Node{ null, null };