- minor format changes
- remove some unnecessary functions - use OBJ_* macros - fix ompi_hase_table_get_[first|next]_key_uint[32|64] functions This commit was SVN r2732.
Этот коммит содержится в:
родитель
e7135621fe
Коммит
71054a834e
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
#include "include/constants.h"
|
#include "include/constants.h"
|
||||||
#include "util/output.h"
|
#include "util/output.h"
|
||||||
|
#include "class/ompi_list.h"
|
||||||
#include "class/ompi_hash_table.h"
|
#include "class/ompi_hash_table.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -44,10 +45,12 @@ static void ompi_hash_table_destruct(ompi_hash_table_t* ht)
|
|||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
ompi_hash_table_remove_all(ht);
|
ompi_hash_table_remove_all(ht);
|
||||||
for(i=0; i<ht->ht_table_size; i++)
|
for(i=0; i<ht->ht_table_size; i++) {
|
||||||
OBJ_DESTRUCT(ht->ht_table+i);
|
OBJ_DESTRUCT(ht->ht_table+i);
|
||||||
if(NULL != ht->ht_table)
|
}
|
||||||
|
if(NULL != ht->ht_table) {
|
||||||
free(ht->ht_table);
|
free(ht->ht_table);
|
||||||
|
}
|
||||||
OBJ_DESTRUCT(&ht->ht_nodes);
|
OBJ_DESTRUCT(&ht->ht_nodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,8 +67,9 @@ int ompi_hash_table_init(ompi_hash_table_t* ht, size_t table_size)
|
|||||||
|
|
||||||
ht->ht_mask = power2-1;
|
ht->ht_mask = power2-1;
|
||||||
ht->ht_table = malloc(power2 * sizeof(ompi_list_t));
|
ht->ht_table = malloc(power2 * sizeof(ompi_list_t));
|
||||||
if(NULL == ht->ht_table)
|
if(NULL == ht->ht_table) {
|
||||||
return OMPI_ERR_OUT_OF_RESOURCE;
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
||||||
|
}
|
||||||
for(i=ht->ht_table_size; i<power2; i++) {
|
for(i=ht->ht_table_size; i<power2; i++) {
|
||||||
ompi_list_t* list = ht->ht_table+i;
|
ompi_list_t* list = ht->ht_table+i;
|
||||||
OBJ_CONSTRUCT(list, ompi_list_t);
|
OBJ_CONSTRUCT(list, ompi_list_t);
|
||||||
@ -93,6 +97,8 @@ int ompi_hash_table_remove_all(ompi_hash_table_t* ht)
|
|||||||
return OMPI_SUCCESS;
|
return OMPI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***************************************************************************/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ompi_uint32_hash_node_t
|
* ompi_uint32_hash_node_t
|
||||||
*/
|
*/
|
||||||
@ -105,20 +111,10 @@ struct ompi_uint32_hash_node_t
|
|||||||
};
|
};
|
||||||
typedef struct ompi_uint32_hash_node_t ompi_uint32_hash_node_t;
|
typedef struct ompi_uint32_hash_node_t ompi_uint32_hash_node_t;
|
||||||
|
|
||||||
static void ompi_uint32_hash_node_construct(ompi_uint32_hash_node_t* hn)
|
static OBJ_CLASS_INSTANCE(ompi_uint32_hash_node_t,
|
||||||
{
|
ompi_list_item_t,
|
||||||
}
|
NULL,
|
||||||
|
NULL);
|
||||||
static void ompi_uint32_hash_node_destruct(ompi_uint32_hash_node_t* hn)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static ompi_class_t ompi_uint32_hash_node_t_class = {
|
|
||||||
"ompi_uint32_hash_node_t",
|
|
||||||
&ompi_list_item_t_class,
|
|
||||||
(ompi_construct_t)ompi_uint32_hash_node_construct,
|
|
||||||
(ompi_destruct_t)ompi_uint32_hash_node_destruct
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
void* ompi_hash_table_get_value_uint32(ompi_hash_table_t* ht, uint32_t key)
|
void* ompi_hash_table_get_value_uint32(ompi_hash_table_t* ht, uint32_t key)
|
||||||
@ -205,6 +201,7 @@ int ompi_hash_table_remove_value_uint32(ompi_hash_table_t* ht, uint32_t key)
|
|||||||
return OMPI_ERR_NOT_FOUND;
|
return OMPI_ERR_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***************************************************************************/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ompi_uint64_hash_node_t
|
* ompi_uint64_hash_node_t
|
||||||
@ -218,20 +215,10 @@ struct ompi_uint64_hash_node_t
|
|||||||
};
|
};
|
||||||
typedef struct ompi_uint64_hash_node_t ompi_uint64_hash_node_t;
|
typedef struct ompi_uint64_hash_node_t ompi_uint64_hash_node_t;
|
||||||
|
|
||||||
static void ompi_uint64_hash_node_construct(ompi_uint64_hash_node_t* hn)
|
static OBJ_CLASS_INSTANCE(ompi_uint64_hash_node_t,
|
||||||
{
|
ompi_list_item_t,
|
||||||
}
|
NULL,
|
||||||
|
NULL);
|
||||||
static void ompi_uint64_hash_node_destruct(ompi_uint64_hash_node_t* hn)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
static ompi_class_t ompi_uint64_hash_node_t_class = {
|
|
||||||
"ompi_uint64_hash_node_t",
|
|
||||||
OBJ_CLASS(ompi_list_item_t),
|
|
||||||
(ompi_construct_t)ompi_uint64_hash_node_construct,
|
|
||||||
(ompi_destruct_t)ompi_uint64_hash_node_destruct
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
void* ompi_hash_table_get_value_uint64(ompi_hash_table_t* ht, uint64_t key)
|
void* ompi_hash_table_get_value_uint64(ompi_hash_table_t* ht, uint64_t key)
|
||||||
@ -282,9 +269,10 @@ int ompi_hash_table_set_value_uint64(ompi_hash_table_t* ht,
|
|||||||
node = (ompi_uint64_hash_node_t*)ompi_list_remove_first(&ht->ht_nodes);
|
node = (ompi_uint64_hash_node_t*)ompi_list_remove_first(&ht->ht_nodes);
|
||||||
if(NULL == node) {
|
if(NULL == node) {
|
||||||
node = OBJ_NEW(ompi_uint64_hash_node_t);
|
node = OBJ_NEW(ompi_uint64_hash_node_t);
|
||||||
if(NULL == node)
|
if(NULL == node) {
|
||||||
return OMPI_ERR_OUT_OF_RESOURCE;
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
node->hn_key = key;
|
node->hn_key = key;
|
||||||
node->hn_value = value;
|
node->hn_value = value;
|
||||||
ompi_list_append(list, (ompi_list_item_t*)node);
|
ompi_list_append(list, (ompi_list_item_t*)node);
|
||||||
@ -318,7 +306,7 @@ int ompi_hash_table_remove_value_uint64(ompi_hash_table_t* ht, uint64_t key)
|
|||||||
return OMPI_ERR_NOT_FOUND;
|
return OMPI_ERR_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/***************************************************************************/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ompi_ptr_hash_node_t
|
* ompi_ptr_hash_node_t
|
||||||
@ -342,16 +330,15 @@ static void ompi_ptr_hash_node_construct(ompi_ptr_hash_node_t* hn)
|
|||||||
|
|
||||||
static void ompi_ptr_hash_node_destruct(ompi_ptr_hash_node_t* hn)
|
static void ompi_ptr_hash_node_destruct(ompi_ptr_hash_node_t* hn)
|
||||||
{
|
{
|
||||||
if(NULL != hn->hn_key)
|
if(NULL != hn->hn_key) {
|
||||||
free(hn->hn_key);
|
free(hn->hn_key);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static ompi_class_t ompi_ptr_hash_node_t_class = {
|
static OBJ_CLASS_INSTANCE(ompi_ptr_hash_node_t,
|
||||||
"ompi_ptr_hash_node_t",
|
ompi_list_item_t,
|
||||||
OBJ_CLASS(ompi_list_item_t),
|
ompi_ptr_hash_node_construct,
|
||||||
(ompi_construct_t)ompi_ptr_hash_node_construct,
|
ompi_ptr_hash_node_destruct);
|
||||||
(ompi_destruct_t)ompi_ptr_hash_node_destruct
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static inline uint32_t ompi_hash_value(size_t mask, const void *key,
|
static inline uint32_t ompi_hash_value(size_t mask, const void *key,
|
||||||
@ -420,9 +407,10 @@ int ompi_hash_table_set_value_ptr(ompi_hash_table_t* ht, const void* key,
|
|||||||
node = (ompi_ptr_hash_node_t*)ompi_list_remove_first(&ht->ht_nodes);
|
node = (ompi_ptr_hash_node_t*)ompi_list_remove_first(&ht->ht_nodes);
|
||||||
if(NULL == node) {
|
if(NULL == node) {
|
||||||
node = OBJ_NEW(ompi_ptr_hash_node_t);
|
node = OBJ_NEW(ompi_ptr_hash_node_t);
|
||||||
if(NULL == node)
|
if(NULL == node) {
|
||||||
return OMPI_ERR_OUT_OF_RESOURCE;
|
return OMPI_ERR_OUT_OF_RESOURCE;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
node->hn_key = malloc(key_size);
|
node->hn_key = malloc(key_size);
|
||||||
node->hn_key_size = key_size;
|
node->hn_key_size = key_size;
|
||||||
node->hn_value = value;
|
node->hn_value = value;
|
||||||
@ -469,40 +457,69 @@ int
|
|||||||
ompi_hash_table_get_first_key_uint32(ompi_hash_table_t *ht, uint32_t *key,
|
ompi_hash_table_get_first_key_uint32(ompi_hash_table_t *ht, uint32_t *key,
|
||||||
void **value, void **node)
|
void **value, void **node)
|
||||||
{
|
{
|
||||||
|
size_t i;
|
||||||
ompi_uint32_hash_node_t *list_node;
|
ompi_uint32_hash_node_t *list_node;
|
||||||
list_node = (ompi_uint32_hash_node_t*) ompi_list_get_first(ht->ht_table);
|
|
||||||
|
/* Go through all the lists and return the first element off the
|
||||||
|
first non-empty list */
|
||||||
|
|
||||||
|
for (i = 0; i < ht->ht_table_size; ++i) {
|
||||||
|
if (ompi_list_get_size(ht->ht_table + i) > 0) {
|
||||||
|
list_node = (ompi_uint32_hash_node_t*)
|
||||||
|
ompi_list_get_first(ht->ht_table + i);
|
||||||
*node = list_node;
|
*node = list_node;
|
||||||
|
|
||||||
/* Quit if there is no element in the list */
|
|
||||||
if (*node == ompi_list_get_end(ht->ht_table)) {
|
|
||||||
return OMPI_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
*key = list_node->hn_key;
|
*key = list_node->hn_key;
|
||||||
*value = list_node->hn_value;
|
*value = list_node->hn_value;
|
||||||
return OMPI_SUCCESS;
|
return OMPI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* The hash table is empty */
|
||||||
|
|
||||||
|
return OMPI_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
ompi_hash_table_get_next_key_uint32(ompi_hash_table_t *ht, uint32_t *key,
|
ompi_hash_table_get_next_key_uint32(ompi_hash_table_t *ht, uint32_t *key,
|
||||||
void **value, void *in_node, void **out_node)
|
void **value, void *in_node,
|
||||||
|
void **out_node)
|
||||||
{
|
{
|
||||||
ompi_list_t* list = ht->ht_table + (((ompi_uint32_hash_node_t*)
|
size_t i;
|
||||||
in_node)->hn_key & ht->ht_mask);
|
ompi_list_t *list;
|
||||||
if (in_node == ompi_list_get_last(list)) {
|
ompi_list_item_t *item;
|
||||||
++list;
|
ompi_uint32_hash_node_t *next;
|
||||||
*out_node = (void *) ompi_list_get_first(list);
|
|
||||||
|
|
||||||
if (*out_node == ompi_list_get_end(list)) {
|
/* Try to simply get the next value in the list. If there isn't
|
||||||
|
one, find the next non-empty list and take the first value */
|
||||||
|
|
||||||
|
next = (ompi_uint32_hash_node_t*) in_node;
|
||||||
|
list = ht->ht_table + (next->hn_key & ht->ht_mask);
|
||||||
|
item = ompi_list_get_next(next);
|
||||||
|
if (ompi_list_get_end(list) == item) {
|
||||||
|
item = NULL;
|
||||||
|
for (i = (list - ht->ht_table) + 1; i < ht->ht_table_size; ++i) {
|
||||||
|
if (ompi_list_get_size(ht->ht_table + i) > 0) {
|
||||||
|
item = ompi_list_get_first(ht->ht_table + i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If we didn't find another non-empty list after this one,
|
||||||
|
then we're at the end of the hash table */
|
||||||
|
|
||||||
|
if (NULL == item) {
|
||||||
return OMPI_ERROR;
|
return OMPI_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
|
||||||
*out_node = (void *) ompi_list_get_next(in_node);
|
|
||||||
}
|
}
|
||||||
*key = ((ompi_uint32_hash_node_t*)(*out_node))->hn_key;
|
|
||||||
*value = ((ompi_uint32_hash_node_t*)(*out_node))->hn_value;
|
/* We found it. Save the values (use "next" to avoid some
|
||||||
|
typecasting) */
|
||||||
|
|
||||||
|
next = *out_node = (void *) item;
|
||||||
|
*key = next->hn_key;
|
||||||
|
*value = next->hn_value;
|
||||||
|
|
||||||
return OMPI_SUCCESS;
|
return OMPI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -511,38 +528,68 @@ int
|
|||||||
ompi_hash_table_get_first_key_uint64(ompi_hash_table_t *ht, uint64_t *key,
|
ompi_hash_table_get_first_key_uint64(ompi_hash_table_t *ht, uint64_t *key,
|
||||||
void **value, void **node)
|
void **value, void **node)
|
||||||
{
|
{
|
||||||
*node = (ompi_uint64_hash_node_t*) ompi_list_get_first(ht->ht_table);
|
size_t i;
|
||||||
|
ompi_uint64_hash_node_t *list_node;
|
||||||
|
|
||||||
/* Quit if there is no element in the list */
|
/* Go through all the lists and return the first element off the
|
||||||
if (*node == ompi_list_get_end(ht->ht_table)) {
|
first non-empty list */
|
||||||
return OMPI_ERROR;
|
|
||||||
|
for (i = 0; i < ht->ht_table_size; ++i) {
|
||||||
|
if (ompi_list_get_size(ht->ht_table + i) > 0) {
|
||||||
|
list_node = (ompi_uint64_hash_node_t*)
|
||||||
|
ompi_list_get_first(ht->ht_table + i);
|
||||||
|
*node = list_node;
|
||||||
|
*key = list_node->hn_key;
|
||||||
|
*value = list_node->hn_value;
|
||||||
|
return OMPI_SUCCESS;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*key = ((ompi_uint64_hash_node_t*)(*node))->hn_key;
|
/* The hash table is empty */
|
||||||
*value = ((ompi_uint64_hash_node_t*)(*node))->hn_value;
|
|
||||||
return OMPI_SUCCESS;
|
return OMPI_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
ompi_hash_table_get_next_key_uint64(ompi_hash_table_t *ht, uint64_t *key,
|
ompi_hash_table_get_next_key_uint64(ompi_hash_table_t *ht, uint64_t *key,
|
||||||
void **value, void *in_node, void **out_node)
|
void **value, void *in_node,
|
||||||
|
void **out_node)
|
||||||
{
|
{
|
||||||
ompi_list_t* list = ht->ht_table + (((ompi_uint64_hash_node_t*)
|
size_t i;
|
||||||
in_node)->hn_key & ht->ht_mask);
|
ompi_list_t *list;
|
||||||
if (in_node == ompi_list_get_last(list)) {
|
ompi_list_item_t *item;
|
||||||
++list;
|
ompi_uint64_hash_node_t *next;
|
||||||
*out_node = (void *) ompi_list_get_first(list);
|
|
||||||
|
|
||||||
if (*out_node == ompi_list_get_end(list)) {
|
/* Try to simply get the next value in the list. If there isn't
|
||||||
|
one, find the next non-empty list and take the first value */
|
||||||
|
|
||||||
|
next = (ompi_uint64_hash_node_t*) in_node;
|
||||||
|
list = ht->ht_table + (next->hn_key & ht->ht_mask);
|
||||||
|
item = ompi_list_get_next(next);
|
||||||
|
if (ompi_list_get_end(list) == item) {
|
||||||
|
item = NULL;
|
||||||
|
for (i = (list - ht->ht_table) + 1; i < ht->ht_table_size; ++i) {
|
||||||
|
if (ompi_list_get_size(ht->ht_table + i) > 0) {
|
||||||
|
item = ompi_list_get_first(ht->ht_table + i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* If we didn't find another non-empty list after this one,
|
||||||
|
then we're at the end of the hash table */
|
||||||
|
|
||||||
|
if (NULL == item) {
|
||||||
return OMPI_ERROR;
|
return OMPI_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
|
||||||
*out_node = (void *) ompi_list_get_next(in_node);
|
|
||||||
}
|
}
|
||||||
*key = ((ompi_uint64_hash_node_t*)(*out_node))->hn_key;
|
|
||||||
*value = ((ompi_uint32_hash_node_t*)(*out_node))->hn_value;
|
/* We found it. Save the values (use "next" to avoid some
|
||||||
|
typecasting) */
|
||||||
|
|
||||||
|
next = *out_node = (void *) item;
|
||||||
|
*key = next->hn_key;
|
||||||
|
*value = next->hn_value;
|
||||||
|
|
||||||
return OMPI_SUCCESS;
|
return OMPI_SUCCESS;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user