diff --git a/src/fileEngine.zig b/src/fileEngine.zig index f717fdb..1760810 100644 --- a/src/fileEngine.zig +++ b/src/fileEngine.zig @@ -279,7 +279,7 @@ pub const FileEngine = struct { } /// Use a struct name and filter to populate a map with all UUID bytes as key and void as value - /// This map is use as value for the link array, so I can do a `contains` on it. + /// This map is use as value for the ConditionValue of links, so I can do a `contains` on it. pub fn populateVoidUUIDMap( self: *FileEngine, struct_name: []const u8, @@ -330,6 +330,16 @@ pub const FileEngine = struct { for (thread_writer_list) |list| { for (list.items) |uuid| _ = map.getOrPut(uuid) catch return ZipponError.MemoryError; } + + if (additional_data.entity_count_to_find == 0) return; + + if (map.count() > additional_data.entity_count_to_find) { + log.err("Found {d} entity in populateVoidUUIDMap but max is: {d}", .{ map.count(), additional_data.entity_count_to_find }); + var iter = map.iterator(); + while (iter.next()) |entry| { + log.debug("{s}", .{UUID.format_bytes(entry.key_ptr.bytes)}); + } + } } fn populateVoidUUIDMapOneFile( @@ -358,6 +368,7 @@ pub const FileEngine = struct { defer iter.deinit(); while (iter.next() catch return) |row| { + if (sync_context.checkStructLimit()) break; if (filter == null or filter.?.evaluate(row)) { list.*.append(UUID{ .bytes = row[0].UUID }) catch |err| { sync_context.logError("Error initializing DataIterator", err); @@ -474,6 +485,7 @@ pub const FileEngine = struct { sync_context.logError("Error in iter next", err); return; }) |row| { + if (sync_context.checkStructLimit()) break; if (filter) |f| if (!f.evaluate(row)) continue; writeEntity( @@ -719,6 +731,7 @@ pub const FileEngine = struct { sync_context.logError("Parsing files", err); return; }) |row| { + if (sync_context.checkStructLimit()) break; if (filter == null or filter.?.evaluate(row)) { // Add the unchanged Data in the new_data_buff new_data_buff[0] = row[0]; @@ -872,6 +885,7 @@ pub const FileEngine = struct { sync_context.logError("Error during iter", err); return; }) |row| { + if (sync_context.checkStructLimit()) break; if (filter == null or filter.?.evaluate(row)) { writer.print("{{\"{s}\"}},", .{UUID.format_bytes(row[0].UUID)}) catch |err| { sync_context.logError("Error writting", err); diff --git a/src/schemaEngine.zig b/src/schemaEngine.zig index dc7a70b..033cf23 100644 --- a/src/schemaEngine.zig +++ b/src/schemaEngine.zig @@ -125,7 +125,6 @@ pub const SchemaEngine = struct { /// Chech if the name of a struct is in the current schema pub fn isStructNameExists(self: *SchemaEngine, struct_name: []const u8) bool { var i: u16 = 0; - log.debug("\n\n{any}\n\n", .{self.struct_array}); while (i < self.struct_array.len) : (i += 1) if (std.mem.eql(u8, self.struct_array[i].name, struct_name)) return true; return false; } diff --git a/src/threadEngine.zig b/src/threadEngine.zig index 0c9efdb..0a90a51 100644 --- a/src/threadEngine.zig +++ b/src/threadEngine.zig @@ -34,7 +34,13 @@ pub const ThreadSyncContext = struct { pub fn incrementAndCheckStructLimit(self: *ThreadSyncContext) bool { if (self.max_struct == 0) return false; const new_count = self.processed_struct.fetchAdd(1, .monotonic); - return new_count >= self.max_struct; + return (new_count + 1) >= self.max_struct; + } + + pub fn checkStructLimit(self: *ThreadSyncContext) bool { + if (self.max_struct == 0) return false; + const count = self.processed_struct.load(.monotonic); + return (count) >= self.max_struct; } pub fn logError(self: *ThreadSyncContext, message: []const u8, err: anyerror) void {