diff --git a/src/small_buf_map.zig b/src/small_buf_map.zig index 032885c..eca2e19 100644 --- a/src/small_buf_map.zig +++ b/src/small_buf_map.zig @@ -21,19 +21,19 @@ pub fn SmallBufMap(comptime buffer_size: u8) type { const Self = @This(); /// Assumes the existence of a key at i - inline fn getKey(self: Self, i: u8) []const u8 { + inline fn getKey(self: *const Self, i: u8) []const u8 { const start = if (i == 0) 0 else self.buffer[buffer_size - (2 * i)]; const end = self.buffer[buffer_size - (2 * i) - 1]; return self.buffer[start..end]; } /// Assumes the existence of a value at i - inline fn getValue(self: Self, i: u8) []const u8 { + inline fn getValue(self: *const Self, i: u8) []const u8 { const start = self.buffer[buffer_size - (2 * i) - 1]; const end = self.buffer[buffer_size - (2 * i) - 2]; return self.buffer[start..end]; } /// Assumes the existence of key+value at i - pub fn getKeyValue(self: Self, i: u8) [2][]const u8 { + pub fn getKeyValue(self: *const Self, i: u8) [2][]const u8 { return [2][]const u8{ self.getKey(i), self.getValue(i) }; } @@ -50,12 +50,12 @@ pub fn SmallBufMap(comptime buffer_size: u8) type { @memcpy(self.buffer[key_end..value_end], value); } - fn hasEntry(self: Self, i: u8) bool { + fn hasEntry(self: *const Self, i: u8) bool { const offset = self.buffer[buffer_size - (2 * i) - 1]; return offset != 0; } - pub fn count(self: Self) u8 { + pub fn count(self: *const Self) u8 { var i: u8 = 0; while (i < 256) : (i += 1) { if (!self.hasEntry(i)) { @@ -65,12 +65,12 @@ pub fn SmallBufMap(comptime buffer_size: u8) type { return 255; } - pub fn dataCount(self: Self) u8 { + pub fn dataCount(self: *const Self) u8 { const c = self.count(); return if (c == 0) 0 else self.buffer[buffer_size - (2 * c)]; } - inline fn getKeyIndex(self: Self, key: []const u8) ?u8 { + inline fn getKeyIndex(self: *const Self, key: []const u8) ?u8 { var i: u8 = 0; while (i < 256) : (i += 1) { if (!self.hasEntry(i)) { @@ -84,14 +84,14 @@ pub fn SmallBufMap(comptime buffer_size: u8) type { return null; } - pub fn get(self: Self, key: []const u8) ?[]const u8 { + pub fn get(self: *const Self, key: []const u8) ?[]const u8 { const i = self.getKeyIndex(key) orelse return null; return self.getValue(i); } const PutOpType = enum { replace, insert, append }; const PutOp = struct { op: PutOpType, i: u8 }; - fn getPutOp(self: Self, key: []const u8) PutOp { + fn getPutOp(self: *const Self, key: []const u8) PutOp { var i: u8 = 0; while (i < 256) : (i += 1) { if (!self.hasEntry(i)) {