summaryrefslogtreecommitdiff
path: root/src/font/CodepointMap.zig
diff options
context:
space:
mode:
authorMitchell Hashimoto <mitchell.hashimoto@gmail.com>2024-04-01 12:38:07 -0700
committerMitchell Hashimoto <mitchell.hashimoto@gmail.com>2024-04-05 09:29:40 -0700
commit9d8da8fcc72f3894dc0fd5949d795e1246e941ef (patch)
treebbd8787a77047048bcd9f70c624942bb61fa5816 /src/font/CodepointMap.zig
parentbfcd5f380a91a87f2c2cd982747d6fb5946f78db (diff)
font: CodepointMap hashable, use for groupcacheset
Diffstat (limited to 'src/font/CodepointMap.zig')
-rw-r--r--src/font/CodepointMap.zig20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/font/CodepointMap.zig b/src/font/CodepointMap.zig
index 58a8a7c43..c5b5b1ffb 100644
--- a/src/font/CodepointMap.zig
+++ b/src/font/CodepointMap.zig
@@ -53,6 +53,26 @@ pub fn get(self: *const CodepointMap, cp: u21) ?discovery.Descriptor {
return null;
}
+/// Hash with the given hasher.
+pub fn hash(self: *const CodepointMap, hasher: anytype) void {
+ const autoHash = std.hash.autoHash;
+ autoHash(hasher, self.list.len);
+ const slice = self.list.slice();
+ for (0..slice.len) |i| {
+ const entry = slice.get(i);
+ autoHash(hasher, entry.range);
+ entry.descriptor.hash(hasher);
+ }
+}
+
+/// Returns a hash code that can be used to uniquely identify this
+/// action.
+pub fn hashcode(self: *const CodepointMap) u64 {
+ var hasher = std.hash.Wyhash.init(0);
+ self.hash(&hasher);
+ return hasher.final();
+}
+
test "codepointmap" {
const testing = std.testing;
const alloc = testing.allocator;