cache_table and ref_counted_set work on 32-bit machines

This commit is contained in:
Mitchell Hashimoto
2024-06-22 20:45:30 -07:00
parent 71353d016e
commit 9271fd50b6
2 changed files with 4 additions and 5 deletions

View File

@ -55,6 +55,7 @@ pub fn CacheTable(
comptime {
assert(std.math.isPowerOfTwo(bucket_count));
assert(bucket_count <= std.math.maxInt(usize));
}
/// `bucket_count` buckets containing `bucket_size` KV pairs each.
@ -79,7 +80,7 @@ pub fn CacheTable(
/// make room then it is returned in a struct with its key and value.
pub fn put(self: *Self, key: K, value: V) ?KV {
const kv: KV = .{ .key = key, .value = value };
const idx: u64 = self.context.hash(key) % bucket_count;
const idx: usize = @intCast(self.context.hash(key) % bucket_count);
// If we have space available in the bucket then we just append
if (self.lengths[idx] < bucket_size) {
@ -105,8 +106,7 @@ pub fn CacheTable(
///
/// Returns null if no item is found with the provided key.
pub fn get(self: *Self, key: K) ?V {
const idx = self.context.hash(key) % bucket_count;
const idx: usize = @intCast(self.context.hash(key) % bucket_count);
const len = self.lengths[idx];
var i: usize = len;
while (i > 0) {

View File

@ -431,8 +431,7 @@ pub fn RefCountedSet(
const hash: u64 = self.context.hash(value);
for (0..self.max_psl + 1) |i| {
const p = (hash + i) & self.layout.table_mask;
const p: usize = @intCast((hash + i) & self.layout.table_mask);
const id = table[p];
// Empty bucket, our item cannot have probed to