Esempio n. 1
0
int main()
{
	map *m;
	string *k;
	string *v;
	string *q;
	map_iterator *n;
	pair *t;

	m = map_init(stcmp);
	q = string_init_cstring("");
	k = string_init();
	string_read_line(k);

	while(string_cmp(k, q))
	{
		v = string_init();
		string_read_line(v);
		map_add(m, k, v);

		k = string_init();
		string_read_line(k);
	}

	k = string_free(k);

	/* Iterate through map. */
	for(n = map_begin(m); n; n = map_next(n))
	{
		t = n->data;
		string_print(t->first);
		printf(" => ");
		string_println(t->second);
	}

	/* Free map. */
	for(n = map_begin(m); n; n = map_next(n))
	{
		t = n->data;
		string_free(t->first);
		string_free(t->second);
	}

	string_free(q);
	m = map_free(m);

	return 0;
}
Esempio n. 2
0
void map_init_copy(map_t* pt_mapdest, const map_t* cpt_mapsrc)
{
    assert(pt_mapdest != NULL && cpt_mapsrc != NULL);
    assert(
        pt_mapdest->_t_pair._t_firsttypesize == 
            cpt_mapsrc->_t_pair._t_firsttypesize &&
        pt_mapdest->_t_pair._t_secondtypesize ==
            cpt_mapsrc->_t_pair._t_secondtypesize);
    assert(
        strncmp(
            pt_mapdest->_t_pair._sz_firsttypename,
            cpt_mapsrc->_t_pair._sz_firsttypename,
            _ELEM_TYPE_NAME_SIZE) == 0 &&
        strncmp(
            pt_mapdest->_t_pair._sz_secondtypename,
            cpt_mapsrc->_t_pair._sz_secondtypename,
            _ELEM_TYPE_NAME_SIZE) == 0);

    /* initialize dest map with src map attribute */
    map_init(pt_mapdest);
    /* insert all element from src to dest */
    if(!map_empty(cpt_mapsrc))
    {
        map_insert_range(pt_mapdest, map_begin(cpt_mapsrc), map_end(cpt_mapsrc));
    }
}
Esempio n. 3
0
void attribute_destroy_recursive( container *attributes )
{
    iterator	it = map_begin(attributes);

    for (; it.valid; it=map_next(it))
	{
	    destroy(pair(map_val(it)).second.C);
	    attribute_destroy_recursive( pair(map_val(it)).first.C );
	}

    destroy(attributes);
}
Esempio n. 4
0
File: map.c Progetto: oopos/windsoul
static void *
_findfirst(struct map *m, struct map_op * op)
{
	struct node *v = map_begin(m);
	op->value = v;
	if (v == NULL) {
		op->key.p = NULL;
		return NULL;
	}
	else {
		op->key.p = v->key;
	}
	return v->value;
}
Esempio n. 5
0
void map_assign(map_t* pt_mapdest, const map_t* cpt_mapsrc)
{
    assert(pt_mapdest != NULL && cpt_mapsrc != NULL);
    assert(_same_map_pair_type(&pt_mapdest->_t_pair, &cpt_mapsrc->_t_pair));

    /* destroy dest map */
    map_destroy(pt_mapdest);
    /* initialize dest map with src map attribute */
    map_init(pt_mapdest);
    /* insert all element from src to dest */
    if(!map_empty(cpt_mapsrc))
    {
        map_insert_range(pt_mapdest, map_begin(cpt_mapsrc), map_end(cpt_mapsrc));
    }
}
Esempio n. 6
0
/**
 * Assign map container.
 */
