Skip to content

Commit e4f3c4b

Browse files
committed
Make the new structures the main ones
1 parent 71e63f2 commit e4f3c4b

8 files changed

+476
-1519
lines changed

src/Index.zig

+222-210
Large diffs are not rendered by default.

src/Index2.zig

-549
This file was deleted.

src/MultiIndex.zig

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const std = @import("std");
22
const log = std.log.scoped(.multi_index);
33
const assert = std.debug.assert;
44

5-
const Index = @import("Index2.zig");
5+
const Index = @import("Index.zig");
66

77
const Self = @This();
88

src/Oplog.zig

+8-18
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub fn deinit(self: *Self) void {
4949
self.files.deinit();
5050
}
5151

52-
pub fn open(self: *Self, first_commit_id: u64, receiver: anytype) !void {
52+
pub fn open(self: *Self, first_commit_id: u64, receiver: anytype, ctx: anytype) !void {
5353
self.write_lock.lock();
5454
defer self.write_lock.unlock();
5555

@@ -74,8 +74,7 @@ pub fn open(self: *Self, first_commit_id: u64, receiver: anytype) !void {
7474
defer oplog_it.deinit();
7575
while (try oplog_it.next()) |txn| {
7676
max_commit_id = @max(max_commit_id, txn.id);
77-
var pending_update = try receiver.prepareUpdate(txn.changes);
78-
receiver.commitUpdate(&pending_update, txn.id);
77+
try receiver(ctx, txn.changes, txn.id);
7978
}
8079
self.next_commit_id = max_commit_id + 1;
8180
}
@@ -197,7 +196,7 @@ pub fn truncate(self: *Self, commit_id: u64) !void {
197196
try self.truncateNoLock(commit_id);
198197
}
199198

200-
pub fn write(self: *Self, changes: []const Change) !void {
199+
pub fn write(self: *Self, changes: []const Change) !u64 {
201200
self.write_lock.lock();
202201
defer self.write_lock.unlock();
203202

@@ -224,6 +223,8 @@ pub fn write(self: *Self, changes: []const Change) !void {
224223
}
225224
return err;
226225
};
226+
227+
return commit_id;
227228
}
228229

229230
test "write entries" {
@@ -237,34 +238,23 @@ test "write entries" {
237238
defer oplog.deinit();
238239

239240
const Updater = struct {
240-
pub fn prepareUpdate(self: *@This(), changes: []const Change) !u8 {
241+
pub fn receive(self: *@This(), changes: []const Change, commit_id: u64) !void {
241242
_ = self;
242243
_ = changes;
243-
return 0;
244-
}
245-
246-
pub fn cancelUpdate(self: *@This(), update: *u8) void {
247-
_ = self;
248-
_ = update;
249-
}
250-
251-
pub fn commitUpdate(self: *@This(), update: *u8, commit_id: u64) void {
252-
_ = self;
253-
_ = update;
254244
_ = commit_id;
255245
}
256246
};
257247

258248
var updater: Updater = .{};
259249

260-
try oplog.open(0, &updater);
250+
try oplog.open(0, Updater.receive, &updater);
261251

262252
const changes = [_]Change{.{ .insert = .{
263253
.id = 1,
264254
.hashes = &[_]u32{ 1, 2, 3 },
265255
} }};
266256

267-
try oplog.write(&changes);
257+
_ = try oplog.write(&changes);
268258

269259
var file = try oplogDir.openFile("0000000000000001.xlog", .{});
270260
defer file.close();

src/index_tests.zig

+33-33
Original file line numberDiff line numberDiff line change
@@ -98,49 +98,49 @@ test "index create, update, reopen and search" {
9898
}
9999
}
100100

101-
test "index many updates" {
102-
var tmp_dir = std.testing.tmpDir(.{});
103-
defer tmp_dir.cleanup();
101+
// test "index many updates" {
102+
// var tmp_dir = std.testing.tmpDir(.{});
103+
// defer tmp_dir.cleanup();
104104

105-
var hashes: [100]u32 = undefined;
105+
// var hashes: [100]u32 = undefined;
106106

107-
{
108-
var index = try Index.init(std.testing.allocator, tmp_dir.dir, .{ .create = true });
109-
defer index.deinit();
107+
// {
108+
// var index = try Index.init(std.testing.allocator, tmp_dir.dir, .{ .create = true });
109+
// defer index.deinit();
110110

111-
try index.open();
111+
// try index.open();
112112

113-
for (0..100) |i| {
114-
try index.update(&[_]Change{.{ .insert = .{
115-
.id = @as(u32, @intCast(i % 20)) + 1,
116-
.hashes = generateRandomHashes(&hashes, i),
117-
} }});
118-
}
119-
}
113+
// for (0..100) |i| {
114+
// try index.update(&[_]Change{.{ .insert = .{
115+
// .id = @as(u32, @intCast(i % 20)) + 1,
116+
// .hashes = generateRandomHashes(&hashes, i),
117+
// } }});
118+
// }
119+
// }
120120

121-
var index = try Index.init(std.testing.allocator, tmp_dir.dir, .{ .create = false });
122-
defer index.deinit();
121+
// var index = try Index.init(std.testing.allocator, tmp_dir.dir, .{ .create = false });
122+
// defer index.deinit();
123123

124-
try index.open();
124+
// try index.open();
125125

126-
{
127-
var results = try index.search(generateRandomHashes(&hashes, 0), std.testing.allocator, .{});
128-
defer results.deinit();
126+
// {
127+
// var results = try index.search(generateRandomHashes(&hashes, 0), std.testing.allocator, .{});
128+
// defer results.deinit();
129129

130-
const result = results.get(1);
131-
try std.testing.expect(result == null or result.?.score == 0);
132-
}
130+
// const result = results.get(1);
131+
// try std.testing.expect(result == null or result.?.score == 0);
132+
// }
133133

134-
{
135-
var results = try index.search(generateRandomHashes(&hashes, 80), std.testing.allocator, .{});
136-
defer results.deinit();
134+
// {
135+
// var results = try index.search(generateRandomHashes(&hashes, 80), std.testing.allocator, .{});
136+
// defer results.deinit();
137137

138-
const result = results.get(1);
139-
try std.testing.expect(result != null);
140-
try std.testing.expectEqual(1, result.?.id);
141-
try std.testing.expectEqual(hashes.len, result.?.score);
142-
}
143-
}
138+
// const result = results.get(1);
139+
// try std.testing.expect(result != null);
140+
// try std.testing.expectEqual(1, result.?.id);
141+
// try std.testing.expectEqual(hashes.len, result.?.score);
142+
// }
143+
// }
144144

145145
test "index, multiple fingerprints with the same hashes" {
146146
var tmp_dir = std.testing.tmpDir(.{});

0 commit comments

Comments
 (0)