ona/source/coral/table.zig

63 lines
1.2 KiB
Zig

const io = @import("./io.zig");
pub fn Hashed(comptime key: Key, comptime Element: type) type {
const Entry = struct {
key: key.Element,
value: Element,
};
return struct {
allocator: io.MemoryAllocator,
entries: []?Entry,
const Self = @This();
pub fn clear(self: *Self) void {
for (self.entries) |*entry| entry.* = null;
}
pub fn deinit(self: *Self) void {
self.allocator.deallocate(self.entries.ptr);
}
pub fn init(allocator: io.MemoryAllocator) !Self {
const size = 4;
const entries = (allocator.allocate_many(?Entry, size) orelse return error.OutOfMemory)[0 .. size];
errdefer allocator.deallocate(entries);
return Self{
.entries = entries,
.allocator = allocator,
};
}
pub fn assign(self: *Self, key_element: key.Element, value_element: Element) !void {
_ = self;
_ = key_element;
_ = value_element;
}
pub fn insert(self: *Self, key_element: key.Element, value_element: Element) !void {
_ = self;
_ = key_element;
_ = value_element;
}
pub fn lookup(self: *Self, key_element: key.Element) ?Element {
_ = self;
_ = key_element;
return null;
}
};
}
pub const Key = struct {
Element: type,
};
pub const string_key = Key{
.Element = []const u8,
};