void map_assign(map_t* pmap_dest, const map_t* cpmap_src)
{
    assert(pmap_dest != NULL);
    assert(cpmap_src != NULL);
    assert(_pair_is_inited(&pmap_dest->_pair_temp));
    assert(_pair_is_inited(&cpmap_src->_pair_temp));
    assert(_map_same_pair_type_ex(&pmap_dest->_pair_temp, &cpmap_src->_pair_temp));

    /* clear */
    map_clear(pmap_dest);
    /* insert all element from src to dest */
    if(!map_empty(cpmap_src))
    {
        map_insert_range(pmap_dest, map_begin(cpmap_src), map_end(cpmap_src));
    }
}
Esempio n. 7
0
inline void map_print( container *C, value a )
{
    int		i=0;
    iterator	it = map_begin(a.C);

    printf("(");
    for (; it.valid; it=map_next(it))
    {
        if (i==0) i++;
        else printf(" ");

        printv(((map_container_priv*)C->priv)->Key, map_key(it));
        printf(":");
        printv(((map_container_priv*)C->priv)->Data, map_val(it));
    }
    printf(")");
}
Esempio n. 8
0
static void free_prices(map_t *contracts) {
	map_iter_t *iter = map_iter_create();

	for (map_begin(iter, contracts); map_iter_valid(iter, contracts); map_iter_next(iter)) {
		void *contract = (void *)map_iter_key(iter);
		deq_t *prices = map_iter_value(iter);
		int i, size = deq_size(prices);

		FREE(contract);
		for (i = 0; i < size; ++i) {
			float *price = deq_at(prices, i);

			FREE(price);
		}
		deq_destroy(prices);
	}
	map_iter_destroy(iter);
}
Esempio n. 9
0
/**
 * Initialize map container with map.
 */
void map_init_copy(map_t* pmap_dest, const map_t* cpmap_src)
{
    assert(pmap_dest != NULL);
    assert(cpmap_src != NULL);
    assert(_pair_is_created(&pmap_dest->_pair_temp));
    assert(_pair_is_inited(&cpmap_src->_pair_temp));

    /* initialize dest map with src map attribute */
    map_init(pmap_dest);
    pmap_dest->_bfun_keycompare = cpmap_src->_bfun_keycompare;
    pmap_dest->_bfun_valuecompare = cpmap_src->_bfun_valuecompare;
    pmap_dest->_pair_temp._bfun_mapkeycompare = cpmap_src->_pair_temp._bfun_mapkeycompare;
    pmap_dest->_pair_temp._bfun_mapvaluecompare = cpmap_src->_pair_temp._bfun_mapvaluecompare;

    assert(_map_same_pair_type_ex(&pmap_dest->_pair_temp, &cpmap_src->_pair_temp));
    /* insert all element from src to dest */
    if(!map_empty(cpmap_src))
    {
        map_insert_range(pmap_dest, map_begin(cpmap_src), map_end(cpmap_src));
    }
}
Esempio n. 10
0
void attribute_count_print( container *attributes, int attrib_count, int indent )
{
    iterator		it = map_begin(attributes);

    for (; it.valid; it=map_next(it))
	{
	    int		i;

	    for (i=0; i<indent; i++) printf(" ");
	    printf("%s\n", (char*)map_key(it).ptr);
	    /*
	    for (i=0; i<attrib_count; i++)
		{
		    if (i>0) printf(", ");
		    printf("%i", ((int*)pair(map_val(it)).second.ptr)[i]);
		}
	    printf(")\n");
	    */

	    attribute_count_print(pair(map_val(it)).first.C, attrib_count, indent+2);
	}
}
Esempio n. 11
0
int _attribute_count_hits_(container *count, int filter, int group_filter_id)
{
    if (count==NULL) return 0;

    int		i;
    int		len = group_filter_id+1;
    int		alle = 0;

    for (i=0; i<len; i++) alle+= 1<<i;

    int		inverse = alle - filter;
    //printf("filter:");
    //for (i=0; i<len; i++) printf("%c", (inverse & (1<<i) ? '1':'0'));
    //printf("\n");

    int		hits = 0;
    int		__total__ = 0;
    iterator	it;

    it = map_begin(count);
    for (; it.valid; it=map_next(it))
	{
	    //printf("       ");
	    //for (i=0; i<len; i++) printf("%c", ((alle - map_key(it).i) & (1<<i) ? '1':'0'));

	    __total__++;
	    if (((alle - map_key(it).i) & inverse) == 0)
		{
		    hits+= map_val(it).i;
		    //printf("  <count>\n");
		}
	    //else printf("  <----->\n");
	}
    //printf("       match:%i/%i\n", hits, __total__);

    return hits;
}
Esempio n. 12
0
struct _attr_ret_ _attribute_add_children_(container *attributes, container *attr_query, container *hide, container *A, int container_id)
{
    int		i, j;
    container	*list_items = vector_container( ptr_container() );
    iterator	it_m1 = map_begin(attributes);
    int		has_selected_child = 0;

