Exemplo n.º 1
0
/*! Deep first search to build a connective component
 * \param curr_vertex
 *          start vertex for the search
 * \param not_checked_vertices
 *          set of not checked vertices
 * \param curr_conn_comp
 *          connective component that is being built by this search
 * \param graph
 *          sc-addr of graph structure to search connective components
 */
void deep_first_search_for_find_conn_comp(sc_addr curr_vertex, sc_addr not_checked_vertices, sc_addr curr_conn_comp, sc_addr graph)
{
    sc_iterator3 *it3 = sc_iterator3_f_a_f_new(not_checked_vertices,
                                             sc_type_arc_pos_const_perm,
                                             curr_vertex);

    if (sc_iterator3_next(it3) == SC_TRUE)
        sc_memory_element_free(it3->results[1]);

    sc_iterator3_free(it3);

    sc_memory_arc_new(sc_type_arc_pos_const_perm, curr_conn_comp, curr_vertex);

    sc_iterator5 *it5 = sc_iterator5_f_a_a_a_f_new(curr_vertex,
                                                   sc_type_edge_common | sc_type_const,
                                                   sc_type_node | sc_type_const,
                                                   sc_type_arc_pos_const_perm,
                                                   graph);

    while(sc_iterator5_next(it5) == SC_TRUE)
    {
        if (sc_helper_check_arc(not_checked_vertices, it5->results[2],
                                sc_type_arc_pos_const_perm) == SC_TRUE)
            deep_first_search_for_find_conn_comp(it5->results[2], not_checked_vertices, curr_conn_comp, graph);
    }
    sc_iterator5_free(it5);

}
Exemplo n.º 2
0
sc_result merge_sc_elements(sc_addr first, sc_addr second)
{
    copy_incident_connectors(first, second);

    return
        sc_memory_element_free(second);
}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
0
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);
}
Exemplo n.º 5
0
void finish_question(sc_addr question)
{
    sc_iterator3 *it = nullptr;
    sc_addr arc;

    it = sc_iterator3_f_a_f_new(keynode_question_initiated, sc_type_arc_pos_const_perm, question);
    while (sc_iterator3_next(it))
        sc_memory_element_free(sc_iterator3_value(it, 1));
    sc_iterator3_free(it);

    arc = sc_memory_arc_new(sc_type_arc_pos_const_perm, keynode_question_finished, question);
    SYSTEM_ELEMENT(arc);
}
Exemplo n.º 6
0
sctpErrorCode sctpCommand::processElementErase(quint32 cmdFlags, quint32 cmdId, QDataStream *params, QIODevice *outDevice)
{
    sc_addr addr;
    Q_UNUSED(cmdFlags);

    Q_ASSERT(params != 0);

    // read sc-addr of sc-element from parameters
    READ_PARAM(addr);

    sctpResultCode resCode = (sc_memory_element_free(addr) == SC_RESULT_OK) ? SCTP_RESULT_OK : SCTP_RESULT_FAIL;
    // send result
    writeResultHeader(SCTP_CMD_CHECK_ELEMENT, cmdId, resCode, 0, outDevice);

    return SCTP_ERROR_NO;
}
Exemplo n.º 7
0
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;
}
scp_result eraseEl(scp_operand *param)
{
    if (param->param_type != SCP_FIXED)
    {
        return print_error("eraseEl", "Parameter must have FIXED modifier");
    }
    if (param->erase != SCP_TRUE)
    {
        return print_error("eraseEl", "Parameter must have ERASE modifier");
    }
    if (SC_FALSE == sc_memory_is_element(param->addr))
    {
        return print_error("eraseEl", "Element has not value");
    }
    sc_memory_element_free(param->addr);
    SC_ADDR_MAKE_EMPTY(param->addr);
    return SCP_RESULT_TRUE;
}
Exemplo n.º 9
0
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();
}
Exemplo n.º 10
0
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);
}
Exemplo n.º 11
0
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);

}
Exemplo n.º 12
0
bool ScMemoryContext::eraseElement(ScAddr const & addr)
{
    check_expr(isValid());
    return sc_memory_element_free(mContext, addr.mRealAddr) == SC_RESULT_OK;
}