Skip to content

Commit bababd1

Browse files
committed
Add a data section pointer to Result to facilitate caching
1 parent 0a270d1 commit bababd1

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/reader.zig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ pub const Reader = struct {
212212
.network = entry.network,
213213
.value = v,
214214
.arena = null,
215+
.pointer = entry.pointer,
215216
};
216217
}
217218

@@ -239,6 +240,7 @@ pub const Reader = struct {
239240
.network = entry.network,
240241
.value = value,
241242
.arena = null,
243+
.pointer = entry.pointer,
242244
};
243245
}
244246

@@ -296,6 +298,7 @@ pub const Reader = struct {
296298
.network = entry.network,
297299
.value = value,
298300
.arena = arena,
301+
.pointer = entry.pointer,
299302
};
300303
}
301304

@@ -694,6 +697,10 @@ pub fn Cache(comptime T: type) type {
694697
/// When a cache is used, the cache owns the memory and arena is null.
695698
pub fn Result(comptime T: type) type {
696699
return struct {
700+
/// Raw pointer into the data section as stored in the search tree.
701+
/// Two results with the same pointer reference the same data record.
702+
/// This is the same value as Entry.pointer and Cache.Entry.pointer.
703+
pointer: usize,
697704
network: net.Network,
698705
value: T,
699706
arena: ?std.heap.ArenaAllocator,
@@ -756,6 +763,7 @@ pub fn Iterator(T: type) type {
756763
.network = ip_net,
757764
.value = v,
758765
.arena = null,
766+
.pointer = current.node,
759767
};
760768
}
761769
}
@@ -786,13 +794,15 @@ pub fn Iterator(T: type) type {
786794
.network = ip_net,
787795
.value = value,
788796
.arena = null,
797+
.pointer = current.node,
789798
};
790799
}
791800

792801
return .{
793802
.network = ip_net,
794803
.value = value,
795804
.arena = entry_arena,
805+
.pointer = current.node,
796806
};
797807
} else if (current.node < self.node_count) {
798808
// In order traversal of the children on the right (1-bit).

0 commit comments

Comments
 (0)