scp_result searchSetStr3_f_a_a(sc_memory_context *context, scp_operand *param1, scp_operand *param2, scp_operand *param3, scp_operand *sets) { scp_result res = SCP_RESULT_FALSE; if (sets[1].set == SCP_TRUE && sets[1].param_type == SCP_ASSIGN) { sets[1].addr = sc_memory_node_new(context, sc_type_node | sc_type_const); } if (sets[2].set == SCP_TRUE && sets[2].param_type == SCP_ASSIGN) { sets[2].addr = sc_memory_node_new(context, sc_type_node | sc_type_const); } sc_iterator3 *it = sc_iterator3_f_a_a_new(context, param1->addr, param2->element_type, param3->element_type); while (SC_TRUE == sc_iterator3_next(it)) { res = SCP_RESULT_TRUE; param2->addr = sc_iterator3_value(it, 1); param3->addr = sc_iterator3_value(it, 2); if (sets[1].set == SCP_TRUE) { sc_memory_arc_new(context, sc_type_arc_pos_const_perm, sets[1].addr, param2->addr); } if (sets[2].set == SCP_TRUE) { sc_memory_arc_new(context, sc_type_arc_pos_const_perm, sets[2].addr, param3->addr); } } sc_iterator3_free(it); return res; }
scp_result scp_sys_gen_for_variables(sc_memory_context *context, scp_operand *param1, scp_operand_pair *variables, sc_uint32 var_count, scp_operand_pair *parameters, sc_uint32 param_count, scp_operand *param4) { sc_uint32 i; if (param1->param_type != SCP_FIXED) { return print_error("sys_gen_for_variables", "Parameter 1 must have FIXED modifier"); } if (SC_FALSE == sc_memory_is_element(context, param1->addr)) { return print_error("sys_gen_for_variables", "Parameter 1 has modifier FIXED, but has not value"); } for (i = 0; i < param_count; i++) { if (parameters[i].operand1->param_type == SCP_ASSIGN || parameters[i].operand2->param_type == SCP_ASSIGN) { return print_error("sys_gen_for_variables", "All elements of parameter set must have FIXED modifier"); } if (SC_FALSE == sc_memory_is_element(context, parameters[i].operand1->addr) || SC_FALSE == sc_memory_is_element(context, parameters[i].operand2->addr)) { return print_error("sys_gen_for_variables", "All elements of parameter set must have value"); } } for (i = 0; i < var_count; i++) { if (variables[i].operand1->param_type == SCP_ASSIGN) { return print_error("sys_gen_for_variables", "All variables of variable set must have FIXED modifier"); } if (SC_FALSE == sc_memory_is_element(context, variables[i].operand1->addr)) { return print_error("sys_gen_for_variables", "All variables of variable set must have value"); } if (variables[i].operand2->param_type == SCP_FIXED) { return print_error("sys_gen_for_variables", "All variables values must have ASSIGN modifier"); } } if (param4 != nullptr) { if (param4->param_type == SCP_FIXED) { if (SC_FALSE == sc_memory_is_element(context, param1->addr)) { return print_error("scp_sys_gen_for_variables", "Parameter 4 has modifier FIXED, but has not value"); } } else { param4->addr = sc_memory_node_new(context, scp_type_const); } } for (i = 0; i < var_count; i++) { if (variables[i].operand2->param_type == SCP_ASSIGN && variables[i].operand2->set == SCP_TRUE) { variables[i].operand2->addr = sc_memory_node_new(context, scp_type_const); } } return sys_gen_for_variables(context, param1, variables, var_count, parameters, param_count, param4); }
// simple arc creation test gpointer create_arc_thread(gpointer data) { sc_memory_context *ctx = sc_memory_context_new(sc_access_lvl_make(8, 8)); int count = GPOINTER_TO_INT(data); int result = count; for (int i = 0; i < count; ++i) { sc_addr addr = sc_memory_node_new(ctx, 0); if (SC_ADDR_IS_EMPTY(addr)) goto result; sc_addr addr2 = sc_memory_node_new(ctx, 0); if (SC_ADDR_IS_EMPTY(addr2)) goto result; sc_addr arc = sc_memory_arc_new(ctx, sc_type_arc_access, addr, addr); if (SC_ADDR_IS_EMPTY(arc)) goto result; continue; result = i + 1; break; } result: { sc_memory_context_free(ctx); } return GINT_TO_POINTER(result); }
scp_result scp_sys_search(sc_memory_context *context, scp_operand *param1, scp_operand *param2, scp_operand_pair *parameters, sc_uint32 param_count, scp_operand *param4, scp_bool full_only) { scp_bool flag2; sc_uint32 i; if (param1->param_type != SCP_FIXED) { return print_error("scp_sys_search", "Parameter 1 must have FIXED modifier"); } if (SC_FALSE == sc_memory_is_element(context, param1->addr)) { return print_error("scp_sys_search", "Parameter 1 has modifier FIXED, but has not value"); } if (param2->param_type == SCP_FIXED) { if (SC_FALSE == sc_memory_is_element(context, param1->addr)) { return print_error("scp_sys_search", "Parameter 2 has modifier FIXED, but has not value"); } } else { flag2 = SCP_TRUE; } for (i = 0; i < param_count; i++) { if (parameters[i].operand1->param_type == SCP_ASSIGN || parameters[i].operand2->param_type == SCP_ASSIGN) { return print_error("scp_sys_search", "All elements of parameter set must have FIXED modifier"); } if (SC_FALSE == sc_memory_is_element(context, parameters[i].operand1->addr) || SC_FALSE == sc_memory_is_element(context, parameters[i].operand2->addr)) { return print_error("scp_sys_search", "All elements of parameter set must have value"); } } if (param4 != nullptr) { if (param4->param_type == SCP_FIXED) { if (SC_FALSE == sc_memory_is_element(context, param1->addr)) { return print_error("scp_sys_search", "Parameter 4 has modifier FIXED, but has not value"); } } else { param4->addr = sc_memory_node_new(context, scp_type_const); } } if (flag2 == SCP_TRUE) { param2->addr = sc_memory_node_new(context, scp_type_const); } return sys_search(context, param1, param2, parameters, param_count, param4, full_only); }
// ------------------------------------------------- sc_bool initialize_keynodes() { RESOLVE_KEYNODE(s_default_ctx, keynode_user); RESOLVE_KEYNODE(s_default_ctx, keynode_question_nrel_answer); RESOLVE_KEYNODE(s_default_ctx, keynode_question_finished); RESOLVE_KEYNODE(s_default_ctx, keynode_command_translate_from_sc); RESOLVE_KEYNODE(s_default_ctx, keynode_nrel_authors); RESOLVE_KEYNODE(s_default_ctx, keynode_nrel_user_answer_formats); RESOLVE_KEYNODE(s_default_ctx, keynode_rrel_source_sc_construction); RESOLVE_KEYNODE(s_default_ctx, keynode_rrel_output_format); RESOLVE_KEYNODE(s_default_ctx, keynode_nrel_translation); RESOLVE_KEYNODE(s_default_ctx, keynode_nrel_format); RESOLVE_KEYNODE(s_default_ctx, keynode_command_generate_instance); RESOLVE_KEYNODE(s_default_ctx, keynode_command_initiated); RESOLVE_KEYNODE(s_default_ctx, keynode_command_failed); RESOLVE_KEYNODE(s_default_ctx, keynode_command_finished); RESOLVE_KEYNODE(s_default_ctx, keynode_rrel_command_arguments); RESOLVE_KEYNODE(s_default_ctx, keynode_rrel_command); RESOLVE_KEYNODE(s_default_ctx, keynode_nrel_command_template); RESOLVE_KEYNODE(s_default_ctx, keynode_nrel_command_result); RESOLVE_KEYNODE(s_default_ctx, keynode_displayed_answer); RESOLVE_KEYNODE(s_default_ctx, keynode_format_scs_json); RESOLVE_KEYNODE(s_default_ctx, keynode_format_scg_json); RESOLVE_KEYNODE(s_default_ctx, keynode_format_scn_json); RESOLVE_KEYNODE(s_default_ctx, keynode_system_element); for (sc_uint32 i = 0; i < RREL_ORDER_COUNT; ++i) { std::stringstream ss; ss << "rrel_" << (i + 1); if (sc_helper_resolve_system_identifier(s_default_ctx, ss.str().c_str(), &(ui_keynode_rrel_order[i])) == SC_FALSE) { ui_keynode_rrel_order[i] = sc_memory_node_new(s_default_ctx, 0); if (sc_helper_set_system_identifier(s_default_ctx, ui_keynode_rrel_order[i], ss.str().c_str(), (sc_uint32)ss.str().size()) != SC_RESULT_OK) return SC_FALSE; } } for (sc_uint32 i = 0; i < UI_ARG_COUNT; ++i) { std::stringstream ss; ss << "ui_arg_" << (i + 1); if (sc_helper_resolve_system_identifier(s_default_ctx, ss.str().c_str(), &(ui_keynode_arg[i])) == SC_FALSE) { ui_keynode_rrel_order[i] = sc_memory_node_new(s_default_ctx, 0); if (sc_helper_set_system_identifier(s_default_ctx, ui_keynode_rrel_order[i], ss.str().c_str(), (sc_uint32)ss.str().size()) != SC_RESULT_OK) return SC_FALSE; } } return SC_TRUE; }
sc_result sc_helper_init(sc_memory_context const * ctx) { g_message("Initialize sc-helper"); _init_keynodes_str(); sc_keynodes = g_new0(sc_addr, SC_KEYNODE_COUNT); if (resolve_nrel_system_identifier(ctx) != SC_RESULT_OK) { g_message("Can't resovle nrel_system_identifier node. Create the last one"); sc_addr addr = sc_memory_node_new(ctx, sc_type_const | sc_type_node_norole); sc_addr link = sc_memory_link_new(ctx); sc_stream *stream = sc_stream_memory_new(keynodes_str[SC_KEYNODE_NREL_SYSTEM_IDENTIFIER], (sc_uint)(sizeof(sc_uchar) * strlen(keynodes_str[SC_KEYNODE_NREL_SYSTEM_IDENTIFIER])), SC_STREAM_FLAG_READ, SC_FALSE); sc_memory_set_link_content(ctx, link, stream); sc_stream_free(stream); sc_addr arc = sc_memory_arc_new(ctx, sc_type_arc_common | sc_type_const, addr, link); sc_memory_arc_new(ctx, sc_type_arc_pos_const_perm, addr, arc); sc_keynodes[SC_KEYNODE_NREL_SYSTEM_IDENTIFIER] = addr; } sc_helper_is_initialized = SC_TRUE; return SC_RESULT_OK; }
sctpErrorCode sctpCommand::processCreateNode(quint32 cmdFlags, quint32 cmdId, QDataStream *params, QIODevice *outDevice) { Q_UNUSED(cmdFlags); Q_ASSERT(params != 0); sc_type type; // read type of node READ_PARAM(type); sc_addr addr = sc_memory_node_new(type); // send result sctpErrorCode result; if (SC_ADDR_IS_NOT_EMPTY(addr)) { writeResultHeader(SCTP_CMD_CREATE_NODE, cmdId, SCTP_RESULT_OK, sizeof(addr), outDevice); outDevice->write((const char*)&addr, sizeof(addr)); result = SCTP_ERROR_NO; }else { writeResultHeader(SCTP_CMD_CREATE_NODE, cmdId, SCTP_RESULT_FAIL, 0, outDevice); result = SCTP_ERROR; } return result; }
sc_result sc_graph_find_conn_comp(sc_addr graph, sc_addr *conn_comp_set) { if (sc_helper_check_arc(sc_graph_keynode_not_oriented_graph, graph, sc_type_arc_pos_const_perm) == SC_FALSE) return SC_RESULT_ERROR_INVALID_PARAMS; sc_addr not_checked_vertices, curr_vertex; sc_iterator3 *it3; sc_iterator5 *it5 = sc_iterator5_f_a_a_a_f_new(graph, sc_type_arc_pos_const_perm, sc_type_node | sc_type_const, sc_type_arc_pos_const_perm, sc_graph_keynode_rrel_vertex); not_checked_vertices = sc_memory_node_new(sc_type_node | sc_type_const); *conn_comp_set = sc_memory_node_new(sc_type_node | sc_type_const); while(sc_iterator5_next(it5) == SC_TRUE) { curr_vertex = it5->results[2]; sc_memory_arc_new(sc_type_arc_pos_const_perm, not_checked_vertices, curr_vertex); } sc_iterator5_free(it5); it3 = sc_iterator3_f_a_a_new(not_checked_vertices, sc_type_arc_pos_const_perm, sc_type_node); while(sc_iterator3_next(it3) == SC_TRUE) { sc_addr curr_conn_comp = sc_memory_node_new(sc_type_node | sc_type_const); curr_vertex = it3->results[2]; if(sc_helper_check_arc(not_checked_vertices, curr_vertex, sc_type_arc_pos_const_perm) == SC_FALSE) continue; deep_first_search_for_find_conn_comp(curr_vertex, not_checked_vertices, curr_conn_comp, graph); sc_memory_arc_new(sc_type_arc_pos_const_perm, *conn_comp_set, curr_conn_comp); } sc_iterator3_free(it3); sc_memory_element_free(not_checked_vertices); return SC_RESULT_OK; }
sc_result sc_graph_find_min_path(sc_addr graph, sc_addr beg_vertex, sc_addr end_vertex, sc_addr_list **path) { sc_addr curr_vertex, cur_wave; sc_addr_list *not_checked_vertices = nullptr, *wave_list_head = nullptr, *path_head = nullptr; sc_iterator3 *wave_it; sc_iterator5 *it5 = sc_iterator5_f_a_a_a_f_new(graph, sc_type_arc_pos_const_perm, sc_type_node | sc_type_const, sc_type_arc_pos_const_perm, sc_graph_keynode_rrel_vertex); if (sc_helper_check_arc(sc_graph_keynode_graph, graph, sc_type_arc_pos_const_perm) == SC_FALSE) return SC_RESULT_ERROR_INVALID_PARAMS; while (sc_iterator5_next(it5) == SC_TRUE) { if (SC_ADDR_IS_EQUAL(beg_vertex, it5->results[2]) == SC_FALSE) { not_checked_vertices = sc_addr_list_append(not_checked_vertices); not_checked_vertices->value = it5->results[2]; } } cur_wave = sc_memory_node_new(sc_type_node | sc_type_const); sc_memory_arc_new(sc_type_arc_pos_const_perm, cur_wave, beg_vertex); wave_list_head = sc_addr_list_append(wave_list_head); wave_list_head->value = cur_wave; do { cur_wave = create_wave(cur_wave, graph, ¬_checked_vertices); wave_it = sc_iterator3_f_a_a_new(cur_wave, sc_type_arc_pos_const_perm, sc_type_node | sc_type_const); if (sc_iterator3_next(wave_it) == SC_FALSE) //TODO clear memory return SC_RESULT_ERROR; wave_list_head = sc_addr_list_append(wave_list_head); wave_list_head->value = cur_wave; } while(sc_helper_check_arc(cur_wave, end_vertex, sc_type_arc_pos_const_perm) == SC_FALSE); path_head = sc_addr_list_append(path_head); path_head->value = end_vertex; curr_vertex = end_vertex; wave_list_head = sc_addr_list_next(wave_list_head); do { curr_vertex = find_adjacent_from_wave(graph, wave_list_head->value, curr_vertex); path_head = sc_addr_list_append(path_head); path_head->value = curr_vertex; } while((wave_list_head = sc_addr_list_next(wave_list_head)) != nullptr); *path = path_head; return SC_RESULT_OK; }
void iTranslator::generateFormatInfo(sc_addr addr, const String &ext) { String fmtStr = "format_" + ext; tStringAddrMap::iterator it = mSysIdtfAddrs.find(fmtStr); sc_addr fmt_addr; if (it != mSysIdtfAddrs.end()) { fmt_addr = it->second; } else { // try to find by system identifier if (sc_helper_find_element_by_system_identifier(mContext, fmtStr.c_str(), (sc_uint32)fmtStr.size(), &fmt_addr) != SC_RESULT_OK) { fmt_addr = sc_memory_node_new(mContext, sc_type_node_class | sc_type_const); sc_helper_set_system_identifier(mContext, fmt_addr, fmtStr.c_str(), (sc_uint32)fmtStr.size()); mSysIdtfAddrs[fmtStr] = fmt_addr; } } // try to find format relation sc_addr nrel_format_addr; String nrel_format_str = NREL_FORMAT_STR; it = mSysIdtfAddrs.find(nrel_format_str); if (it != mSysIdtfAddrs.end()) { nrel_format_addr = it->second; } else { // try to find by system identifier if (sc_helper_find_element_by_system_identifier(mContext, nrel_format_str.c_str(), (sc_uint32)nrel_format_str.size(), &nrel_format_addr) != SC_RESULT_OK) { nrel_format_addr = sc_memory_node_new(mContext, sc_type_node_norole | sc_type_const); sc_helper_set_system_identifier(mContext, nrel_format_addr, nrel_format_str.c_str(), (sc_uint32)nrel_format_str.size()); mSysIdtfAddrs[nrel_format_str] = nrel_format_addr; } } // connect sc-link with format sc_addr arc_addr = sc_memory_arc_new(mContext, sc_type_arc_common | sc_type_const, addr, fmt_addr); sc_memory_arc_new(mContext, sc_type_arc_pos_const_perm, nrel_format_addr, arc_addr); }
sc_result question_search_all_output_arcs(sc_event *event, sc_addr arg) { sc_addr question_node; sc_addr question_argument; sc_addr answer_node; sc_addr value; sc_bool arg_exist = SC_FALSE; sc_iterator3 *it = 0; sc_uint32 i = 0; if (sc_memory_get_arc_end(arg, &question_node) != SC_RESULT_OK) return SC_RESULT_ERROR; // check question type // if (sc_helper_check_arc(question_) == SC_FALSE) // return SC_RESULT_ERROR_INVALID_PARAMS; // get question argument it = sc_iterator3_f_a_a_new(question_node, sc_type_arc_pos_const_perm, 0); while (sc_iterator3_next(it)) { question_argument = sc_iterator3_value(it, 2); arg_exist = SC_TRUE; } sc_iterator3_free(it); // make answer answer_node = sc_memory_node_new(sc_type_node | sc_type_const); if (arg_exist == SC_TRUE) { // iterate all output arcs and append them into result it = sc_iterator3_f_a_a_new(question_argument, 0, 0); while (sc_iterator3_next(it)) { for (i = 0; i < 3; ++i) { value = sc_iterator3_value(it, i); sc_memory_arc_new(sc_type_arc_pos_const_perm, answer_node, value); } } sc_iterator3_free(it); } // connect question with answer value = sc_memory_arc_new(sc_type_arc_common | sc_type_const, question_node, answer_node); sc_memory_arc_new(sc_type_arc_pos_const_perm, q_keynode_question_nrel_answer, value); // change question state sc_memory_element_free(arg); sc_memory_arc_new(sc_type_arc_pos_const_perm, q_keynode_question_finished, question_node); return SC_RESULT_OK; }
void test7() { sc_uint32 i, j; sc_addr addr, addr1, addr2; sc_addr new_addr; sc_event *event1, *event2, *event3, *event4; printf("Segments count: %d\n", sc_storage_get_segments_count()); print_storage_statistics(); timer = g_timer_new(); g_timer_reset(timer); g_timer_start(timer); addr = sc_memory_node_new(0); addr1 = sc_memory_node_new(0); printf("Register events\n"); event1 = sc_event_new(addr, SC_EVENT_ADD_OUTPUT_ARC, 0, &event_callback, 0); event2 = sc_event_new(addr1, SC_EVENT_ADD_INPUT_ARC, 1, &event_callback, 0); event3 = sc_event_new(addr, SC_EVENT_REMOVE_OUTPUT_ARC, 2, &event_callback, 0); event4 = sc_event_new(addr1, SC_EVENT_REMOVE_INPUT_ARC, 3, &event_callback, 0); addr2 = sc_memory_arc_new(0, addr, addr1); sc_memory_element_free(addr2); printf("Unregister events\n"); sc_event_destroy(event1); sc_event_destroy(event2); sc_event_destroy(event3); sc_event_destroy(event4); addr2 = sc_memory_arc_new(0, addr, addr1); sc_memory_element_free(addr2); g_timer_stop(timer); printf("Segments count: %d\n", sc_storage_get_segments_count()); print_storage_statistics(); g_timer_destroy(timer); }
sc_result sc_common_resolve_keynode(sc_memory_context const * ctx, char const * sys_idtf, sc_addr * keynode) { if (sc_helper_resolve_system_identifier(ctx, sys_idtf, keynode) == SC_FALSE) { *keynode = sc_memory_node_new(ctx, 0); if (sc_helper_set_system_identifier(ctx, *keynode, sys_idtf, (sc_uint32)strlen(sys_idtf)) != SC_RESULT_OK) return SC_RESULT_ERROR; g_message("Created element with system identifier: %s", sys_idtf); } return SC_RESULT_OK; }
// simple test on node creation gpointer create_node_thread(gpointer data) { sc_memory_context *ctx = sc_memory_context_new(sc_access_lvl_make(8, 8)); int count = GPOINTER_TO_INT(data); int result = count; for (int i = 0; i < count; ++i) { sc_addr addr = sc_memory_node_new(ctx, 0); if (SC_ADDR_IS_EMPTY(addr)) result = i + 1; } sc_memory_context_free(ctx); return GINT_TO_POINTER(result); }
scp_result genEl(scp_operand *param) { if (param->param_type != SCP_ASSIGN) { return print_error("genEl", "Parameter must have ASSIGN modifier"); } if ((param->element_type & scp_type_node) != scp_type_node) { return print_error("genEl", "Only node element can be generated. Use genElStr3 for arcs"); } param->addr = sc_memory_node_new(param->element_type); if (SC_FALSE == sc_memory_is_element(param->addr)) { return print_error("genEl", "Element cannot be generated"); } return SCP_RESULT_TRUE; }
sc_result sc_graph_find_conn_comp(sc_addr graph, sc_addr_list **conn_comp_set) { sc_addr curr_vertex, graph_keynode; sc_addr_list *not_checked_vertices = nullptr; sc_iterator5 *it5 = sc_iterator5_f_a_a_a_f_new(graph, sc_type_arc_pos_const_perm, sc_type_node | sc_type_const, sc_type_arc_pos_const_perm, sc_graph_keynode_rrel_vertex); if (sc_helper_check_arc(sc_graph_keynode_graph, graph, sc_type_arc_pos_const_perm) == SC_FALSE) return SC_RESULT_ERROR_INVALID_PARAMS; if (sc_helper_check_arc(sc_graph_keynode_not_oriented_graph, graph, sc_type_arc_pos_const_perm) == SC_TRUE) graph_keynode = sc_graph_keynode_not_oriented_graph; else if (sc_helper_check_arc(sc_graph_keynode_oriented_graph, graph, sc_type_arc_pos_const_perm) == SC_TRUE) graph_keynode = sc_graph_keynode_oriented_graph; else return SC_RESULT_ERROR_INVALID_PARAMS; *conn_comp_set = nullptr; while(sc_iterator5_next(it5) == SC_TRUE) { curr_vertex = it5->results[2]; not_checked_vertices = sc_addr_list_append(not_checked_vertices); not_checked_vertices->value = curr_vertex; } sc_iterator5_free(it5); while (not_checked_vertices != nullptr) { sc_addr curr_conn_comp = sc_memory_node_new(sc_type_node | sc_type_const); sc_memory_arc_new(sc_type_arc_pos_const_perm, sc_graph_keynode_graph, curr_conn_comp); sc_memory_arc_new(sc_type_arc_pos_const_perm, graph_keynode, curr_conn_comp); curr_vertex = not_checked_vertices->value; deep_first_search_for_find_conn_comp(curr_vertex, ¬_checked_vertices, &curr_conn_comp, graph); *conn_comp_set = sc_addr_list_append(*conn_comp_set); (*conn_comp_set)->value = curr_conn_comp; } return SC_RESULT_OK; }
scp_result check_node_parameter_1(sc_memory_context *context, const sc_char *operator_name, scp_operand *param1) { if (SCP_ASSIGN == param1->param_type) { param1->addr = sc_memory_node_new(context, scp_type_node); } else { if (SC_FALSE == sc_memory_is_element(context, param1->addr)) { return print_error(operator_name, "Parameter 1 has not value"); } if (check_type(context, param1->addr, scp_type_node) == SCP_RESULT_FALSE) { return print_error(operator_name, "Parameter 1 isn't node"); } } return SCP_RESULT_TRUE; }
sc_addr create_wave(sc_addr cur_wave, sc_addr graph, sc_addr_list **not_checked_vertices) { sc_addr_list *cur_item; sc_addr new_wave; sc_iterator3 *it3 = sc_iterator3_f_a_a_new(cur_wave, sc_type_arc_pos_const_perm, sc_type_node | sc_type_const); sc_type arc_type; new_wave = sc_memory_node_new(sc_type_node | sc_type_const); if (sc_helper_check_arc(sc_graph_keynode_not_oriented_graph, graph, sc_type_arc_pos_const_perm) == SC_TRUE) arc_type = sc_type_edge_common; else if(sc_helper_check_arc(sc_graph_keynode_oriented_graph, graph, sc_type_arc_pos_const_perm) == SC_TRUE) arc_type = sc_type_arc_common; while (sc_iterator3_next(it3) == SC_TRUE) { sc_addr cur_vertex = it3->results[2]; sc_iterator5 *it5 = sc_iterator5_f_a_a_a_f_new(cur_vertex, arc_type | sc_type_const, sc_type_node | sc_type_const, sc_type_arc_pos_const_perm, graph); while (sc_iterator5_next(it5) == SC_TRUE) { cur_item = *not_checked_vertices; do { if (SC_ADDR_IS_EQUAL(cur_item->value, it5->results[2]) == SC_TRUE) { if (cur_item == *not_checked_vertices) *not_checked_vertices = sc_addr_list_remove(*not_checked_vertices); else cur_item = sc_addr_list_remove(cur_item); sc_memory_arc_new(sc_type_arc_pos_const_perm, new_wave, it5->results[2]); break; } } while((cur_item = sc_addr_list_next(cur_item)) != nullptr); } } return new_wave; }
void test_save() { // create nodes s_default_ctx = sc_memory_initialize(¶ms); sc_memory_context *ctx = sc_memory_context_new(sc_access_lvl_make(8, 8)); int const count = 1000000; for (int i = 0; i < count; ++i) { g_assert(SC_ADDR_IS_NOT_EMPTY(sc_memory_node_new(ctx, 0))); } sc_memory_context_free(ctx); GThread * thread = g_thread_try_new(0, start_save_threaded, 0, 0); test_creation(create_arc_thread, g_task_count, g_thread_count); g_thread_join(thread); sc_memory_shutdown(SC_FALSE); }
void test3() { sc_addr node[10], arc[10][10]; sc_uint32 i, j; printf("Create 10 nodes and 100 arcs, that connect nodes each other\n"); for (i = 0; i < 10; i++) node[i] = sc_memory_node_new(sc_type_const); for (i = 0; i < 10; i++) for (j = 0; j < 10; j++) arc[i][j] = sc_memory_arc_new(0, node[i], node[j]); printf("Segments count: %d\n", sc_storage_get_segments_count()); print_storage_statistics(); printf("Delete 5 nodes\n"); for (i = 0; i < 5; i++) sc_memory_element_free(node[i]); printf("Segments count: %d\n", sc_storage_get_segments_count()); print_storage_statistics(); }
bool GwfTranslator::processString(const String &data) { tinyxml2::XMLDocument doc; tinyxml2::XMLError error = doc.Parse(data.c_str()); if (error != tinyxml2::XML_SUCCESS) { THROW_EXCEPT(Exception::ERR_PARSE, doc.GetErrorStr2(), mParams.fileName, -1); } tinyxml2::XMLElement *root = doc.FirstChildElement("GWF"); if (!root) { THROW_EXCEPT(Exception::ERR_PARSE, "Can't find root element", mParams.fileName, -1); } root = root->FirstChildElement("staticSector"); if (!root) { THROW_EXCEPT(Exception::ERR_PARSE, "Cna't find static sector", mParams.fileName, -1); } // collect elements std::vector<tinyxml2::XMLElement*> nodes; std::vector<tinyxml2::XMLElement*> edges; std::vector<tinyxml2::XMLElement*> buses; std::vector<tinyxml2::XMLElement*> all; static std::string s_arc = "arc"; static std::string s_pair = "pair"; static std::string s_bus = "bus"; tinyxml2::XMLElement *el = root->FirstChildElement(); while (el) { all.push_back(el); if (el->Name() == s_arc || el->Name() == s_pair) edges.push_back(el); else if (el->Name() == s_bus) buses.push_back(el); else nodes.push_back(el); el = el->NextSiblingElement(); } static std::string s_node = "node"; static std::string s_contour = "contour"; tStringAddrMap id_map; tStringAddrMap::iterator itId; // create all nodes std::vector<tinyxml2::XMLElement*>::iterator it, itEnd = nodes.end(); for (it = nodes.begin(); it != itEnd; ++it) { el = *it; String idtf = el->Attribute("idtf"); String id = el->Attribute("id"); sc_addr addr; itId = id_map.find(id); if (itId != id_map.end()) continue; if (idtf.size() > 0) { if (getScAddr(idtf, addr)) { id_map[id] = addr; continue; // skip elements that already exists } } if (el->Name() == s_contour) { addr = sc_memory_node_new(sc_type_const | sc_type_node_struct); appendScAddr(addr, idtf); } else { tinyxml2::XMLElement *content = el->FirstChildElement("content"); if (!content) { THROW_EXCEPT(Exception::ERR_PARSE, "There are no child content for node with id=" + id, mParams.fileName, -1); } if (content->IntAttribute("type") == 0) { addr = sc_memory_node_new(convertType(el->Attribute("type"))); appendScAddr(addr, idtf); } else { // need to create link addr = sc_memory_link_new(); // setup content String data = content->GetText(); if (content->IntAttribute("type") == 4) data = base64_decode(data); sc_stream *stream = sc_stream_memory_new(data.c_str(), data.size(), SC_STREAM_READ, SC_FALSE); sc_memory_set_link_content(addr, stream); sc_stream_free(stream); if (mParams.autoFormatInfo) { String ext = StringUtil::getFileExtension(content->Attribute("file_name")); if (!ext.empty()) generateFormatInfo(addr, ext); } } } if (!idtf.empty()) sc_helper_set_system_identifier(addr, idtf.c_str(), idtf.size()); id_map[id] = addr; } // process buses itEnd = buses.end(); for (it = buses.begin(); it != itEnd; ++it) { el = *it; tStringAddrMap::iterator itOwner = id_map.find(el->Attribute("owner")); if (itOwner == id_map.end()) continue; id_map[el->Attribute("id")] = itOwner->second; } // now create edges bool created = true; while (created) { created = false; itEnd = edges.end(); for (it = edges.begin(); it != itEnd; ++it) { el = *it; sc_addr addr; String id = el->Attribute("id"); String idtf = el->Attribute("idtf"); if (id_map.find(id) != id_map.end()) continue; if (getScAddr(idtf, addr)) continue; // get begin and end elements tStringAddrMap::iterator itB = id_map.find(el->Attribute("id_b")); if (itB == id_map.end()) continue; tStringAddrMap::iterator itE = id_map.find(el->Attribute("id_e")); if (itE == id_map.end()) continue; // create arc created = true; addr = sc_memory_arc_new(convertType(el->Attribute("type")), itB->second, itE->second); appendScAddr(addr, idtf); id_map[id] = addr; if (!idtf.empty()) sc_helper_set_system_identifier(addr, idtf.c_str(), idtf.size()); } } // now append elemnts into contours itEnd = all.end(); for (it = all.begin(); it != itEnd; ++it) { el = *it; tStringAddrMap::iterator itSelf = id_map.find(el->Attribute("id")); if (itSelf == id_map.end()) continue; tStringAddrMap::iterator itP = id_map.find(el->Attribute("parent")); if (itP == id_map.end()) continue; sc_memory_arc_new(sc_type_arc_pos_const_perm, itP->second, itSelf->second); } return false; }
sc_addr create_answer_node() { sc_addr res = sc_memory_node_new(sc_type_const); SYSTEM_ELEMENT(res); return res; }
sc_addr SCsTranslator::createScAddr(sElement *el) { sc_addr addr; SC_ADDR_MAKE_EMPTY(addr); if (el->type & sc_type_node) addr = sc_memory_node_new(mContext, el->type); else if (el->type & sc_type_link) { addr = sc_memory_link_new(mContext); // setup link content if (el->link_is_file) { String file_path; if (_getAbsFilePath(el->file_path, file_path)) { sc_stream *stream = sc_stream_file_new(file_path.c_str(), SC_STREAM_FLAG_READ); if (stream) { sc_memory_set_link_content(mContext, addr, stream); sc_stream_free(stream); } else { THROW_EXCEPT(Exception::ERR_FILE_NOT_FOUND, "Can't open file " + el->file_path, mParams.fileName, -1); } } else { THROW_EXCEPT(Exception::ERR_INVALID_PARAMS, "Unsupported link type " + el->file_path, mParams.fileName, -1); } } else { sc_stream *stream = sc_stream_memory_new(el->link_data.data.data(), (sc_uint)el->link_data.data.size(), SC_STREAM_FLAG_READ, SC_FALSE); sc_memory_set_link_content(mContext, addr, stream); sc_stream_free(stream); } // generate format information if (mParams.autoFormatInfo) { if (el->link_is_file) { size_t n = el->file_path.find_last_of("."); if (n != String::npos) generateFormatInfo(addr, el->file_path.substr(n + 1)); } } } else { assert(el->arc_src && el->arc_trg); if (SC_ADDR_IS_EMPTY(el->arc_src->addr) || SC_ADDR_IS_EMPTY(el->arc_trg->addr)) return addr; addr = sc_memory_arc_new(mContext, el->type, el->arc_src->addr, el->arc_trg->addr); } el->addr = addr; return addr; }
ScAddr ScMemoryContext::createNode(sc_type type) { check_expr(isValid()); return ScAddr(sc_memory_node_new(mContext, type)); }
extern "C" scp_result sys_search(scp_operand *param1, scp_operand *param2, scp_operand_pair *parameters, sc_uint32 param_count, scp_operand *param4, scp_bool full_only) { sc_type_result params; sc_addr curr_result_node, addr1, addr2, arc; sc_type_result_vector result; sc_type_result::iterator it; sc_uint i; scp_result res = SCP_RESULT_FALSE; GHashTable *table; for (i = 0; i < param_count; i++) { params.insert(sc_addr_pair(parameters[i].operand1->addr, parameters[i].operand2->addr)); } if (SCP_TRUE == full_only) { if (SC_RESULT_OK != system_sys_search_only_full(param1->addr, params, &result)) { return SCP_RESULT_ERROR; } } else { if (SC_RESULT_OK != system_sys_search(param1->addr, params, &result)) { return SCP_RESULT_ERROR; } } if (result.size() > 0) { res = SCP_RESULT_TRUE; } else { free_result_vector(&result); return SCP_RESULT_FALSE; } if (param4 != nullptr) { table = g_hash_table_new(NULL, NULL); } for (i = 0; i < result.size(); i++) { curr_result_node = sc_memory_node_new(sc_type_const); for (it = result[i]->begin() ; it != result[i]->end(); it++) { addr1 = (*it).first; addr2 = (*it).second; arc = sc_memory_arc_new(sc_type_arc_common | sc_type_const, addr1, addr2); sc_memory_arc_new(sc_type_arc_pos_const_perm, curr_result_node, arc); if (param4 != nullptr) { if (FALSE == g_hash_table_contains(table, MAKE_SC_ADDR_HASH(addr2))) { sc_memory_arc_new(sc_type_arc_pos_const_perm, param4->addr, addr2); g_hash_table_add(table, MAKE_SC_ADDR_HASH(addr2)); } } } sc_memory_arc_new(sc_type_arc_pos_const_perm, param2->addr, curr_result_node); } free_result_vector(&result); if (param4 != nullptr) { g_hash_table_destroy(table); } return res; }
void test4() { sc_addr node[10], arc[10][10]; sc_uint32 i, j; sc_iterator3 *it = 0; sc_addr addr1, addr2, addr3; printf("Create 10 nodes and 100 arcs, that connect nodes each other\n"); for (i = 0; i < 10; i++) node[i] = sc_memory_node_new(sc_type_const); for (i = 0; i < 10; i++) for (j = 0; j < 10; j++) arc[i][j] = sc_memory_arc_new(0, node[i], node[j]); print_storage_statistics(); printf("---\nTest iterator3_f_a_a\n"); for (i = 0; i < 10; i++) { it = sc_iterator3_f_a_a_new(node[i], 0, 0); g_assert(it != 0); printf("Node %d:\n", i); while (sc_iterator3_next(it)) { addr1 = sc_iterator3_value(it, 0); addr2 = sc_iterator3_value(it, 1); addr3 = sc_iterator3_value(it, 2); printf("\t%u, %u; %u, %u; %u, %u\n", addr1.seg, addr1.offset, addr2.seg, addr2.offset, addr3.seg, addr3.offset); } sc_iterator3_free(it); } printf("---\nTest iterator3_a_a_f\n"); for (i = 0; i < 10; i++) { it = sc_iterator3_a_a_f_new(0, 0, node[i]); g_assert(it != 0); printf("Node %d:\n", i); while (sc_iterator3_next(it)) { addr1 = sc_iterator3_value(it, 0); addr2 = sc_iterator3_value(it, 1); addr3 = sc_iterator3_value(it, 2); printf("\t%u, %u; %u, %u; %u, %u\n", addr1.seg, addr1.offset, addr2.seg, addr2.offset, addr3.seg, addr3.offset); } sc_iterator3_free(it); } printf("---\nTest iterator3_f_a_f\n"); for (i = 0; i < 10; i++) { it = sc_iterator3_f_a_f_new(node[i], 0, node[9 - i]); g_assert(it != 0); printf("Node %d:\n", i); while (sc_iterator3_next(it)) { addr1 = sc_iterator3_value(it, 0); addr2 = sc_iterator3_value(it, 1); addr3 = sc_iterator3_value(it, 2); printf("\t%u, %u; %u, %u; %u, %u\n", addr1.seg, addr1.offset, addr2.seg, addr2.offset, addr3.seg, addr3.offset); } sc_iterator3_free(it); } // iterator allocations printf("---\nTest iterator allocation(dealocation) speed...\n"); timer = g_timer_new(); g_timer_reset(timer); g_timer_start(timer); for (i = 0; i < iterator_alloc_count; i++) { it = sc_iterator3_f_a_a_new(node[0], 0, 0); sc_iterator3_free(it); } g_timer_stop(timer); printf("Allocated iterators: %d\n", iterator_alloc_count); printf("Allocation/deallocation per second: %f\n", iterator_alloc_count / g_timer_elapsed(timer, 0)); g_timer_destroy(timer); }
void test8() { sc_addr node[10], arc[10][10], addr_arc; sc_uint32 i, j; sc_iterator3 *it = 0; printf("Segments count: %d\n", sc_storage_get_segments_count()); print_storage_statistics(); timer = g_timer_new(); printf("Create 10 nodes and 100 arcs, that connect nodes each other\n"); for (i = 0; i < 10; i++) node[i] = sc_memory_node_new(sc_type_node); for (i = 0; i < 10; i++) for (j = 0; j < 10; j++) arc[i][j] = sc_memory_arc_new(0, node[i], node[j]); printf("Segments count: %d\n", sc_storage_get_segments_count()); print_storage_statistics(); printf("Delete 5 nodes\n"); for (i = 0; i < 5; i++) sc_memory_element_free(node[i]); // iterate element for check it = sc_iterator3_f_a_a_new(node[9], 0, 0); while (sc_iterator3_next(it) == SC_TRUE) { addr_arc = sc_iterator3_value(it, 1); printf("Arc: %d, %d\n", addr_arc.seg, addr_arc.offset); } sc_iterator3_free(it); printf("Segments count: %d\n", sc_storage_get_segments_count()); print_storage_statistics(); g_timer_stop(timer); printf("Collect and delete garbage...\n"); g_timer_reset(timer); g_timer_start(timer); sc_storage_update_segments(); g_timer_stop(timer); // iterate element for check it = sc_iterator3_f_a_a_new(node[9], 0, 0); while (sc_iterator3_next(it) == SC_TRUE) { addr_arc = sc_iterator3_value(it, 1); printf("Arc: %d, %d\n", addr_arc.seg, addr_arc.offset); } sc_iterator3_free(it); printf("Elapsed time: %f\n", g_timer_elapsed(timer, 0)); printf("Segments count: %d\n", sc_storage_get_segments_count()); print_storage_statistics(); g_timer_destroy(timer); }
void test1() { sc_uint idx = 0; sc_addr id, id2; sc_uint32 count = 0; printf("Element size: %d bytes\n", sizeof(sc_element)); printf("Segment size: %d elements\n", SEGMENT_SIZE); timer = g_timer_new(); print_storage_statistics(); printf("--- Node creation ---\n"); g_timer_start(timer); for (idx = 0; idx < nodes_append_count; idx++) { id = sc_memory_node_new(sc_type_const); //g_printf("uri: %d\t%d\n", uri.seg, uri.id); } g_timer_stop(timer); printf("Time: %f s\n", g_timer_elapsed(timer, 0)); printf("Nodes per second: %f\n", (float)nodes_append_count / g_timer_elapsed(timer, 0)); printf("Segments count: %d\n", sc_storage_get_segments_count()); print_storage_statistics(); g_timer_reset(timer); printf("--- Node segmentation ---\n"); count = 0; printf("Prepare test...\n"); for (idx = 1; idx < nodes_remove_count + 1; idx++) { if (idx % 10 < 5) { id.seg = idx / SEGMENT_SIZE; id.offset = idx % SEGMENT_SIZE; /*do { id = get_random_addr(sc_type_node); } while(!sc_storage_is_element(id) && is_sc_addr_in_segment_node_vector(id));*/ if (sc_memory_is_element(id)) segment_node_del.push_back(id); } } printf("Run test...\n"); g_timer_start(timer); sc_uint32 n = segment_node_del.size(); for (sc_uint32 i = 0; i < n; ++i) sc_memory_element_free(segment_node_del[i]); n = nodes_remove_count - n; for (sc_uint32 i = 0; i < n; i++) sc_memory_node_new(0); g_timer_stop(timer); segment_node_del.clear(); printf("Time: %f s\n", g_timer_elapsed(timer, 0)); printf("Elements per second: %f\n", (float)nodes_remove_count / g_timer_elapsed(timer, 0)); printf("Segments count: %d\n", sc_storage_get_segments_count()); printf("Element free calls: %u\n", segment_node_del.size()); print_storage_statistics(); g_timer_reset(timer); printf("--- Arcs creation ---\n"); count = 0; printf("Prepare...\n"); for (idx = 0; idx < arcs_append_count; idx++) { do { id = get_random_addr(0); }while (!sc_memory_is_element(id)); do { id2 = get_random_addr(0); }while (!sc_memory_is_element(id2)); arc_creation_vector.push_back(id); arc_creation_vector.push_back(id2); } printf("Run...\n"); g_timer_start(timer); n = arc_creation_vector.size() / 2; for (sc_uint32 i = 0; i < n; ++i) { sc_memory_arc_new(sc_type_arc_common, arc_creation_vector[i], arc_creation_vector[i + n]); } g_timer_stop(timer); printf("Timer: %fs\n", g_timer_elapsed(timer, 0)); printf("Arcs per second: %f\n", (float)n / g_timer_elapsed(timer, 0)); printf("Segments count: %d\n", sc_storage_get_segments_count()); print_storage_statistics(); g_timer_destroy(timer); }