static inline iterator_t * __container_hash_map_end(container_t *ct,iterator_t *end) { end->container_p = ct; hash_map_end(ct->priv.hmap,&end->pos.hash_pos); return end; }
void *get_tls_data(int32_t key) { hash_map_t h = (hash_map_t)pthread_getspecific(thread_key); if(!h) { h = hash_map_create(128,sizeof(key),sizeof(void*),tls_hash_func,tls_hash_key_eq); return NULL; } hash_map_iter it = hash_map_find(h,(void*)&key); hash_map_iter end = hash_map_end(h); if(!IT_EQ(it,end)) return IT_GET_VAL(void*,it); return NULL; }
void set_tls_data(int32_t key,void *data) { hash_map_t h = (hash_map_t)pthread_getspecific(thread_key); if(!h) { h = hash_map_create(128,sizeof(key),sizeof(void*),tls_hash_func,tls_hash_key_eq); } hash_map_iter it = hash_map_find(h,(void*)&key); hash_map_iter end = hash_map_end(h); if(IT_EQ(it,end)) HASH_MAP_INSERT(int32_t,void*,h,key,data); else IT_SET_VAL(void*,it,data); }
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; };