Commit d59d63fc authored by jehan's avatar jehan

replace long map by unsigned long long map

parent d5e453b0
......@@ -31,10 +31,10 @@ typedef struct _bctoolbox_iterator_t bctoolbox_iterator_t;
typedef struct _bctoolbox_mmap_long_t bctoolbox_mmap_long_t;
typedef struct _bctoolbox_mmap_ullong_t bctoolbox_mmap_ullong_t;
/*map*/
BCTOOLBOX_PUBLIC bctoolbox_map_t *bctoolbox_mmap_long_new(void);
BCTOOLBOX_PUBLIC void bctoolbox_mmap_long_delete(bctoolbox_map_t *mmap);
BCTOOLBOX_PUBLIC bctoolbox_map_t *bctoolbox_mmap_ullong_new(void);
BCTOOLBOX_PUBLIC void bctoolbox_mmap_ullong_delete(bctoolbox_map_t *mmap);
BCTOOLBOX_PUBLIC void bctoolbox_map_insert(bctoolbox_map_t *map,const bctoolbox_pair_t *pair);
/*same as insert, but also deleting pair*/
BCTOOLBOX_PUBLIC void bctoolbox_map_insert_and_delete(bctoolbox_map_t *map,bctoolbox_pair_t *pair);
......@@ -65,11 +65,11 @@ BCTOOLBOX_PUBLIC bool_t bctoolbox_iterator_equals(const bctoolbox_iterator_t *a
BCTOOLBOX_PUBLIC void bctoolbox_iterator_delete(bctoolbox_iterator_t *it);
/*pair*/
typedef struct _bctoolbox_pair_long_t bctoolbox_pair_long_t; /*inherite from bctoolbox_pair_t*/
BCTOOLBOX_PUBLIC bctoolbox_pair_long_t * bctoolbox_pair_long_new(long key,void *value);
typedef struct _bctoolbox_pair_ullong_t bctoolbox_pair_ullong_t; /*inherite from bctoolbox_pair_t*/
BCTOOLBOX_PUBLIC bctoolbox_pair_ullong_t * bctoolbox_pair_ullong_new(unsigned long long key,void *value);
BCTOOLBOX_PUBLIC void* bctoolbox_pair_get_second(const bctoolbox_pair_t * pair);
BCTOOLBOX_PUBLIC const long bctoolbox_pair_long_get_first(const bctoolbox_pair_long_t * pair);
BCTOOLBOX_PUBLIC const unsigned long long bctoolbox_pair_ullong_get_first(const bctoolbox_pair_ullong_t * pair);
BCTOOLBOX_PUBLIC void bctoolbox_pair_delete(bctoolbox_pair_t * pair);
......
......@@ -22,26 +22,26 @@
#define LOG_DOMAIN "bctoolbox"
typedef std::multimap<long, void*> mmap_long_t;
typedef mmap_long_t::value_type pair_long_t;
typedef std::multimap<unsigned long long, void*> mmap_ullong_t;
typedef mmap_ullong_t::value_type pair_ullong_t;
extern "C" bctoolbox_map_t *bctoolbox_mmap_long_new(void) {
return (bctoolbox_map_t *) new mmap_long_t();
extern "C" bctoolbox_map_t *bctoolbox_mmap_ullong_new(void) {
return (bctoolbox_map_t *) new mmap_ullong_t();
}
extern "C" void bctoolbox_mmap_long_delete(bctoolbox_map_t *mmap) {
delete (mmap_long_t *)mmap;
extern "C" void bctoolbox_mmap_ullong_delete(bctoolbox_map_t *mmap) {
delete (mmap_ullong_t *)mmap;
}
static bctoolbox_iterator_t * bctoolbox_map_insert_base(bctoolbox_map_t *map,const bctoolbox_pair_t *pair,bool_t returns_it) {
mmap_long_t::iterator it;
if (typeid((pair_long_t*)pair) != typeid(pair_long_t*)) {
mmap_ullong_t::iterator it;
if (typeid((pair_ullong_t*)pair) != typeid(pair_ullong_t*)) {
BCTOOLBOX_SLOGE(LOG_DOMAIN) << "Cannot insert pair ["<< pair << "] on map [" << map <<"] , wrong type";
return NULL;
} else {
it = ((mmap_long_t *)map)->insert(*((pair_long_t*)pair));
it = ((mmap_ullong_t *)map)->insert(*((pair_ullong_t*)pair));
}
if (returns_it) {
return (bctoolbox_iterator_t *) new mmap_long_t::iterator(it);
return (bctoolbox_iterator_t *) new mmap_ullong_t::iterator(it);
} else
return NULL;
}
......@@ -62,24 +62,24 @@ extern "C" bctoolbox_iterator_t * bctoolbox_map_insert_and_delete_with_returned_
}
extern "C" bctoolbox_iterator_t *bctoolbox_map_erase(bctoolbox_map_t *map,bctoolbox_iterator_t *it) {
//bctoolbox_iterator_t * next = (bctoolbox_iterator_t *) new mmap_long_t::iterator((*(mmap_long_t::iterator*)it));
//bctoolbox_iterator_t * next = (bctoolbox_iterator_t *) new mmap_ullong_t::iterator((*(mmap_ullong_t::iterator*)it));
//next = bctoolbox_iterator_get_next(next);
((mmap_long_t *)map)->erase((*(mmap_long_t::iterator*)it)++);
((mmap_ullong_t *)map)->erase((*(mmap_ullong_t::iterator*)it)++);
//bctoolbox_iterator_delete(it);
return it;
}
extern "C" bctoolbox_iterator_t *bctoolbox_map_begin(const bctoolbox_map_t *map) {
return (bctoolbox_iterator_t *) new mmap_long_t::iterator(((mmap_long_t *)map)->begin());
return (bctoolbox_iterator_t *) new mmap_ullong_t::iterator(((mmap_ullong_t *)map)->begin());
}
extern "C" bctoolbox_iterator_t * bctoolbox_map_end(const bctoolbox_map_t *map) {
return (bctoolbox_iterator_t *) new mmap_long_t::iterator(((mmap_long_t *)map)->end());
return (bctoolbox_iterator_t *) new mmap_ullong_t::iterator(((mmap_ullong_t *)map)->end());
}
/*iterator*/
extern "C" bctoolbox_pair_t *bctoolbox_iterator_get_pair(const bctoolbox_iterator_t *it) {
return (bctoolbox_pair_t *)&(**((mmap_long_t::iterator*)it));
return (bctoolbox_pair_t *)&(**((mmap_ullong_t::iterator*)it));
}
extern "C" bctoolbox_iterator_t *bctoolbox_iterator_get_next(bctoolbox_iterator_t *it) {
((mmap_long_t::iterator*)it)->operator++();
((mmap_ullong_t::iterator*)it)->operator++();
return it;
}
extern "C" bctoolbox_iterator_t *bctoolbox_iterator_get_next_and_delete(bctoolbox_iterator_t *it) {
......@@ -88,25 +88,25 @@ extern "C" bctoolbox_iterator_t *bctoolbox_iterator_get_next_and_delete(bctoolb
return next;
}
extern "C" bool_t bctoolbox_iterator_equals(const bctoolbox_iterator_t *a,const bctoolbox_iterator_t *b) {
return *(mmap_long_t::iterator*)a == *(mmap_long_t::iterator*)b;
return *(mmap_ullong_t::iterator*)a == *(mmap_ullong_t::iterator*)b;
}
extern "C" void bctoolbox_iterator_delete(bctoolbox_iterator_t *it) {
delete ((mmap_long_t::iterator*)it);
delete ((mmap_ullong_t::iterator*)it);
}
/*pair*/
extern "C" bctoolbox_pair_long_t * bctoolbox_pair_long_new(long key,void *value) {
return (bctoolbox_pair_long_t *) new pair_long_t(key,value);
extern "C" bctoolbox_pair_ullong_t * bctoolbox_pair_ullong_new(unsigned long long key,void *value) {
return (bctoolbox_pair_ullong_t *) new pair_ullong_t(key,value);
}
extern "C" const long bctoolbox_pair_long_get_first(const bctoolbox_pair_long_t * pair) {
return ((pair_long_t*)pair)->first;
extern "C" const unsigned long long bctoolbox_pair_ullong_get_first(const bctoolbox_pair_ullong_t * pair) {
return ((pair_ullong_t*)pair)->first;
}
extern "C" void* bctoolbox_pair_get_second(const bctoolbox_pair_t * pair) {
return ((pair_long_t*)pair)->second;
return ((pair_ullong_t*)pair)->second;
}
extern "C" void bctoolbox_pair_delete(bctoolbox_pair_t * pair) {
delete ((pair_long_t*)pair);
delete ((pair_ullong_t*)pair);
}
extern "C" bctoolbox_iterator_t * bctoolbox_map_find_custom(bctoolbox_map_t *map, bctoolbox_compare_func compare_func, const void *user_data) {
......@@ -126,5 +126,5 @@ extern "C" bctoolbox_iterator_t * bctoolbox_map_find_custom(bctoolbox_map_t *map
}
extern "C" size_t bctoolbox_map_size(const bctoolbox_map_t *map) {
return ((mmap_long_t *)map)->size();
return ((mmap_ullong_t *)map)->size();
}
......@@ -22,14 +22,14 @@
#include "bctoolbox/list.h"
static void multimap_insert(void) {
bctoolbox_map_t *mmap = bctoolbox_mmap_long_new();
bctoolbox_map_t *mmap = bctoolbox_mmap_ullong_new();
bctoolbox_list_t *head = NULL, *ref = NULL;
bctoolbox_iterator_t *it,*end;
long i=0;
int N = 100;
for(i=0;i<N;i++) {
bctoolbox_pair_t* pair = (bctoolbox_pair_t*)bctoolbox_pair_long_new(i, (void*)((long)i));
bctoolbox_pair_t* pair = (bctoolbox_pair_t*)bctoolbox_pair_ullong_new(N-i-1, (void*)((long)N-i-1));
ref = bctoolbox_list_append(ref, (void*)i);
bctoolbox_map_insert(mmap, pair);
bctoolbox_pair_delete(pair);
......@@ -59,18 +59,18 @@ static void multimap_insert(void) {
bctoolbox_iterator_delete(it);
bctoolbox_iterator_delete(end);
bctoolbox_list_free(head);
bctoolbox_mmap_long_delete(mmap);
bctoolbox_mmap_ullong_delete(mmap);
}
static void multimap_erase(void) {
bctoolbox_map_t *mmap = bctoolbox_mmap_long_new();
bctoolbox_map_t *mmap = bctoolbox_mmap_ullong_new();
bctoolbox_iterator_t *it;
bctoolbox_iterator_t *end;
long i=0;
int N = 100;
for(i=0;i<N;i++) {
bctoolbox_map_insert_and_delete(mmap, (bctoolbox_pair_t*)bctoolbox_pair_long_new(i, (void*)((long)i)));
bctoolbox_map_insert_and_delete(mmap, (bctoolbox_pair_t*)bctoolbox_pair_ullong_new(i, (void*)((long)i)));
}
end= bctoolbox_map_end(mmap);
......@@ -88,7 +88,7 @@ static void multimap_erase(void) {
, N/2
,long, "%lu");
bctoolbox_mmap_long_delete(mmap);
bctoolbox_mmap_ullong_delete(mmap);
bctoolbox_iterator_delete(end);
}
......@@ -96,19 +96,19 @@ static int compare_func(const void *a, const void*b) {
return (long)a == (long)b;
}
static void multimap_find_custom(void) {
bctoolbox_map_t *mmap = bctoolbox_mmap_long_new();
bctoolbox_map_t *mmap = bctoolbox_mmap_ullong_new();
long i=0;
int N = 100;
for(i=0;i<N;i++) {
bctoolbox_pair_t* pair = (bctoolbox_pair_t*)bctoolbox_pair_long_new(i, (void*)((long)i));
bctoolbox_pair_t* pair = (bctoolbox_pair_t*)bctoolbox_pair_ullong_new(i, (void*)((long)i));
bctoolbox_map_insert_and_delete(mmap, pair);
}
bctoolbox_iterator_t * it = bctoolbox_map_find_custom(mmap, compare_func, (void*)10l);
BC_ASSERT_EQUAL((long)bctoolbox_pair_get_second(bctoolbox_iterator_get_pair(it))
, 0
,long, "%lu");
bctoolbox_mmap_long_delete(mmap);
bctoolbox_mmap_ullong_delete(mmap);
bctoolbox_iterator_delete(it);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment