as's not needed
This commit is contained in:
parent
b1ac3f4631
commit
b2a92c5c51
|
@ -77,7 +77,7 @@ pub fn Table(comptime K: type, comptime V: type) type {
|
|||
}
|
||||
|
||||
pub fn exists(self: *const Self, id: Id) bool {
|
||||
return id.index < self.values.items.len and id.gen == self.gens.items[@as(usize, id.index)];
|
||||
return id.index < self.values.items.len and id.gen == self.gens.items[id.index];
|
||||
}
|
||||
|
||||
pub const AddResult = struct {
|
||||
|
@ -94,11 +94,9 @@ pub fn Table(comptime K: type, comptime V: type) type {
|
|||
}
|
||||
|
||||
if (self.free_list.popOrNull()) |index| {
|
||||
const uindex = @as(usize, index);
|
||||
|
||||
const gen = self.gens.items[uindex];
|
||||
self.keys.items[uindex] = key;
|
||||
self.values.items[uindex] = val;
|
||||
const gen = self.gens.items[index];
|
||||
self.keys.items[index] = key;
|
||||
self.values.items[index] = val;
|
||||
try self.lookup.putNoClobber(key, index);
|
||||
self.len += 1;
|
||||
return AddResult{
|
||||
|
@ -139,31 +137,28 @@ pub fn Table(comptime K: type, comptime V: type) type {
|
|||
assert(self.len > 0);
|
||||
|
||||
try self.free_list.push(id.index);
|
||||
const index = id.index;
|
||||
|
||||
const uindex = @as(usize, id.index);
|
||||
|
||||
const key = self.keys.items[uindex] orelse unreachable;
|
||||
const key = self.keys.items[index] orelse unreachable;
|
||||
const removed = self.lookup.remove(key);
|
||||
assert(removed);
|
||||
|
||||
self.keys.items[uindex] = null;
|
||||
self.keys.items[index] = null;
|
||||
|
||||
self.gens.items[uindex] = self.gens.items[uindex] +% 1;
|
||||
const val = self.values.items[uindex] orelse unreachable;
|
||||
self.values.items[uindex] = null;
|
||||
self.gens.items[index] = self.gens.items[index] +% 1;
|
||||
const val = self.values.items[index] orelse unreachable;
|
||||
self.values.items[index] = null;
|
||||
self.len -= 1;
|
||||
return val;
|
||||
}
|
||||
|
||||
pub fn get(self: *Self, id: Id) ?*V {
|
||||
return if (self.exists(id)) &(self.values.items[@as(usize, id.index)] orelse unreachable) else null;
|
||||
return if (self.exists(id)) &(self.values.items[id.index] orelse unreachable) else null;
|
||||
}
|
||||
|
||||
pub fn find(self: *Self, key: K) ?Id {
|
||||
if (self.lookup.get(key)) |index| {
|
||||
const uindex = @as(usize, index);
|
||||
|
||||
const gen = self.gens.items[uindex];
|
||||
const gen = self.gens.items[index];
|
||||
return Id{
|
||||
.index = index,
|
||||
.gen = gen,
|
||||
|
@ -174,7 +169,7 @@ pub fn Table(comptime K: type, comptime V: type) type {
|
|||
}
|
||||
|
||||
pub fn getKey(self: *Self, id: Id) ?K {
|
||||
return if (self.exists(id)) (self.keys.items[@as(usize, id.index)] orelse unreachable) else null;
|
||||
return if (self.exists(id)) (self.keys.items[id.index] orelse unreachable) else null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -281,7 +276,7 @@ pub fn RefTable(comptime K: type, comptime V: type) type {
|
|||
}
|
||||
|
||||
pub fn remove(self: *Self, id: Id) !V {
|
||||
self.ref_counts.items[@as(usize, id.index)] = 0;
|
||||
self.ref_counts.items[id.index] = 0;
|
||||
return self.table.remove(id);
|
||||
}
|
||||
|
||||
|
@ -342,7 +337,7 @@ pub fn RefTable(comptime K: type, comptime V: type) type {
|
|||
assert(result.id.index == self.ref_counts.items.len);
|
||||
try self.ref_counts.append(1);
|
||||
} else {
|
||||
self.ref_counts.items[@as(usize, result.id.index)] = 1;
|
||||
self.ref_counts.items[result.id.index] = 1;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
Loading…
Reference in New Issue