| author | |
| committer | |
| log | 25f49eccc782ade9c0a32ba80c7e7c8f44353f2a |
| tree | 497bc102f2e6baa9760badf85402c7bfb33ad156 |
| parent | 35065b703a0912fd39d56f91f7e4f8c886b9ab63 |
| signature |
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+ code | 17 | \\ 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 @@ |
| 7 | 7 | ||
| 8 | const ucd = @import("./lib.zig"); | 8 | const ucd = @import("./lib.zig"); |
| 9 | const std = @import("std"); | 9 | const std = @import("std"); |
| 10 | const extras = @import("extras"); | ||
| 11 | |||
| 12 | pub const data_soa = extras.StaticMultiList(Codepoint).initComptime(&data).items; | ||
| 10 | 13 | ||
| 11 | pub const Codepoint = struct { | 14 | pub const Codepoint = struct { |
| 12 | u21, // U+ code | 15 | u21, // U+ code |
| ... | @@ -47,7 +50,7 @@ pub const Decomposition = enum { | ... | @@ -47,7 +50,7 @@ pub const Decomposition = enum { |
| 47 | }; | 50 | }; |
| 48 | 51 | ||
| 49 | pub fn find(cp: u21) Codepoint { | 52 | pub 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 | } |
| 52 | 55 | ||
| 53 | fn binarySearchClosest(comptime T: type, items: []const T, context: anytype, comptime compareFn: fn (@TypeOf(context), T) std.math.Order) usize { | 56 | fn 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 | } |
| 67 | 70 | ||
| 68 | pub fn compare(needle: u21, row: Codepoint) std.math.Order { | 71 | pub 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 | } |
| 73 | 76 |
zig.mod+2| ... | @@ -3,6 +3,8 @@ name: unicode-ucd | ... | @@ -3,6 +3,8 @@ name: unicode-ucd |
| 3 | main: src/lib.zig | 3 | main: src/lib.zig |
| 4 | license: MIT | 4 | license: MIT |
| 5 | description: Zig bindings for the Unicode Character Database | 5 | description: Zig bindings for the Unicode Character Database |
| 6 | dependencies: | ||
| 7 | - src: git https://github.com/nektro/zig-extras | ||
| 6 | root_dependencies: | 8 | root_dependencies: |
| 7 | - src: git https://github.com/nektro/zfetch | 9 | - src: git https://github.com/nektro/zfetch |
| 8 | - src: git https://github.com/nektro/zig-ansi | 10 | - src: git https://github.com/nektro/zig-ansi |