INSERTION
This commit is contained in:
parent
b0cd4a92cd
commit
254d4da92e
@ -27,14 +27,14 @@ add_compile_definitions(_POSIX_C_SOURCE=200112L)
|
||||
add_compile_definitions(_GNU_SOURCE)
|
||||
add_compile_options(-fno-trapping-math)
|
||||
|
||||
add_executable(codegen_l1 src/l1/anne/codegen.c)
|
||||
target_compile_definitions(codegen_l1
|
||||
PRIVATE PROTOTYPE1_L1_CODEGEN_BOOTSTRAP_USE_CHICKEN_VECU8)
|
||||
#add_executable(codegen_l1 src/l1/anne/codegen.c)
|
||||
#target_compile_definitions(codegen_l1
|
||||
# PRIVATE PROTOTYPE1_L1_CODEGEN_BOOTSTRAP_USE_CHICKEN_VECU8)
|
||||
|
||||
#add_executable(0_test src/l1_4/tests/t0.c)
|
||||
#add_executable(1_test src/l1_4/tests/t1.c)
|
||||
#
|
||||
#add_executable(codegen_l1_5 src/l1_5/anne/codegen.c)
|
||||
add_executable(codegen_l1_5 src/l1_5/anne/codegen.c)
|
||||
#
|
||||
#add_executable(0_render_test src/l2/tests/r0/r0.c gen/l_wl_protocols/xdg-shell-private.c
|
||||
# src/l1/core/rb_tree_node.h)
|
||||
|
||||
@ -10,12 +10,12 @@ void generate_liza_l1_headers() {
|
||||
// todo: continue OptionT + util_templates_instantiation_options refactoring from here
|
||||
generate_util_templ_inst_eve_header(l, ns, (util_templates_instantiation_options){
|
||||
.T = cstr("BoxLizaSound"), .vec = true});
|
||||
generate_util_templ_inst_eve_header(l, ns, cstr("PlayingSound"),
|
||||
(util_templates_instantiation_options){.vec_extended = true});
|
||||
generate_util_templ_inst_eve_header(l, ns, cstr("BoxLizaInstrument"),
|
||||
(util_templates_instantiation_options){ .vec = true});
|
||||
generate_util_templ_inst_eve_header(l, ns, cstr("MyInstrument"),
|
||||
(util_templates_instantiation_options){ .vec = true});
|
||||
generate_util_templ_inst_eve_header(l, ns, (util_templates_instantiation_options){
|
||||
.T = cstr("PlayingSound"), .vec_extended = true});
|
||||
generate_util_templ_inst_eve_header(l, ns, (util_templates_instantiation_options){
|
||||
.T = cstr("BoxLizaInstrument"), .vec = true});
|
||||
generate_util_templ_inst_eve_header(l, ns, (util_templates_instantiation_options){
|
||||
.T = cstr("MyInstrument"), .vec = true});
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -7,18 +7,20 @@ void generate_margaret_eve_for_vulkan_utils() {
|
||||
SpanU8 l = cstr("l1");
|
||||
SpanU8 ns = cstr("margaret");
|
||||
mkdir_nofail("l1/eve/margaret");
|
||||
generate_util_templ_inst_eve_header(l, ns, cstr("MargaretScoredPhysicalDevice"),
|
||||
(util_templates_instantiation_options){ .t_primitive = true, .vec = true, .span = true,
|
||||
.mut_span = true, .collab_vec_span = true, .span_sort = true});
|
||||
|
||||
generate_util_templ_inst_eve_header(l, ns, (util_templates_instantiation_options){
|
||||
.T = cstr("MargaretScoredPhysicalDevice"), .t_primitive = true, .vec = true, .span = true,
|
||||
.mut_span = true, .collab_vec_span = true, .span_sort = true
|
||||
});
|
||||
generate_eve_span_company_for_primitive(l, ns, cstr("MargaretBufferInMemoryInfo"), true, false);
|
||||
generate_util_templ_inst_eve_header(l, ns, cstr("PtrMargaretBufferInMemoryInfo"),
|
||||
(util_templates_instantiation_options){ .t_primitive = true, .vec = true, .span = true, .mut_span = true,
|
||||
.collab_vec_span = true});
|
||||
generate_util_templ_inst_eve_header(l, ns, (util_templates_instantiation_options){
|
||||
.T = cstr("PtrMargaretBufferInMemoryInfo"), .t_primitive = true, .vec = true, .span = true, .mut_span = true,
|
||||
.collab_vec_span = true
|
||||
});
|
||||
generate_eve_span_company_for_primitive(l, ns, cstr("MargaretImageInMemoryInfo"), true, false);
|
||||
generate_util_templ_inst_eve_header(l, ns, cstr("PtrMargaretImageInMemoryInfo"),
|
||||
(util_templates_instantiation_options){ .t_primitive = true, .vec = true, .span = true, .mut_span = true,
|
||||
.collab_vec_span = true});
|
||||
generate_util_templ_inst_eve_header(l, ns, (util_templates_instantiation_options){
|
||||
.T = cstr("PtrMargaretImageInMemoryInfo"), .t_primitive = true, .vec = true, .span = true, .mut_span = true,
|
||||
.collab_vec_span = true
|
||||
});
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -570,6 +570,7 @@ void option_template_instantiation_op_fix(option_template_instantiation_op* self
|
||||
}
|
||||
|
||||
NODISCARD VecU8 generate_OptionT_struct_and_methods(option_template_instantiation_op op) {
|
||||
option_template_instantiation_op_fix(&op);
|
||||
VecU8 g_OptionT = VecU8_fmt("Option%s", op.T);
|
||||
SpanU8 OptionT = VecU8_to_span(&g_OptionT);
|
||||
|
||||
|
||||
@ -24,112 +24,4 @@ void set_instantiation_op_fix(set_instantiation_op* self){
|
||||
self->t_clonable = true;
|
||||
}
|
||||
|
||||
// /* K and V still must be sized and trivially movable */
|
||||
// typedef struct {
|
||||
// SpanU8 K;
|
||||
// bool k_integer;
|
||||
// bool k_primitive;
|
||||
// bool k_clonable;
|
||||
// SpanU8 V;
|
||||
// bool v_primitive;
|
||||
// bool v_clonable;
|
||||
// } map_instantiation_options;
|
||||
//
|
||||
// void map_instantiation_options_fix(map_instantiation_options* self){
|
||||
// if (self->K.len == 0)
|
||||
// abortf("Key cannot be void");
|
||||
// if (self->k_integer)
|
||||
// self->k_primitive = true;
|
||||
// if (self->k_primitive)
|
||||
// self->k_clonable = true;
|
||||
//
|
||||
// if (self->V.len == 0)
|
||||
// self->v_primitive = true;
|
||||
// if (self->v_primitive)
|
||||
// self->v_clonable = true;
|
||||
// }
|
||||
|
||||
|
||||
// NODISCARD VecU8 codegen_expr_MapKToV_option_ref_mut_pair_type(map_instantiation_options op){
|
||||
// if (op.V.len)
|
||||
// return VecU8_fmt("OptionRefMutPairMap%sTo%s", op.K, op.V);
|
||||
// return VecU8_fmt("OptionRefMut%s", op.K);
|
||||
// }
|
||||
//
|
||||
// /* Generates PairMapKToV structure + [drop] + [clone] methods
|
||||
// * Instantiates Option<PairMapKToV> and Vec<PairMapKToV>
|
||||
// * Generates alias RefPairMapKToV = const PairMapKToV*
|
||||
// * Instantiates Option<RefPairMapKToV> template
|
||||
// * Generates RefMutMapKToV structure (const ptr to key with mutable ptr to value)
|
||||
// * Instantiates Option<RefMutPairMapKToV> template
|
||||
// * If `vec_vec_pair_needed` option is set, Vec<Vec<PairMapKToV>> template will be instantiated
|
||||
// * Vec<Vec<PairMapKToV>> is needed in Hash_Map implementation
|
||||
// */
|
||||
// NODISCARD VecU8 generate_MapKToV_pair_type(map_instantiation_options op, bool vec_vec_pair_needed){
|
||||
// map_instantiation_options_fix(&op);
|
||||
// if (op.V.len == 0)
|
||||
// abortf("No need to generate structure for Key Value pair when Value is void\n");
|
||||
// VecU8 g_pair = codegen_expr_MapKToV_pair_type(op);
|
||||
// SpanU8 pair = VecU8_to_span(&g_pair);
|
||||
// VecU8 result = VecU8_fmt(
|
||||
// "typedef struct {\n"
|
||||
// SPACE4 "%s key;\n"
|
||||
// SPACE4 "%s value;\n"
|
||||
// "} %s;\n\n", op.K, op.V, pair);
|
||||
//
|
||||
// if (!op.k_primitive || !op.v_primitive) {
|
||||
// VecU8_append_vec(&result, VecU8_fmt("void %s_drop(%s self) {\n", pair, pair));
|
||||
// if (!op.k_primitive)
|
||||
// VecU8_append_vec(&result, VecU8_fmt("%s_drop();\n", op.K));
|
||||
// if (!op.v_primitive)
|
||||
// VecU8_append_vec(&result, VecU8_fmt("%s_drop();\n", op.V));
|
||||
// VecU8_append_span(&result, cstr("}\n\n"));
|
||||
// }
|
||||
//
|
||||
// if (op.k_clonable && op.v_clonable && !(op.k_primitive && op.v_primitive)) {
|
||||
// VecU8_append_vec(&result, VecU8_fmt("%s%s %s_clone(const %s* self) {\n",
|
||||
// (op.k_primitive && op.v_primitive) ? cstr("") : cstr("NODISCARD"), pair, pair, pair));
|
||||
// VecU8_append_vec(&result, VecU8_fmt(
|
||||
// SPACE4 "return (%s) {.key = %v, .value = %v};\n"
|
||||
// "}\n\n",
|
||||
// op.k_primitive ? vcstr("self->key") : VecU8_fmt("%s_clone(&self->key)"),
|
||||
// op.v_primitive ? vcstr("self->value") : VecU8_fmt("%s_clone(&self->value)")));
|
||||
// }
|
||||
//
|
||||
// VecU8_append_vec(&result, generate_util_templates_instantiation(pair, (util_templates_instantiation_options){
|
||||
// .t_integer = op.k_integer, .t_primitive = op.k_primitive, .t_clonable = op.k_clonable,
|
||||
// .vec = true, .vec_extended = true, .option = true}));
|
||||
//
|
||||
// VecU8 g_vec_pair = codegen_expr_MapKToV_vec_pair_type(op);
|
||||
// SpanU8 vec_pair = VecU8_to_span(&g_vec_pair);
|
||||
// VecU8 g_ref_pair = codegen_expr_MapKToV_ref_pair_type(op);
|
||||
// SpanU8 ref_pair = VecU8_to_span(&g_ref_pair);
|
||||
//
|
||||
// VecU8_append_vec(&result, VecU8_fmt("typedef const %s* %s;\n\n", pair, ref_pair));
|
||||
// VecU8_append_vec(&result, generate_util_templates_instantiation(ref_pair,
|
||||
// (util_templates_instantiation_options){.t_integer = true, .option = true}));
|
||||
//
|
||||
// VecU8 g_ref_mut_pair = codegen_expr_MapKToV_ref_mut_pair_type(op);
|
||||
// SpanU8 ref_mut_pair = VecU8_to_span(&g_ref_pair);
|
||||
//
|
||||
// VecU8_append_vec(&result, VecU8_fmt(
|
||||
// "typedef struct {\n"
|
||||
// SPACE4 "const %s* key;\n"
|
||||
// SPACE4 "%s* value;\n"
|
||||
// "} %s\n\n", op.K, op.V, ref_mut_pair));
|
||||
// VecU8_append_vec(&result, generate_util_templates_instantiation(ref_mut_pair,
|
||||
// (util_templates_instantiation_options){.t_integer = true, .option = true}));
|
||||
//
|
||||
// if (vec_vec_pair_needed) {
|
||||
// VecU8_append_vec(&result, generate_util_templates_instantiation(vec_pair,
|
||||
// (util_templates_instantiation_options){.vec = true}));
|
||||
// }
|
||||
//
|
||||
// VecU8_drop(g_ref_mut_pair);
|
||||
// VecU8_drop(g_ref_pair);
|
||||
// VecU8_drop(g_vec_pair);
|
||||
// VecU8_drop(g_pair);
|
||||
// return result;
|
||||
// }
|
||||
|
||||
#endif
|
||||
|
||||
@ -3,100 +3,97 @@
|
||||
|
||||
#include "all_set_map_templ_util_inst.h"
|
||||
|
||||
// VecU8 codegen_rb_tree_NOT_EQUAL(set_instantiation_op op, SpanU8 A, SpanU8 B){
|
||||
// return op.t_integer ? VecU8_fmt("%s != %s", A, B) : VecU8_fmt("!%s_equal_%s(%s, %s)", op.T, op.T, A, B);
|
||||
// }
|
||||
//
|
||||
// VecU8 codegen_rb_tree_LESS(set_instantiation_op op, SpanU8 A, SpanU8 B){
|
||||
// return op.t_integer ? VecU8_fmt("A < B", A, B) : VecU8_fmt("%s_less_%s(%s, %s)", op.T, op.T, A, B);
|
||||
// }
|
||||
|
||||
/* When key is given by value into some method of Buff_RBTreeSet */
|
||||
NODISCARD VecU8 codegen_rb_tree_set_key_value_NOT_EQUAL_element(set_instantiation_op op, SpanU8 node_id_var_name){
|
||||
if (op.t_integer)
|
||||
return VecU8_fmt("self->el.buf[%s - 1] != key", node_id_var_name);
|
||||
return VecU8_fmt("!%s_equal_%s(&self->el.buf[%s - 1], &key)", op.T, op.T, node_id_var_name);
|
||||
}
|
||||
|
||||
/* When key is given by value into some method of Buff_RBTreeSet */
|
||||
NODISCARD VecU8 codegen_rb_tree_set_key_value_LESS_element(set_instantiation_op op, SpanU8 node_id_var_name){
|
||||
if (op.t_integer)
|
||||
return VecU8_fmt("key < self->el.buf[%s - 1]", node_id_var_name);
|
||||
return VecU8_fmt("%s_less_%s(&key, &self->el.buf[%s - 1])", op.T, op.T, node_id_var_name);
|
||||
}
|
||||
|
||||
/* src/l1_5/core/rb_tree_node.h is a dependency of all instantiations of rb_tree_set template
|
||||
* Don't forget to include them
|
||||
*/
|
||||
NODISCARD VecU8 generate_rb_tree_set_template_instantiation(set_instantiation_op op){
|
||||
set_instantiation_op_fix(&op);
|
||||
VecU8 res = VecU8_new();
|
||||
VecU8 set = VecU8_fmt("BuffRBTree_Set%s", op.T);
|
||||
VecU8_append_vec(&res, VecU8_fmt(
|
||||
"typedef struct {\n"
|
||||
SPACE4 ""
|
||||
"}\n\n"
|
||||
));
|
||||
// todo: continue from here after I finish the dumb option shit
|
||||
SPACE4 "VecRBTreeNode tree;\n"
|
||||
SPACE4 "U64 root;\n"
|
||||
SPACE4 "Vec%s"
|
||||
"} %s\n\n", op.T, VecU8_to_span(&set)));
|
||||
|
||||
VecU8_append_vec(&res, VecU8_fmt(
|
||||
"void %s_drop(%s self) {\n"
|
||||
SPACE4 "VecRBTreeNode_drop(self->tree);\n"
|
||||
SPACE4 "Vec%s_drop(self->el);\n"
|
||||
"}\n\n", VecU8_to_span(&set), VecU8_to_span(&set), op.T));
|
||||
|
||||
/* Method insert does not try to replace the existing element with equal key,
|
||||
* it returns true if insertion was done, false it collision happened and key was not inserted */
|
||||
VecU8_append_vec(&res, VecU8_fmt(
|
||||
"bool %s_insert(%s* self, %s key) {\n"
|
||||
SPACE4 "if (self->root == 0) {\n"
|
||||
SPACE4 SPACE4 "assert(self->tree.len == 1);\n"
|
||||
SPACE4 SPACE4 "VecRBTreeNode_append(&self->tree, (RBTreeNode){.color = RBTree_black});\n"
|
||||
SPACE4 SPACE4 "Vec%s_append(&self->el, key);\n"
|
||||
SPACE4 SPACE4 "self->root = 1;\n"
|
||||
SPACE4 SPACE4 "return true;\n"
|
||||
SPACE4 "}\n"
|
||||
SPACE4 "U64 cur = self->root;\n"
|
||||
SPACE4 "while (%v) {\n"
|
||||
SPACE4 SPACE4 "if (%v) {\n"
|
||||
SPACE4 SPACE4 SPACE4 "if (self->tree.buf[cur].left != 0) {\n"
|
||||
SPACE4 SPACE4 SPACE4 SPACE4 "cur = self->tree.buf[cur].left\n"
|
||||
SPACE4 SPACE4 SPACE4 "} else { \n"
|
||||
/* We are inserting to the left of cur */
|
||||
SPACE4 SPACE4 SPACE4 SPACE4 "U64 n = self->tree.len;\n"
|
||||
SPACE4 SPACE4 SPACE4 SPACE4 "VecRBTreeNode_append(&self->tree, (RBTreeeNode){.parent = cur, .color = RBTree_red});\n"
|
||||
SPACE4 SPACE4 SPACE4 SPACE4 "self->tree.buf[cur].left = n;\n"
|
||||
SPACE4 SPACE4 SPACE4 SPACE4 "RBTree_fix_after_insert(&self->tree, &self->root, n);\n"
|
||||
SPACE4 SPACE4 SPACE4 SPACE4 "return true;\n"
|
||||
SPACE4 SPACE4 SPACE4 "}\n"
|
||||
SPACE4 SPACE4 "} else {\n"
|
||||
SPACE4 SPACE4 SPACE4 "if (self->tree.buf[cur].right != 0) {\n"
|
||||
SPACE4 SPACE4 SPACE4 SPACE4 "cur = self->tree.buf[cur].right\n"
|
||||
SPACE4 SPACE4 SPACE4 "} else {\n"
|
||||
/* We are inserting to the right of cur */
|
||||
SPACE4 SPACE4 SPACE4 SPACE4 "U64 n = self->tree.len;\n"
|
||||
SPACE4 SPACE4 SPACE4 SPACE4 "VecRBTreeNode_append(&self->tree, (RBTreeeNode){.parent = cur, .color = RBTree_red});\n"
|
||||
SPACE4 SPACE4 SPACE4 SPACE4 "self->tree.buf[cur].right = n;\n"
|
||||
SPACE4 SPACE4 SPACE4 SPACE4 "RBTree_fix_after_insert(&self->tree, &self->root, n);\n"
|
||||
SPACE4 SPACE4 SPACE4 SPACE4 "return true;\n"
|
||||
SPACE4 SPACE4 SPACE4 "}\n"
|
||||
SPACE4 SPACE4 "}\n"
|
||||
SPACE4 "}\n"
|
||||
SPACE4 "return false;\n"
|
||||
"}\n\n",
|
||||
VecU8_to_span(&set), VecU8_to_span(&set), op.T,
|
||||
codegen_rb_tree_set_key_value_NOT_EQUAL_element(op, cstr("cur")),
|
||||
codegen_rb_tree_set_key_value_LESS_element(op, cstr("cur"))
|
||||
));
|
||||
|
||||
// VecU8_append_vec(&res, VecU8_fmt(
|
||||
// ""));
|
||||
|
||||
VecU8_drop(set);
|
||||
return res;
|
||||
}
|
||||
|
||||
/* This type will require not only the definition of T=MapPair<K, V>, but also Vec<T>, Option<>, Option<&mut T> and Option<&T>
|
||||
* Also it requires l1_5/core/rb_tree_node.h to be included by that point */
|
||||
// NODISCARD VecU8 generate_rb_tree_set_template_instantiation(map_instantiation_options op, bool
|
||||
// bool implementation_mark){
|
||||
// VecU8 g_map = get_rb_tree_MapKToV_name(op, implementation_mark);
|
||||
// SpanU8 map = VecU8_to_span(&g_map);
|
||||
// VecU8 g_pair = get_MapKToV_pair_name(op);
|
||||
// SpanU8 pair = VecU8_to_span(&g_pair);
|
||||
// VecU8 g_vec_pair = VecU8_fmt("Vec%s", pair);
|
||||
// SpanU8 vec_pair = VecU8_to_span(&g_vec_pair);
|
||||
// VecU8 g_option_pair = VecU8_fmt("Option%s", pair);
|
||||
// SpanU8 option_pair = VecU8_to_span(&g_option_pair);
|
||||
// VecU8 g_option_ref_pair = VecU8_fmt("OptionRef%s", pair);
|
||||
// SpanU8 option_ref_pair = VecU8_to_span(&g_option_ref_pair);
|
||||
// VecU8 g_option_ref_mut_pair = VecU8_fmt("OptionRefMut%s", pair);
|
||||
// SpanU8 option_ref_mut_pair = VecU8_to_span(&g_option_ref_mut_pair);
|
||||
//
|
||||
// VecU8 res = VecU8_new();
|
||||
//
|
||||
// VecU8_append_vec(&res, VecU8_fmt(
|
||||
// "typedef struct {\n"
|
||||
// SPACE4 "VecRBTreeNode tree;\n"
|
||||
// SPACE4 "size_t root;\n"
|
||||
// SPACE4 "%s el;\n"
|
||||
// "} %s;\n\n", vec_pair, map));
|
||||
//
|
||||
// VecU8_append_vec(&res, VecU8_fmt(
|
||||
// "NODISCARD %s %s_new() {\n"
|
||||
// SPACE4 "return (%s){.tree = VecRBTreeNode_new_zeroinit(1), .root = 0, .el = %s_new()};\n"
|
||||
// "}\n\n", map, map, map, vec_pair));
|
||||
//
|
||||
// VecU8_append_vec(&res, VecU8_fmt(
|
||||
// "NODISCARD %s %s_new_reserved(size_t n) {\n"
|
||||
// SPACE4 "return (%s){.tree = VecRBTreeNode_new_reserved(1 + n), .root = 0, .el = %s_new_reserved(n)};\n"
|
||||
// "}\n\n", map, map, map, vec_pair));
|
||||
//
|
||||
// VecU8_append_vec(&res, VecU8_fmt(
|
||||
// "void %s_drop(%s self) {\n"
|
||||
// SPACE4 "VecRBTreeNode_drop(self.tree);\n"
|
||||
// SPACE4 "%s_drop(self.el);\n"
|
||||
// "}\n\n", vec_pair));
|
||||
//
|
||||
// VecU8_append_vec(&res, VecU8_fmt(
|
||||
// "bool %s_contains(const %s* self, const %s* key){\n"
|
||||
// SPACE4 "size_t cur = self->root;\n"
|
||||
// SPACE4 "while (cur > 0) {\n"
|
||||
// SPACE4 SPACE4 "const RBTreeNode* node = VecRBTreeNode_at(&self->tree, cur);\n"
|
||||
// SPACE4 SPACE4 "if %v\n"
|
||||
// SPACE4 SPACE4 SPACE4 "return true;\n"
|
||||
// SPACE4 SPACE4 "cur = %v ? node->left : node -> right;\n"
|
||||
// SPACE4 "}\n"
|
||||
// SPACE4 "return false\n"
|
||||
// "}\n\n", map, map, op.K,
|
||||
// codegen_T_ref_equal_T_ref(op.K, op.k_integer, vcstr("key"), codegen_rb_tree_el_keyptr(op, cstr("cur"))),
|
||||
// codegen_T_ref_less_T_ref(op.K, op.k_integer, vcstr("key"), codegen_rb_tree_el_keyptr(op, cstr("cur")))));
|
||||
//
|
||||
// /* Map may want to get mutable reference to Value of minimal pair
|
||||
// * Btw, UB happens when you call this function on an empty map
|
||||
// */
|
||||
// VecU8_append_vec(&res, VecU8_fmt(
|
||||
// "const %s* %s_min_unsafe(const %s* self) {\n"
|
||||
// SPACE4 "size_t cur = self->root;\n"
|
||||
// SPACE4 "while (self->tree[cur]->left) {\n"
|
||||
// SPACE4 SPACE4 "cur = self->tree[cur]->left;\n"
|
||||
// SPACE4"}\n"
|
||||
// SPACE4 "return &self->el[cur - 1]\n"
|
||||
// "\n\n", pair, ));
|
||||
//
|
||||
// VecU8_append_vec(&res, VecU8_fmt(
|
||||
// "const %s* %s_max_unsafe(const %s* self) {\n"
|
||||
// SPACE4 "size_t cur = self->root;\n"
|
||||
// SPACE4 "while (self->tree[cur]->left) {\n"
|
||||
// SPACE4 SPACE4 "cur = self->tree[cur]->left;\n"
|
||||
// SPACE4"}\n"
|
||||
// SPACE4 "return &self->el[cur - 1]\n"
|
||||
// "\n\n", T, set));
|
||||
//
|
||||
// VecU8_drop(g_option);
|
||||
// VecU8_drop(g_vec);
|
||||
// VecU8_drop(g_set);
|
||||
//
|
||||
// return res;
|
||||
// }
|
||||
#endif
|
||||
@ -3,17 +3,105 @@
|
||||
|
||||
#include "../../l1/core/util.h"
|
||||
|
||||
|
||||
#define RBTree_black 0
|
||||
#define RBTree_red 1
|
||||
typedef enum {
|
||||
RBTree_black = 0,
|
||||
RBTree_red = 1,
|
||||
} RBTreeColor;
|
||||
|
||||
typedef struct {
|
||||
size_t left;
|
||||
size_t right;
|
||||
size_t parent;
|
||||
bool color;
|
||||
/* 0 is black, 1 is red */
|
||||
RBTreeColor color;
|
||||
} RBTreeNode;
|
||||
|
||||
#include "../../../gen/l1/eve/embassy_l1_5/VecRBTreeNode.h"
|
||||
|
||||
void RBTree_left_rotate(RBTreeNode* tree, U64* root, U64 x){
|
||||
assert(x != 0);
|
||||
U64 y = tree[x].right;
|
||||
assert(y != 0);
|
||||
tree[x].right = tree[y].left;
|
||||
if (tree[x].right != 0)
|
||||
tree[tree[x].right].parent = x;
|
||||
|
||||
tree[y].parent = tree[x].parent;
|
||||
if (tree[y].parent != 0) {
|
||||
*root = y;
|
||||
} else if (x == tree[tree[x].parent].left) {
|
||||
tree[tree[x].parent].left = y;
|
||||
} else {
|
||||
tree[tree[x].parent].right = y;
|
||||
}
|
||||
tree[x].parent = y;
|
||||
tree[y].left = x;
|
||||
}
|
||||
|
||||
void RBTree_right_rotate(RBTreeNode* tree, U64* root, U64 x){
|
||||
assert(x != 0);
|
||||
U64 y = tree[x].left;
|
||||
assert(y != 0);
|
||||
tree[x].left = tree[y].right;
|
||||
if (tree[x].left != 0)
|
||||
tree[tree[x].left].parent = x;
|
||||
|
||||
tree[y].parent = tree[x].parent;
|
||||
if (tree[y].parent != 0) {
|
||||
*root = y;
|
||||
} else if (x == tree[tree[x].parent].right) {
|
||||
tree[tree[x].parent].right = y;
|
||||
} else {
|
||||
tree[tree[x].parent].left = y;
|
||||
}
|
||||
tree[x].parent = y;
|
||||
tree[y].right = x;
|
||||
}
|
||||
|
||||
/* Helper function. Called in automatically generated code */
|
||||
void RBTree_fix_after_insert(RBTreeNode* tree, U64* root, U64 me){
|
||||
assert(me);
|
||||
while (true) {
|
||||
U64 mom = tree[me].parent;
|
||||
if (mom == 0)
|
||||
break;
|
||||
if (tree[mom].color == RBTree_black)
|
||||
break;
|
||||
U64 grandma = tree[mom].parent;
|
||||
U64 aunt = tree[grandma].left == mom ? tree[grandma].right : tree[grandma].left;
|
||||
assert(aunt != mom);
|
||||
if (tree[aunt].color == RBTree_red) {
|
||||
/* Easy case */
|
||||
tree[mom].color = RBTree_black;
|
||||
tree[aunt].color = RBTree_black;
|
||||
tree[grandma].color = RBTree_red;
|
||||
me = grandma;
|
||||
} else if (tree[grandma].left == mom) {
|
||||
/* Hard case: firstborn orientation */
|
||||
if (tree[mom].right == me) {
|
||||
RBTree_left_rotate(tree, root, mom);
|
||||
tree[me].color = RBTree_black;
|
||||
} else {
|
||||
tree[mom].color = RBTree_black;
|
||||
}
|
||||
RBTree_right_rotate(tree, root, grandma);
|
||||
tree[grandma].color = RBTree_red;
|
||||
return;
|
||||
} else {
|
||||
/* Hard case: benjamin orientation */
|
||||
if (tree[mom].left == me) {
|
||||
RBTree_right_rotate(tree, root, mom);
|
||||
tree[me].color = RBTree_black;
|
||||
} else {
|
||||
tree[mom].color = RBTree_black;
|
||||
}
|
||||
RBTree_left_rotate(tree, root, grandma);
|
||||
tree[grandma].color = RBTree_red;
|
||||
return;
|
||||
}
|
||||
}
|
||||
assert(*root == me);
|
||||
tree[me].color = RBTree_black;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -16,12 +16,17 @@
|
||||
#include "../../../gen/l1/vulkan/VecVkExtensionProperties.h"
|
||||
#include "../../../gen/l1/vulkan/VecVkImageView.h"
|
||||
#include "../../../gen/l1/vulkan/VecVkPhysicalDevice.h"
|
||||
#include "../../../gen/l1/vulkan/SpanAndOption_VkFormat.h"
|
||||
#include "../../../gen/l1/vulkan/SpanVkFormat.h"
|
||||
#include "../../../gen/l1/vulkan/OptionVkFormat.h"
|
||||
#include "../../../gen/l1/vulkan/VecVkDescriptorPoolSize.h"
|
||||
#include "../../../gen/l1/vulkan/VecVkQueueFamilyProperties.h"
|
||||
#include "../../../gen/l1/vulkan/OptionVkCompositeAlphaFlagBitsKHR.h"
|
||||
#include "../../../gen/l1/vulkan/VecAndOption_VkPresentModeKHR.h"
|
||||
#include "../../../gen/l1/vulkan/VecAndOption_VkSurfaceFormatKHR.h"
|
||||
#include "../../../gen/l1/vulkan/VecVkPresentModeKHR.h"
|
||||
#include "../../../gen/l1/vulkan/OptionVkPresentModeKHR.h"
|
||||
#include "../../../gen/l1/vulkan/OptionVkPresentModeKHR.h"
|
||||
#include "../../../gen/l1/vulkan/VecVkPresentModeKHR.h"
|
||||
#include "../../../gen/l1/vulkan/VecVkSurfaceFormatKHR.h"
|
||||
#include "../../../gen/l1/vulkan/OptionVkSurfaceFormatKHR.h"
|
||||
#include <vulkan/vulkan_wayland.h>
|
||||
// #include <vulkan/vulkan.h>
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user