From 8c6a6188dd093c8fb909a93e913016eeae332e86 Mon Sep 17 00:00:00 2001 From: MrBounty Date: Thu, 30 Jan 2025 20:21:50 +0100 Subject: [PATCH] Working REMOVE and REMOVEAT --- src/file/array.zig | 5 ----- src/ziql/parts/newData.zig | 10 +++++++++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/file/array.zig b/src/file/array.zig index ea36a43..d533c85 100644 --- a/src/file/array.zig +++ b/src/file/array.zig @@ -171,11 +171,6 @@ fn append(allocator: std.mem.Allocator, input: *zid.Data, data: ConditionValue) } } -// TODO: Change the array for a map to speed up thing -// And also I dont really need to realoc anything, only append need because here it can only go lower -// So I could just memcopy the remaining of the bytes at the current position, so it overwrite the value to remove -// Like if I want to re;ove 3 in [1 2 3 4 5], it would become [1 2 4 5 5]. Then I dont take the last value when I return. -// But that mean I keep in memory useless data, so maybe not fn remove(allocator: std.mem.Allocator, input: *zid.Data, data: ConditionValue) !void { var iter = try zid.ArrayIterator.init(input.*); switch (input.*) { diff --git a/src/ziql/parts/newData.zig b/src/ziql/parts/newData.zig index 307f59e..931f4da 100644 --- a/src/ziql/parts/newData.zig +++ b/src/ziql/parts/newData.zig @@ -49,6 +49,8 @@ pub fn parseNewData( var state: Self.State = .expect_member_OR_value; var i: usize = 0; + var array_condition_buf: ArrayCondition = undefined; + while (state != .end) : ({ token = if (!keep_next) self.toker.next() else token; keep_next = false; @@ -131,6 +133,7 @@ pub fn parseNewData( ), .keyword_append => if (for_update) { state = .expect_new_array; + array_condition_buf = .append; } else return printError( "Error: Can only manipulate array with UPDATE.", ZipponError.SynthaxError, @@ -140,6 +143,7 @@ pub fn parseNewData( ), .keyword_remove => if (for_update) { state = .expect_new_array; + array_condition_buf = .remove; } else return printError( "Error: Can only manipulate array with UPDATE.", ZipponError.SynthaxError, @@ -149,6 +153,7 @@ pub fn parseNewData( ), .keyword_remove_at => if (for_update) { state = .expect_new_array; + array_condition_buf = .removeat; } else return printError( "Error: Can only manipulate array with UPDATE.", ZipponError.SynthaxError, @@ -273,7 +278,10 @@ pub fn parseNewData( }; map.put( member_name, - ValueOrArray{ .array = .{ .condition = .append, .data = try self.parseConditionValue(allocator, struct_name, member_name, new_data_type, &token) } }, + ValueOrArray{ .array = .{ + .condition = array_condition_buf, + .data = try self.parseConditionValue(allocator, struct_name, member_name, new_data_type, &token), + } }, ) catch return ZipponError.MemoryError; if (member_data_type == .link or member_data_type == .link_array) { token = self.toker.last_token;