Skip to content

Commit

Permalink
Simplift
Browse files Browse the repository at this point in the history
  • Loading branch information
lalinsky committed Nov 16, 2024
1 parent 1e7aca7 commit bba8676
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
8 changes: 3 additions & 5 deletions src/FileSegment.zig
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,14 @@ pub fn getBlockData(self: *const Self, block: usize) []const u8 {
return self.blocks[block * self.block_size .. (block + 1) * self.block_size];
}

pub fn search(self: *Self, hashes: []const u32, results: *SearchResults) !void {
assert(std.sort.isSorted(u32, hashes, {}, std.sort.asc(u32)));

pub fn search(self: *Self, sorted_hashes: []const u32, results: *SearchResults) !void {
var prev_block_no: usize = std.math.maxInt(usize);
var prev_block_range_start: usize = 0;

var block_items = std.ArrayList(Item).init(self.allocator);
var block_items = std.ArrayList(Item).init(results.results.allocator);
defer block_items.deinit();

for (hashes) |hash| {
for (sorted_hashes) |hash| {
var block_no = std.sort.lowerBound(u32, hash, self.index.items, {}, std.sort.asc(u32));
if (block_no == self.index.items.len) {
block_no = prev_block_range_start;
Expand Down
16 changes: 2 additions & 14 deletions src/InMemorySegment.zig
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const std = @import("std");
const log = std.log;
const io = std.io;
const assert = std.debug.assert;

const common = @import("common.zig");
const Item = common.Item;
Expand All @@ -12,8 +10,6 @@ const Change = @import("change.zig").Change;

const Deadline = @import("utils/Deadline.zig");

const filefmt = @import("filefmt.zig");

const segment_list = @import("segment_list.zig");
pub const List = segment_list.SegmentList(Self);

Expand Down Expand Up @@ -41,17 +37,9 @@ pub fn deinit(self: *Self) void {
self.items.deinit();
}

pub fn write(self: *Self, writer: anytype) !void {
if (self.id == 0) {
return error.InvalidSegmentVersion;
}
try filefmt.writeFile(writer, self);
}

pub fn search(self: *Self, hashes: []const u32, results: *SearchResults) !void {
assert(std.sort.isSorted(u32, hashes, {}, std.sort.asc(u32)));
pub fn search(self: *Self, sorted_hashes: []const u32, results: *SearchResults) !void {
var items = self.items.items;
for (hashes) |hash| {
for (sorted_hashes) |hash| {
const matches = std.sort.equalRange(Item, Item{ .hash = hash, .id = 0 }, items, {}, Item.cmpByHash);
for (matches[0]..matches[1]) |i| {
try results.incr(items[i].id, self.id.version);
Expand Down

0 comments on commit bba8676

Please sign in to comment.