fn Fnv1a(comptime T: type, comptime prime: T, comptime offset: T) type value: T14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41fn Fnv1a(comptime T: type, comptime prime: T, comptime offset: T) type {
return struct {
const Self = @This();
value: T,
pub fn init() Self {
return Self{ .value = offset };
}
pub fn update(self: *Self, input: []const u8) void {
for (input) |b| {
self.value ^= b;
self.value *%= prime;
}
}
pub fn final(self: *Self) T {
return self.value;
}
pub fn hash(input: []const u8) T {
var c = Self.init();
c.update(input);
return c.final();
}
};
}