Condition value now can have a HashMap of UUID/void
This commit is contained in:
parent
ca5de646d6
commit
65ba0263cc
@ -46,8 +46,6 @@ pub const SchemaEngine = struct {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug("SchemaEngine init with {d} SchemaStruct after populateFileIndexUUIDMap.", .{struct_array.items.len});
|
|
||||||
|
|
||||||
return SchemaEngine{
|
return SchemaEngine{
|
||||||
.allocator = allocator,
|
.allocator = allocator,
|
||||||
.null_terminated_schema_buff = null_terminated_schema_buff,
|
.null_terminated_schema_buff = null_terminated_schema_buff,
|
||||||
|
@ -59,7 +59,6 @@ pub const ConditionValue = union(enum) {
|
|||||||
bool_: bool,
|
bool_: bool,
|
||||||
self: UUID,
|
self: UUID,
|
||||||
unix: u64,
|
unix: u64,
|
||||||
link: UUID,
|
|
||||||
int_array: std.ArrayList(i32),
|
int_array: std.ArrayList(i32),
|
||||||
str_array: std.ArrayList([]const u8),
|
str_array: std.ArrayList([]const u8),
|
||||||
float_array: std.ArrayList(f64),
|
float_array: std.ArrayList(f64),
|
||||||
@ -67,14 +66,17 @@ pub const ConditionValue = union(enum) {
|
|||||||
unix_array: std.ArrayList(u64),
|
unix_array: std.ArrayList(u64),
|
||||||
link_array: *std.AutoHashMap(UUID, void),
|
link_array: *std.AutoHashMap(UUID, void),
|
||||||
|
|
||||||
pub fn deinit(self: ConditionValue) void {
|
pub fn deinit(self: ConditionValue, allocator: std.mem.Allocator) void {
|
||||||
switch (self) {
|
switch (self) {
|
||||||
.int_array => self.int_array.deinit(),
|
.int_array => self.int_array.deinit(),
|
||||||
.str_array => self.str_array.deinit(),
|
.str_array => self.str_array.deinit(),
|
||||||
.float_array => self.float_array.deinit(),
|
.float_array => self.float_array.deinit(),
|
||||||
.bool_array => self.bool_array.deinit(),
|
.bool_array => self.bool_array.deinit(),
|
||||||
.unix_array => self.unix_array.deinit(),
|
.unix_array => self.unix_array.deinit(),
|
||||||
.link_array => self.link_array.deinit(),
|
.link_array => {
|
||||||
|
self.link_array.deinit();
|
||||||
|
allocator.destroy(self.link_array);
|
||||||
|
},
|
||||||
else => {},
|
else => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -111,14 +113,6 @@ pub const ConditionValue = union(enum) {
|
|||||||
return ConditionValue{ .unix = s2t.parseDatetime(value).toUnix() };
|
return ConditionValue{ .unix = s2t.parseDatetime(value).toUnix() };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn initLink(value: []const u8) ConditionValue {
|
|
||||||
const uuid = UUID.parse(value) catch {
|
|
||||||
std.debug.print("Error: {s}", .{value});
|
|
||||||
@panic("WFT ?");
|
|
||||||
};
|
|
||||||
return ConditionValue{ .link = uuid };
|
|
||||||
}
|
|
||||||
|
|
||||||
// Array
|
// Array
|
||||||
pub fn initArrayInt(allocator: std.mem.Allocator, value: []const u8) ConditionValue {
|
pub fn initArrayInt(allocator: std.mem.Allocator, value: []const u8) ConditionValue {
|
||||||
return ConditionValue{ .int_array = s2t.parseArrayInt(allocator, value) };
|
return ConditionValue{ .int_array = s2t.parseArrayInt(allocator, value) };
|
||||||
@ -159,8 +153,8 @@ pub const Condition = struct {
|
|||||||
data_type: DataType = undefined,
|
data_type: DataType = undefined,
|
||||||
data_index: usize = undefined, // Index in the file
|
data_index: usize = undefined, // Index in the file
|
||||||
|
|
||||||
pub fn deinit(self: Condition) void {
|
pub fn deinit(self: Condition, allocator: std.mem.Allocator) void {
|
||||||
self.value.deinit();
|
self.value.deinit(allocator);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -187,7 +181,7 @@ pub const Filter = struct {
|
|||||||
pub fn deinit(self: *Filter) void {
|
pub fn deinit(self: *Filter) void {
|
||||||
switch (self.root.*) {
|
switch (self.root.*) {
|
||||||
.logical => self.freeNode(self.root),
|
.logical => self.freeNode(self.root),
|
||||||
.condition => |condition| condition.deinit(),
|
.condition => |condition| condition.deinit(self.allocator),
|
||||||
else => {},
|
else => {},
|
||||||
}
|
}
|
||||||
self.allocator.destroy(self.root);
|
self.allocator.destroy(self.root);
|
||||||
@ -201,7 +195,7 @@ pub const Filter = struct {
|
|||||||
self.allocator.destroy(logical.left);
|
self.allocator.destroy(logical.left);
|
||||||
self.allocator.destroy(logical.right);
|
self.allocator.destroy(logical.right);
|
||||||
},
|
},
|
||||||
.condition => |condition| condition.deinit(),
|
.condition => |condition| condition.deinit(self.allocator),
|
||||||
.empty => {},
|
.empty => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -668,23 +668,22 @@ pub const Parser = struct {
|
|||||||
.time => condition.value = ConditionValue.initTime(self.toker.buffer[start_index..token.loc.end]),
|
.time => condition.value = ConditionValue.initTime(self.toker.buffer[start_index..token.loc.end]),
|
||||||
.datetime => condition.value = ConditionValue.initDateTime(self.toker.buffer[start_index..token.loc.end]),
|
.datetime => condition.value = ConditionValue.initDateTime(self.toker.buffer[start_index..token.loc.end]),
|
||||||
.bool => condition.value = ConditionValue.initBool(self.toker.buffer[start_index..token.loc.end]),
|
.bool => condition.value = ConditionValue.initBool(self.toker.buffer[start_index..token.loc.end]),
|
||||||
.link_array => {
|
.link_array, .link => switch (token.tag) {
|
||||||
var map = std.AutoHashMap(UUID, void).init(self.allocator);
|
.l_brace, .l_bracket => {
|
||||||
try self.file_engine.populateVoidUUIDMap(
|
const map = self.allocator.create(std.AutoHashMap(UUID, void)) catch return ZipponError.MemoryError;
|
||||||
struct_name,
|
map.* = std.AutoHashMap(UUID, void).init(self.allocator);
|
||||||
filter,
|
if (condition.data_type == .link) additional_data.entity_count_to_find = 1; // FIXME: Look like it return 2 of them, not 1
|
||||||
&map,
|
try self.file_engine.populateVoidUUIDMap(
|
||||||
&additional_data,
|
struct_name,
|
||||||
);
|
filter,
|
||||||
condition.value = ConditionValue.initLinkArray(&map);
|
map,
|
||||||
},
|
&additional_data,
|
||||||
.link => switch (token.tag) {
|
);
|
||||||
.l_brace, .l_bracket => {}, // Get the first entity using a filter
|
log.debug("Found {d} entity when parsing for populateVoidUUID\n", .{map.count()});
|
||||||
.uuid_literal => {
|
condition.value = ConditionValue.initLinkArray(map);
|
||||||
condition.value = ConditionValue.initLink(self.toker.buffer[start_index..token.loc.end]);
|
|
||||||
},
|
},
|
||||||
else => return printError(
|
else => return printError(
|
||||||
"Error: Expected filter or UUID",
|
"Error: Expected filter",
|
||||||
ZiQlParserError.SynthaxError,
|
ZiQlParserError.SynthaxError,
|
||||||
self.toker.buffer,
|
self.toker.buffer,
|
||||||
token.loc.start,
|
token.loc.start,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user