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 {...@@ -9,6 +9,9 @@ pub usingnamespace common.Main(struct {
9 pub const dest_header =9 pub const dest_header =
10 \\const ucd = @import("./lib.zig");10 \\const ucd = @import("./lib.zig");
11 \\const std = @import("std");11 \\const std = @import("std");
12 \\const extras = @import("extras");
13 \\
14 \\pub const data_soa = extras.StaticMultiList(Codepoint).initComptime(&data);
12 \\15 \\
13 \\pub const Codepoint = struct {16 \\pub const Codepoint = struct {
14 \\ u21, // U+ code17 \\ u21, // U+ code
...@@ -49,7 +52,7 @@ pub usingnamespace common.Main(struct {...@@ -49,7 +52,7 @@ pub usingnamespace common.Main(struct {
49 \\};52 \\};
50 \\53 \\
51 \\pub fn find(cp: u21) Codepoint {54 \\pub fn find(cp: u21) Codepoint {
52 \\ return data[binarySearchClosest(Codepoint, &data, cp, compare)];55 \\ return data[binarySearchClosest(u21, data_soa[0], cp, compare)];
53 \\}56 \\}
54 \\57 \\
55 \\fn binarySearchClosest(comptime T: type, items: []const T, context: anytype, comptime compareFn: fn (@TypeOf(context), T) std.math.Order) usize {58 \\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 {...@@ -67,9 +70,9 @@ pub usingnamespace common.Main(struct {
67 \\ return high;70 \\ return high;
68 \\}71 \\}
69 \\72 \\
70 \\pub fn compare(needle: u21, row: Codepoint) std.math.Order {73 \\pub fn compare(needle: u21, row: u21) std.math.Order {
71 \\ if (needle < row[0]) return .lt;74 \\ if (needle < row) return .lt;
72 \\ if (needle > row[0]) return .gt;75 \\ if (needle > row) return .gt;
73 \\ return .eq;76 \\ return .eq;
74 \\}77 \\}
75 \\78 \\
src/unicode_data.zig+7-4
...@@ -7,6 +7,9 @@...@@ -7,6 +7,9 @@
77
8const ucd = @import("./lib.zig");8const ucd = @import("./lib.zig");
9const std = @import("std");9const std = @import("std");
10const extras = @import("extras");
11
12pub const data_soa = extras.StaticMultiList(Codepoint).initComptime(&data).items;
1013
11pub const Codepoint = struct {14pub const Codepoint = struct {
12 u21, // U+ code15 u21, // U+ code
...@@ -47,7 +50,7 @@ pub const Decomposition = enum {...@@ -47,7 +50,7 @@ pub const Decomposition = enum {
47};50};
4851
49pub fn find(cp: u21) Codepoint {52pub fn find(cp: u21) Codepoint {
50 return data[binarySearchClosest(Codepoint, &data, cp, compare)];53 return data[binarySearchClosest(u21, data_soa[0], cp, compare)];
51}54}
5255
53fn binarySearchClosest(comptime T: type, items: []const T, context: anytype, comptime compareFn: fn (@TypeOf(context), T) std.math.Order) usize {56fn 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...@@ -65,9 +68,9 @@ fn binarySearchClosest(comptime T: type, items: []const T, context: anytype, com
65 return high;68 return high;
66}69}
6770
68pub fn compare(needle: u21, row: Codepoint) std.math.Order {71pub fn compare(needle: u21, row: u21) std.math.Order {
69 if (needle < row[0]) return .lt;72 if (needle < row) return .lt;
70 if (needle > row[0]) return .gt;73 if (needle > row) return .gt;
71 return .eq;74 return .eq;
72}75}
7376
zig.mod+2
...@@ -3,6 +3,8 @@ name: unicode-ucd...@@ -3,6 +3,8 @@ name: unicode-ucd
3main: src/lib.zig3main: src/lib.zig
4license: MIT4license: MIT
5description: Zig bindings for the Unicode Character Database5description: Zig bindings for the Unicode Character Database
6dependencies:
7 - src: git https://github.com/nektro/zig-extras
6root_dependencies:8root_dependencies:
7 - src: git https://github.com/nektro/zfetch9 - src: git https://github.com/nektro/zfetch
8 - src: git https://github.com/nektro/zig-ansi10 - src: git https://github.com/nektro/zig-ansi