Index
A single entry in the lookup acceleration structure. These structs are found in an array after the IndexHeader. Hashes index into this array, and linear probing is used for collisions.
Fields of this type
Fields
- entry_index:I
- The index of this entry in the backing store.
- distance_from_start_index:I
- The distance between this slot and its ideal placement.
Source
Implementation
fn Index(comptime I: type) type {
return extern struct {
const Self = @This();
/// The index of this entry in the backing store. If the index is
/// empty, this is empty_sentinel.
entry_index: I,
/// The distance between this slot and its ideal placement. This is
/// used to keep maximum scan length small. This value is undefined
/// if the index is empty.
distance_from_start_index: I,
/// The special entry_index value marking an empty slot.
const empty_sentinel = ~@as(I, 0);
/// A constant empty index
const empty = Self{
.entry_index = empty_sentinel,
.distance_from_start_index = undefined,
};
/// Checks if a slot is empty
fn isEmpty(idx: Self) bool {
return idx.entry_index == empty_sentinel;
}
/// Sets a slot to empty
fn setEmpty(idx: *Self) void {
idx.entry_index = empty_sentinel;
idx.distance_from_start_index = undefined;
}
};
}