    for (; it_m1.valid; it_m1=map_next(it_m1))
	{
	    vector_pushback(attr_query, (char*)map_key(it_m1).ptr);

	    int		is_hidden = 0;
	    for (i=0; i<vector_size(hide) && !is_hidden; i++)
		{
		    container	*hide_elem = vector_get(hide, i).C;

		    for (j=0; j<vector_size(hide_elem); j++)
			{
			    if (strcasecmp(vector_get(attr_query,j).ptr, vector_get(hide_elem,j).ptr)) break;
			}

		    if (j>=vector_size(hide_elem)) is_hidden = 1;
		}

	    if (is_hidden)
		{
		    vector_remove_last(attr_query);
		    continue;
		}

	    struct _attr_tree_	*this_item = _attribute_tree_malloc_();
	    int val = _attribute_is_selected_(A, attr_query, container_id);
	    if (val>=0) this_item->selected = val;

	    if (map_size(pair(map_val(it_m1)).first.ptr) > 0)
		{
		    struct _attr_ret_ ret = _attribute_add_children_(pair(map_val(it_m1)).first.ptr, attr_query, hide, A, container_id);
		    if (ret.selected_descendant)
			{
			    this_item->selected_descendant = 1;
			    has_selected_child = 1;
			}
		    this_item->children = ret.C;
		    this_item->query_param = vector_container( string_container() );
		    for (j=0; j<vector_size(attr_query); j++)
			vector_pushback(this_item->query_param, vector_get(attr_query, j).ptr);
		    //this_item->name = ;
		    this_item->count = pair(map_val(it_m1)).second.ptr;
		}
	    else
		{
		    this_item->query_param = vector_container( string_container() );
		    for (j=0; j<vector_size(attr_query); j++)
			vector_pushback(this_item->query_param, vector_get(attr_query, j).ptr);
		    //this_item->name = ;
		    this_item->count = pair(map_val(it_m1)).second.ptr;
		}

	    vector_remove_last(attr_query);

	    if (this_item->name == NULL && this_item->query_param == NULL && this_item->count == NULL && this_item->children == NULL)
		{
		    free(this_item);
		}
	    else
		{
		    vector_pushback(list_items, this_item);
		    if (this_item->selected >= 0) has_selected_child = 1;
		}
	}

    struct _attr_ret_	ret;
    ret.C = list_items;
    ret.selected_descendant = has_selected_child;
    return ret;
}
Esempio n. 13
0
    assert_true(it_iter._t_containertype == _MAP_CONTAINER);
    assert_true(it_iter._t_iteratortype == _BIDIRECTIONAL_ITERATOR);
}

/*
 * test _map_iterator_get_value
 */
UT_CASE_DEFINATION(_map_iterator_get_value)
void test__map_iterator_get_value__null_corepos(void** state)
{
    map_t* pt_map = create_map(int, int);
    map_iterator_t it_iter;
    int elem = 0;
    map_init_ex(pt_map, NULL);

    it_iter = map_begin(pt_map);

    it_iter._t_pos._t_treepos._pby_corepos = NULL;
    expect_assert_failure(_map_iterator_get_value(it_iter, &elem));

    map_destroy(pt_map);
}

void test__map_iterator_get_value__null_tree(void** state)
{
    map_t* pt_map = create_map(int, int);
    map_iterator_t it_iter;
    int elem = 0;
    map_init_ex(pt_map, NULL);

    it_iter = map_begin(pt_map);