terminal: refcountedset passes base memory to all context funcs

This enables these funcs to access memory offsets that may be present in
set items, which is possible since the set itself is in an offset-based
structure.
This commit is contained in:
Mitchell Hashimoto
2024-07-03 16:18:00 -07:00
parent 2a7755c515
commit cb1caff018
2 changed files with 10 additions and 8 deletions

View File

@ -264,7 +264,7 @@ pub fn RefCountedSet(
self.living += 1;
return if (added_id == id) null else added_id;
} else if (self.context.eql(value, items[id].value)) {
} else if (self.context.eql(base, value, items[id].value)) {
items[id].meta.ref += 1;
return null;
@ -390,7 +390,7 @@ pub fn RefCountedSet(
if (comptime @hasDecl(Context, "deleted")) {
// Inform the context struct that we're
// deleting the dead item's value for good.
self.context.deleted(item.value);
self.context.deleted(base, item.value);
}
self.psl_stats[item.meta.psl] -= 1;
@ -423,7 +423,7 @@ pub fn RefCountedSet(
const table = self.table.ptr(base);
const items = self.items.ptr(base);
const hash: u64 = self.context.hash(value);
const hash: u64 = self.context.hash(base, value);
for (0..self.max_psl + 1) |i| {
const p: usize = @intCast((hash + i) & self.layout.table_mask);
@ -455,7 +455,7 @@ pub fn RefCountedSet(
// If the item is a part of the same probe sequence,
// we check if it matches the value we're looking for.
if (item.meta.psl == i and
self.context.eql(value, item.value))
self.context.eql(base, value, item.value))
{
return id;
}
@ -481,7 +481,7 @@ pub fn RefCountedSet(
.meta = .{ .psl = 0, .ref = 0 },
};
const hash: u64 = self.context.hash(value);
const hash: u64 = self.context.hash(base, value);
var held_id: Id = new_id;
var held_item: *Item = &new_item;
@ -510,7 +510,7 @@ pub fn RefCountedSet(
if (comptime @hasDecl(Context, "deleted")) {
// Inform the context struct that we're
// deleting the dead item's value for good.
self.context.deleted(item.value);
self.context.deleted(base, item.value);
}
chosen_id = id;

View File

@ -247,13 +247,15 @@ pub const Set = RefCountedSet(
Id,
size.CellCountInt,
struct {
pub fn hash(self: *const @This(), style: Style) u64 {
pub fn hash(self: *const @This(), base: anytype, style: Style) u64 {
_ = self;
_ = base;
return style.hash();
}
pub fn eql(self: *const @This(), a: Style, b: Style) bool {
pub fn eql(self: *const @This(), base: anytype, a: Style, b: Style) bool {
_ = self;
_ = base;
return a.eql(b);
}
},