Add library support for UTF-8 to Ona module
This commit is contained in:
parent
1997c38e97
commit
1d2356e942
|
@ -0,0 +1,29 @@
|
||||||
|
const std = @import("std");
|
||||||
|
const table = @import("./table.zig");
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Tests if the contents of `this_utf8_sequence` lexically equals the contents of
|
||||||
|
/// `that_utf8_sequence`.
|
||||||
|
///
|
||||||
|
pub fn equals(this_utf8_sequence: []const u8, that_utf8_sequence: []const u8) bool {
|
||||||
|
return std.mem.eql(u8, this_utf8_sequence, that_utf8_sequence);
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Returns a deterministic hash for `utf8_sequence`.
|
||||||
|
///
|
||||||
|
pub fn hash(utf8_sequence: []const u8) usize {
|
||||||
|
var utf8_hash = @as(usize, 5381);
|
||||||
|
|
||||||
|
for (utf8_sequence) |utf8_code| utf8_hash = ((utf8_hash << 5) + utf8_hash) + utf8_code;
|
||||||
|
|
||||||
|
return utf8_hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// A [table.KeyContext] for handling UTF-8 character sequences.
|
||||||
|
///
|
||||||
|
pub const key_context = table.KeyContext([]const u8){
|
||||||
|
.hash = hash,
|
||||||
|
.equals = equals,
|
||||||
|
};
|
Loading…
Reference in New Issue