authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-06-01 03:48:50 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-06-01 03:48:50 -07:00
log25f49eccc782ade9c0a32ba80c7e7c8f44353f2a
tree497bc102f2e6baa9760badf85402c7bfb33ad156
parent35065b703a0912fd39d56f91f7e4f8c886b9ab63
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

move data_soa into ucd


3 files changed, 16 insertions(+), 8 deletions(-)

scripts/UnicodeData.zig+7-4
......@@ -9,6 +9,9 @@ pub usingnamespace common.Main(struct {
99 pub const dest_header =
1010 \\const ucd = @import("./lib.zig");
1111 \\const std = @import("std");
12 \\const extras = @import("extras");
13 \\
14 \\pub const data_soa = extras.StaticMultiList(Codepoint).initComptime(&data);
1215 \\
1316 \\pub const Codepoint = struct {
1417 \\ u21, // U+ code
......@@ -49,7 +52,7 @@ pub usingnamespace common.Main(struct {
4952 \\};
5053 \\
5154 \\pub fn find(cp: u21) Codepoint {
52 \\ return data[binarySearchClosest(Codepoint, &data, cp, compare)];
55 \\ return data[binarySearchClosest(u21, data_soa[0], cp, compare)];
5356 \\}
5457 \\
5558 \\fn binarySearchClosest(comptime T: type, items: []const T, context: anytype, comptime compareFn: fn (@TypeOf(context), T) std.math.Order) usize {
......@@ -67,9 +70,9 @@ pub usingnamespace common.Main(struct {
6770 \\ return high;
6871 \\}
6972 \\
70 \\pub fn compare(needle: u21, row: Codepoint) std.math.Order {
71 \\ if (needle < row[0]) return .lt;
72 \\ if (needle > row[0]) return .gt;
73 \\pub fn compare(needle: u21, row: u21) std.math.Order {
74 \\ if (needle < row) return .lt;
75 \\ if (needle > row) return .gt;
7376 \\ return .eq;
7477 \\}
7578 \\
src/unicode_data.zig+7-4
......@@ -7,6 +7,9 @@
77
88const ucd = @import("./lib.zig");
99const std = @import("std");
10const extras = @import("extras");
11
12pub const data_soa = extras.StaticMultiList(Codepoint).initComptime(&data).items;
1013
1114pub const Codepoint = struct {
1215 u21, // U+ code
......@@ -47,7 +50,7 @@ pub const Decomposition = enum {
4750};
4851
4952pub fn find(cp: u21) Codepoint {
50 return data[binarySearchClosest(Codepoint, &data, cp, compare)];
53 return data[binarySearchClosest(u21, data_soa[0], cp, compare)];
5154}
5255
5356fn binarySearchClosest(comptime T: type, items: []const T, context: anytype, comptime compareFn: fn (@TypeOf(context), T) std.math.Order) usize {
......@@ -65,9 +68,9 @@ fn binarySearchClosest(comptime T: type, items: []const T, context: anytype, com
6568 return high;
6669}
6770
68pub fn compare(needle: u21, row: Codepoint) std.math.Order {
69 if (needle < row[0]) return .lt;
70 if (needle > row[0]) return .gt;
71pub fn compare(needle: u21, row: u21) std.math.Order {
72 if (needle < row) return .lt;
73 if (needle > row) return .gt;
7174 return .eq;
7275}
7376
zig.mod+2
......@@ -3,6 +3,8 @@ name: unicode-ucd
33main: src/lib.zig
44license: MIT
55description: Zig bindings for the Unicode Character Database
6dependencies:
7 - src: git https://github.com/nektro/zig-extras
68root_dependencies:
79 - src: git https://github.com/nektro/zfetch
810 - src: git https://github.com/nektro/zig-ansi