TreeNode * Tree_insert(TreeNode * tn, int val) { if (tn == NULL) { return Tree_constrct(val); } if ((tn -> data) == val) { return tn; // if the data is already in the tree } if ((tn -> data) > val) { // val will be inserted to the left side tn -> left = Tree_insert(tn -> left, val); return tn; // compare this with linked list /* fr -> neft = List_insert(fr -> next, val); return fr; */ } // val will be inserted to the right side tn -> right = Tree_insert(tn -> right, val); return tn; }
TreeNode * Tree_insert(TreeNode * node, int value) { if(node == NULL) return TreeNode_create(value); if(value < node -> value) node -> left = Tree_insert(node -> left, value); if(value > node -> value) node -> right = Tree_insert(node -> right, value); // If they're equal, then we have nothing to do... return node; }
Tree Tree_insert (Tree t, FMComparison cmp, cast key, cast value) { int discrim; if (t==NULL) return Tree_new(key,value); discrim = cmp(key,t->key); if (discrim==0) { t->value = value; /* overwrite old value */ return t; } else if (discrim<0) { return mkBalTree (t, Tree_insert (t->left, cmp, key, value), t->right); } else { return mkBalTree (t, t->left, Tree_insert (t->right, cmp, key, value)); } }
void StructPrototype_add_elem(ParserEnv* e, StructPrototype _self, const char* name, int type) { var key, data; key.str_var = name; if (Tree_find(_self->symbol_to_elem_tree, key, &data)) { parser_exception exce = s_exce_table[The_element_name_is_defined_more_than_once_in_struct]; ParserEnv_push_exce(e, exce); return; } euint elem_size = _get_symbol_type_size(e, type); if (elem_size < 0) { parser_exception exce = s_exce_table[Unknown_data_type]; ParserEnv_push_exce(e, exce); return; } StructElem elem = (StructElem)SMalloc(sizeof(struct_elem)); elem->type = type; elem->offs = _self->size; elem->size = elem_size; _self->size += elem_size; data.vptr_var = elem; Tree_insert(_self->symbol_to_elem_tree, key, data); }
void FunctionClosures_push_vari(FunctionClosures _self, const char* var_name, SymbolValue* v) { SymbolValue* sv = (SymbolValue*)SMalloc(sizeof(SymbolValue)); memcpy(sv, v, sizeof(SymbolValue)); var key, data; key.str_var = (EString)var_name; data.vptr_var = sv; Tree_insert(_self->vari_tree, key, data); switch (_self->status) { case DeclareInputParamsStatus: ///Tree_insert(_self->input_param_tree, key, data); { apush(_self->input_param_array, sv); } break; case DeclareOutputParamsStatus: ///Tree_insert(_self->output_param_tree, key, data); { apush(_self->output_param_array, sv); } break; default: break; } }
void InputSystem::register_input_listener(InputListener* list) { var key, data; key.vptr_var = (vptr)list; data.vptr_var = (vptr)list; Tree_insert(m_input_listen_tree, key, data); }
TreeNode * Tree_build(int * array, int len) { TreeNode * root = NULL; int i; for(i = 0; i < len; ++i) root = Tree_insert(root, array[i]); return root; }
RendererBase::RendererBase ( RendererBase *prev_renderer, bool inherit_material_table, RenderableSorter* sorter ) { if (sorter) renderable_sorter = sorter; else renderable_sorter = ENEW DefaultRenderableSorter; default_rend_matrix = Matrix4x4_new(); Matrix4x4_set_one(default_rend_matrix); render_plane = RenderablePlane_new(); VertexDecl pdec = RenderablePlane_get_vertex_declaration ( render_plane ); display_pass = NULL; clear_sketchbook_pass = NULL; camera_base = prev_renderer->camera_base; x = prev_renderer->x; y = prev_renderer->y; width = prev_renderer->width; height = prev_renderer->height; curt_render_cam = camera_base; ///used_renderable_tree = Tree_new ( Vptr, Vptr, Ealloc, Efree ); ///unused_renderable_tree = Tree_new ( Vptr, Vptr, Ealloc, Efree ); if ( !inherit_material_table ) { material_table = Tree_new ( String, Vptr, (MALLOC)Ealloc, (MFREE)Efree ); var key, data; key.str_var = "default_material"; MaterialPrototype mp; { SdrNdGen sng = ISdrNdGen.New(); ISdrNdGen.register_default_nodes ( sng ); SDisplayProc s; s.proc = default_material_proc3; mp = MaterialPrototype_new ( pdec, 2, s, Shaded, false ); ISdrNdGen.Delete ( sng ); } data.vptr_var = mp; Tree_insert ( material_table, key, data ); material_count = 3; own_material_table = true; } else { material_table = prev_renderer->material_table; material_count = prev_renderer->material_count; own_material_table = false; } own_camera = false; }
void _insert_key_word(ParserEnv* e, char* str, int type) { var key, data; key.str_var = str; SymbolValue* v = (SymbolValue*)SMalloc(sizeof(SymbolValue)); v->type = type; v->data.mem_addr.mem_type = MaxMem; data.vptr_var = v; Tree_insert(e->key_word_tree, key, data); }
FunctionClosures ParserEnv_new_function(ParserEnv* e, const char* _func_name) { FunctionClosures func = FunctionClosures_new(e); var key, data; key.str_var = (EString)_func_name; data.vptr_var = func; Tree_insert(e->func_tree, key, data); e->curt_func = func; SymbolStack_push(&e->sym_stack); return func; }
TreeNode * Tree_insert(TreeNode * tn, int val) { if (tn == NULL) { // empty, create a node return TreeNode_construct(val); } // not empty if (val == (tn -> value)) { // do not insert the same value, values must be distinct return tn; } if (val < (tn -> value)) { tn -> left = Tree_insert(tn -> left, val); } else { tn -> right = Tree_insert(tn -> right, val); } return tn; }
RendererBase::RendererBase ( ViewportPtr view, RenderableSorter* sorter ) { if (sorter) renderable_sorter = sorter; else renderable_sorter = ENEW DefaultRenderableSorter; default_rend_matrix = Matrix4x4_new(); Matrix4x4_set_one(default_rend_matrix); render_plane = RenderablePlane_new(); VertexDecl pdec = RenderablePlane_get_vertex_declaration ( render_plane ); display_pass = NULL; clear_sketchbook_pass = create_clear_sketchbook_pass ( pdec ); camera_base = Camera_new ( view->width, view->height ); x = view->x; y = view->y; width = view->width; height = view->height; Camera_translate ( camera_base, 0.0, 0.0, 1.5f ); curt_render_cam = camera_base; ///used_renderable_tree = Tree_new ( Vptr, Vptr, Ealloc, Efree ); ///unused_renderable_tree = Tree_new ( Vptr, Vptr, Ealloc, Efree ); material_table = Tree_new ( String, Vptr, (MALLOC)Ealloc, (MFREE)Efree ); var key, data; key.str_var = "default_material"; MaterialPrototype mp; { SdrNdGen sng = ISdrNdGen.New(); ISdrNdGen.register_default_nodes ( sng ); SDisplayProc s; s.proc = default_material_proc3; mp = MaterialPrototype_new ( pdec, 2, s, Shaded, false ); ISdrNdGen.Delete ( sng ); } data.vptr_var = mp; Tree_insert ( material_table, key, data ); material_count = 3; own_camera = true; own_material_table = true; }
StructPrototype ParserEnv_new_struct_prototype(ParserEnv* e, const char* _struct_name) { var key, data; key.str_var = _struct_name; if (Tree_find(e->struct_tree, key, &data)) { parser_exception exce = s_exce_table[Structure_is_defined_more_than_once]; ParserEnv_push_exce(e, exce); return NULL; } StructPrototype ret = StructPrototype_new(); data.vptr_var = ret; Tree_insert(e->struct_tree, key, data); e->curt_struct = ret; return ret; }
void ParserEnv_Init(ParserEnv* e, const char* str) { e->char_count = 0; /** e->text = "func test2 (a float) (b float)\n" "{\n" " b = a / 2.0;\n" " print a;\n" "}\n" "func ttt (a float, b float) (c float)\n" "{\n" " var t float;\n" " var g float;\n" " var i int;\n" " i = 3;\n" " t = 4.0 * i;\n" " g = test2(3.0);\n" " j := t * g;\n" " print j;\n" "}"; **/ /** e->text = "func ttt (a float, b float) (c float)\n" "{\n" " var t float;\n" " var g float;\n" " t = 3.0;\n" " g = 1.0;\n" " print t > g;\n" "}"; **/ /** e->text = "func test2 (a float) (b float)\n" "{\n" " b = a / 2.0;\n" " print b;\n" "}\n" "func ttt (a float, b float) (c float)\n" "{\n" " var t float;\n" " var g float;\n" " t = 1.0;\n" " g = 2.0;\n" " if ( t < g )\n" " {\n" " aaa := t + 1.0;\n" " if (aaa == g)\n" " {\n" " print 100.0;\n" " }\n" " j := 9.0;\n" " j = test2(j);\n" " print j;\n" " }\n" " else if (t > g)\n" " {\n" " j := 12.0;\n" " print j;\n" " }\n" " print 2.0;\n" "}\n"; **/ e->text = (EString)str; ///e->sym_2_value_node_tree = Tree_new(String, Vptr, Ealloc, Efree); ///e->value_2_value_node_tree = Tree_new(Vptr, Vptr, Ealloc, Efree); e->key_word_tree = Tree_new(String, Vptr, Ealloc, Efree); e->func_tree = Tree_new(String, Vptr, Ealloc, Efree); e->struct_tree = Tree_new(String, Vptr, Ealloc, Efree); e->curt_func = NULL; void _insert_key_word(char* str, int type) { var key, data; key.str_var = str; SymbolValue* v = Malloc(sizeof(SymbolValue)); v->type = type; v->data.mem_addr.mem_type = MaxMem; data.vptr_var = v; Tree_insert(e->key_word_tree, key, data); }
void FM_insert (FiniteMap fm, cast key, cast value) { fm->root = Tree_insert(fm->root, fm->cmp, key, value); }