int lhi_array_bucket_to_array(const hi_handle_t *hi_handle, size_t bucket, struct lhi_bucket_array *a) { unsigned int len, i, j; int ret = HI_ERR_NODATA; lhi_pthread_mutex_lock(hi_handle->mutex_lock); len = hi_handle->eng.eng_array.bucket_array_slot_size[bucket]; if (len == 0) goto out; ret = lhi_bucket_array_alloc(a, len); if (ret) goto out; j = 0; for (i = 0; i < len ; i++) { /* the array CAN contain spare data buckets, skip it if * we found such bucket */ if (hi_handle->eng.eng_array.bucket_array[bucket][i].allocation == BA_NOT_ALLOCATED) continue; a->data[j] = (void *) hi_handle->eng.eng_array.bucket_array[bucket][i].data; a->keys[j] = (void *) hi_handle->eng.eng_array.bucket_array[bucket][i].key; a->keys_length[i] = hi_handle->eng.eng_array.bucket_array[bucket][i].key_len; j++; } out: lhi_pthread_mutex_unlock(hi_handle->mutex_lock); return ret; }
int lhi_rbtree_bucket_to_array(const hi_handle_t *hi_handle, size_t tree, struct lhi_bucket_array *a) { struct rb_node *rbnode; size_t max; int ret = HI_ERR_NODATA; if (hi_handle->table_size < tree) return HI_ERR_RANGE; rbnode = hi_handle->eng_rbtree.trees[tree].root.rb_node; if (!rbnode) return HI_ERR_NODATA; lhi_pthread_rwlock_rdlock(hi_handle->eng_rbtree.trees[tree].rwlock); max = hi_handle->bucket_size[tree]; if (!max) goto out; ret = lhi_bucket_array_alloc(a, max); if (ret) goto out; hi_rbtree_traverse(rbnode, 0, a); ret = 0; out: lhi_pthread_rwlock_unlock(hi_handle->eng_rbtree.trees[tree].rwlock); return ret; }
int lhi_list_bucket_to_array(const hi_handle_t *hi_handle, size_t bucket, struct lhi_bucket_array *a) { size_t max, i = 0; int ret = HI_ERR_NODATA; if (hi_handle->table_size < bucket) return HI_ERR_RANGE; lhi_pthread_mutex_lock(hi_handle->mutex_lock); max = hi_handle->bucket_size[bucket]; if (!max) goto out_err; ret = lhi_bucket_array_alloc(a, max); if (ret) goto out_err; switch (hi_handle->coll_eng) { case COLL_ENG_LIST: case COLL_ENG_LIST_MTF: { hi_bucket_obj_t *b_obj = hi_handle->eng_list.bucket_table[bucket]; for (; b_obj; b_obj = b_obj->next) { a->data[i] = (void*) b_obj->data; a->keys[i] = (void*) b_obj->key; a->keys_length[i] = b_obj->key_len; i++; } break; } case COLL_ENG_LIST_HASH: case COLL_ENG_LIST_MTF_HASH: { hi_bucket_hl_obj_t *b_obj = hi_handle->eng_list.bucket_table_hl[bucket]; for (; b_obj; b_obj = b_obj->next) { a->data[i] = (void*) b_obj->data; a->keys[i] = (void*) b_obj->key; a->keys_length[i] = b_obj->key_len; i++; } break; } default: ret = HI_ERR_INTERNAL; goto out_err; } lhi_pthread_mutex_unlock(hi_handle->mutex_lock); return 0; out_err: lhi_pthread_mutex_unlock(hi_handle->mutex_lock); return ret; }