static inline iterator_t * __container_hash_map_begin(container_t *ct,iterator_t *begin) { begin->container_p = ct; hash_map_begin(ct->priv.hmap,&begin->pos.hash_pos); return begin; }
int main() { hash_map_t h = hash_map_create(4096,sizeof(int32_t),sizeof(int32_t),_hash_func_,_hash_key_eq_); int32_t i = 1; for( ; i < 10; ++i) { hash_map_iter it = HASH_MAP_INSERT(int32_t,int32_t,h,i,i); printf("%d\n",IT_GET_VAL(int32_t,it)); } printf("----------------------\n"); { hash_map_iter it = HASH_MAP_FIND(int32_t,h,5); hash_map_iter end = hash_map_end(h); if(!IT_EQ(it,end)) printf("%d\n",IT_GET_VAL(int32_t,it)); } printf("----------------------\n"); { hash_map_iter it = HASH_MAP_FIND(int32_t,h,100); hash_map_iter end = hash_map_end(h); if(!IT_EQ(it,end)) printf("%d\n",IT_GET_VAL(int32_t,it)); else printf("can't find 100\n"); } printf("----------------------\n"); HASH_MAP_REMOVE(int32_t,h,5); { hash_map_iter it = hash_map_begin(h); hash_map_iter end = hash_map_end(h); for( ; !IT_EQ(it,end); IT_NEXT(it)) printf("%d\n",IT_GET_VAL(int32_t,it)); } return 0; };
assert_true(it_iter._t_containertype == _HASH_MAP_CONTAINER); assert_true(it_iter._t_iteratortype == _BIDIRECTIONAL_ITERATOR); } /* * test _hash_map_iterator_get_value */ UT_CASE_DEFINATION(_hash_map_iterator_get_value) void test__hash_map_iterator_get_value__null_corepos(void** state) { hash_map_t* pt_hash_map = create_hash_map(int, int); hash_map_iterator_t it_iter; int elem = 0; hash_map_init(pt_hash_map); it_iter = hash_map_begin(pt_hash_map); it_iter._t_pos._t_hashpos._pby_corepos = NULL; expect_assert_failure(_hash_map_iterator_get_value(it_iter, &elem)); hash_map_destroy(pt_hash_map); } void test__hash_map_iterator_get_value__null_hashtable(void** state) { hash_map_t* pt_hash_map = create_hash_map(int, int); hash_map_iterator_t it_iter; int elem = 0; hash_map_init(pt_hash_map); it_iter = hash_map_begin(pt_hash_map);