summaryrefslogtreecommitdiff
path: root/src/CanonData.zig
diff options
context:
space:
mode:
authorGravatar Jose Colon Rodriguez2024-02-28 19:23:23 -0400
committerGravatar Jose Colon Rodriguez2024-02-28 19:23:23 -0400
commit7cad24f76a72f534084de64153f768699170cd05 (patch)
tree0a9eb3b4609a246046952c379ea5e92540623ab7 /src/CanonData.zig
parentGeneral Category with GenCatData (diff)
downloadzg-7cad24f76a72f534084de64153f768699170cd05.tar.gz
zg-7cad24f76a72f534084de64153f768699170cd05.tar.xz
zg-7cad24f76a72f534084de64153f768699170cd05.zip
Using slices for decompositions in Normalizer
Diffstat (limited to 'src/CanonData.zig')
-rw-r--r--src/CanonData.zig17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/CanonData.zig b/src/CanonData.zig
index 81d3eec..36895ff 100644
--- a/src/CanonData.zig
+++ b/src/CanonData.zig
@@ -5,7 +5,7 @@ const mem = std.mem;
5 5
6allocator: mem.Allocator, 6allocator: mem.Allocator,
7nfc: std.AutoHashMap([2]u21, u21), 7nfc: std.AutoHashMap([2]u21, u21),
8nfd: [][2]u21 = undefined, 8nfd: [][]u21 = undefined,
9 9
10const Self = @This(); 10const Self = @This();
11 11
@@ -21,19 +21,21 @@ pub fn init(allocator: mem.Allocator) !Self {
21 var self = Self{ 21 var self = Self{
22 .allocator = allocator, 22 .allocator = allocator,
23 .nfc = std.AutoHashMap([2]u21, u21).init(allocator), 23 .nfc = std.AutoHashMap([2]u21, u21).init(allocator),
24 .nfd = try allocator.alloc([2]u21, 0x110000), 24 .nfd = try allocator.alloc([]u21, 0x110000),
25 }; 25 };
26 26
27 for (0..0x110000) |i| self.nfd[i] = .{ @intCast(i), 0 }; 27 @memset(self.nfd, &.{});
28 28
29 while (true) { 29 while (true) {
30 const len: u8 = try reader.readInt(u8, endian); 30 const len: u8 = try reader.readInt(u8, endian);
31 if (len == 0) break; 31 if (len == 0) break;
32 const cp = try reader.readInt(u24, endian); 32 const cp = try reader.readInt(u24, endian);
33 self.nfd[cp][0] = @intCast(try reader.readInt(u24, endian)); 33 self.nfd[cp] = try allocator.alloc(u21, len - 1);
34 for (0..len - 1) |i| {
35 self.nfd[cp][i] = @intCast(try reader.readInt(u24, endian));
36 }
34 if (len == 3) { 37 if (len == 3) {
35 self.nfd[cp][1] = @intCast(try reader.readInt(u24, endian)); 38 try self.nfc.put(self.nfd[cp][0..2].*, @intCast(cp));
36 try self.nfc.put(self.nfd[cp], @intCast(cp));
37 } 39 }
38 } 40 }
39 41
@@ -42,11 +44,12 @@ pub fn init(allocator: mem.Allocator) !Self {
42 44
43pub fn deinit(self: *Self) void { 45pub fn deinit(self: *Self) void {
44 self.nfc.deinit(); 46 self.nfc.deinit();
47 for (self.nfd) |slice| self.allocator.free(slice);
45 self.allocator.free(self.nfd); 48 self.allocator.free(self.nfd);
46} 49}
47 50
48/// Returns canonical decomposition for `cp`. 51/// Returns canonical decomposition for `cp`.
49pub inline fn toNfd(self: Self, cp: u21) [2]u21 { 52pub inline fn toNfd(self: Self, cp: u21) []const u21 {
50 return self.nfd[cp]; 53 return self.nfd[cp];
51} 54}
52 55