Skip to content

Commit

Permalink
Update to swiftzig v0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
devraymondsh committed Feb 13, 2024
1 parent 9e8a4a8 commit 70ea929
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub fn build(b: *std.Build) !void {
const tag = @tagName(target.os.tag);

// Declares dependencies
Dependency.addExternal(b, "swift_lib", 0);
Dependency.addExternal(b, "swiftzig", 0);
Dependency.addInternal(b, "Kivi", "src/core/Kivi.zig", 1, 0);
Dependency.addInternal(b, "core", "src/core/main.zig", 2, 0);

Expand Down
6 changes: 3 additions & 3 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
.minimum_zig_version = "0.11.0",
.paths = .{ "src", "build.zig", "build.zig.zon" },
.dependencies = .{
.swift_lib = .{
.url = "https://github.com/devraymondsh/swift_lib/archive/refs/tags/v0.3.0.tar.gz",
.hash = "12201501ad4ac2d6827b2a293219ec8a49d7d12239895f17ad00c6209b0418dad3fe",
.swiftzig = .{
.url = "https://github.com/devraymondsh/swiftzig/archive/refs/tags/v0.4.0.tar.gz",
.hash = "12208f395f60bbb782d91309c7b6d5d0da64a41db784e227f28dfd22ae996c05abaa",
},
},
}
8 changes: 4 additions & 4 deletions src/core/ByteMap.zig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/// This is Byte(u8) hashmap implementation that relies on the caller to handle allocations and lifetimes.
const builtin = @import("builtin");
const Wyhash = @import("./Wyhash.zig");
const swift_lib = @import("swift_lib");
const swiftzig = @import("swiftzig");

const Entry = struct {
key: []u8,
Expand Down Expand Up @@ -70,8 +70,8 @@ table_size: usize,

var hasher = Wyhash.init(0);

pub fn init(self: *ByteMap, allocator: swift_lib.heap.Allocator, size: usize) !void {
self.table_size = swift_lib.math.ceilPowerOfTwo(size);
pub fn init(self: *ByteMap, allocator: swiftzig.mem.Allocator, size: usize) !void {
self.table_size = swiftzig.math.ceilPowerOfTwo(size);
self.table_metadata = try allocator.alloc(GroupMetadata, self.table_size);
self.table = try allocator.alloc(Group, self.table_size);

Expand Down Expand Up @@ -183,7 +183,7 @@ pub fn get(self: *ByteMap, key: []const u8) ?[]u8 {
}
return null;
}
pub fn del(self: *ByteMap, allocator: swift_lib.heap.Allocator, key: []const u8) ?[]u8 {
pub fn del(self: *ByteMap, allocator: swiftzig.mem.Allocator, key: []const u8) ?[]u8 {
const found_entity = self.find_index(key, true);
if (found_entity) |entity| {
const entry = &self.table[entity.group_idx].elements[entity.elem_idx];
Expand Down
12 changes: 6 additions & 6 deletions src/core/Kivi.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const ByteMap = @import("ByteMap.zig");
const swift_lib = @import("swift_lib");
const swiftzig = @import("swiftzig");

pub const Config = extern struct {
// (2 ** 18) * 16 = 4194304
Expand All @@ -8,8 +8,8 @@ pub const Config = extern struct {
};

map: ByteMap,
allocator: swift_lib.heap.Allocator,
freelist: swift_lib.heap.FreelistAllocator,
allocator: swiftzig.mem.Allocator,
freelist: swiftzig.mem.FreelistAllocator,

const Kivi = @This();

Expand All @@ -21,9 +21,9 @@ fn stringcpy(dest: []u8, src: []const u8) !void {
}

pub fn init(self: *Kivi, config: *const Config) !usize {
const pages = try swift_lib.heap.PageAllocator.init(config.mem_size / swift_lib.os.page_size);
const pages = try swiftzig.mem.PageAllocator.init(config.mem_size / swiftzig.os.page_size);

self.freelist = swift_lib.heap.FreelistAllocator.init(pages.mem);
self.freelist = swiftzig.mem.FreelistAllocator.init(pages.mem);
self.allocator = self.freelist.allocator();

try self.map.init(self.allocator, config.group_size);
Expand Down Expand Up @@ -94,7 +94,7 @@ pub fn rm(self: *Kivi, key: []const u8) !void {
}

pub fn deinit(self: *Kivi) void {
var pages: swift_lib.heap.PageAllocator = .{ .mem = @alignCast(self.freelist.mem) };
var pages: swiftzig.mem.PageAllocator = .{ .mem = @alignCast(self.freelist.mem) };

self.map.deinit();
pages.deinit();
Expand Down

0 comments on commit 70ea929

Please sign in to comment.