1
1

added a hash table indexed by ompi_process_name_t

This commit was SVN r3316.
Этот коммит содержится в:
Tim Woodall 2004-10-25 19:53:44 +00:00
родитель 088c97b14e
Коммит ee20f3c6b0
4 изменённых файлов: 197 добавлений и 2 удалений

Просмотреть файл

@ -16,6 +16,7 @@ headers = \
ompi_list.h \ ompi_list.h \
ompi_object.h \ ompi_object.h \
ompi_pointer_array.h \ ompi_pointer_array.h \
ompi_proc_table.h \
ompi_value_array.h \ ompi_value_array.h \
ompi_rb_tree.h ompi_rb_tree.h
@ -26,6 +27,7 @@ liblfc_la_SOURCES = \
ompi_list.c \ ompi_list.c \
ompi_object.c \ ompi_object.c \
ompi_pointer_array.c \ ompi_pointer_array.c \
ompi_proc_table.c \
ompi_bitmap.c \ ompi_bitmap.c \
ompi_value_array.c \ ompi_value_array.c \
ompi_rb_tree.c ompi_rb_tree.c

Просмотреть файл

@ -29,8 +29,7 @@ struct ompi_hash_table_t
{ {
ompi_object_t super; /**< subclass of ompi_object_t */ ompi_object_t super; /**< subclass of ompi_object_t */
ompi_list_t ht_nodes; /**< free list of hash nodes */ ompi_list_t ht_nodes; /**< free list of hash nodes */
ompi_list_t *ht_table; /**< each item is an array of ompi_list_t *ht_table; /**< each item is an array of ompi_fhnode_t nodes */
ompi_fhnode_t nodes */
size_t ht_table_size; /**< size of table */ size_t ht_table_size; /**< size of table */
size_t ht_size; /**< number of values on table */ size_t ht_size; /**< number of values on table */
size_t ht_mask; size_t ht_mask;

125
src/class/ompi_proc_table.c Обычный файл
Просмотреть файл

@ -0,0 +1,125 @@
/*
* $HEADER$
*/
#include "ompi_config.h"
#include <string.h>
#include <stdlib.h>
#include "include/constants.h"
#include "util/output.h"
#include "class/ompi_proc_table.h"
/*
* ompi_process_name_hash_node_t
*/
struct ompi_proc_hash_node_t
{
ompi_list_item_t super;
ompi_process_name_t hn_key;
void *hn_value;
};
typedef struct ompi_proc_hash_node_t ompi_proc_hash_node_t;
static OBJ_CLASS_INSTANCE(
ompi_proc_hash_node_t,
ompi_list_item_t,
NULL,
NULL);
void* ompi_hash_table_get_proc(ompi_hash_table_t* ht,
const ompi_process_name_t* proc)
{
uint32_t key = (proc->cellid << 24) + (proc->jobid << 16) + proc->vpid;
ompi_list_t* list = ht->ht_table + (key & ht->ht_mask);
ompi_proc_hash_node_t *node;
#if OMPI_ENABLE_DEBUG
if(ht->ht_table_size == 0) {
ompi_output(0, "ompi_hash_table_get_proc:"
"ompi_hash_table_init() has not been called");
return NULL;
}
#endif
for(node = (ompi_proc_hash_node_t*)ompi_list_get_first(list);
node != (ompi_proc_hash_node_t*)ompi_list_get_end(list);
node = (ompi_proc_hash_node_t*)ompi_list_get_next(node)) {
if (memcmp(&node->hn_key,proc,sizeof(ompi_process_name_t)) == 0) {
return node->hn_value;
}
}
return NULL;
}
int ompi_hash_table_set_proc(
ompi_hash_table_t* ht,
const ompi_process_name_t* proc,
void* value)
{
uint32_t key = (proc->cellid << 24) + (proc->jobid << 16) + proc->vpid;
ompi_list_t* list = ht->ht_table + (key & ht->ht_mask);
ompi_proc_hash_node_t *node;
#if OMPI_ENABLE_DEBUG
if(ht->ht_table_size == 0) {
ompi_output(0, "ompi_hash_table_set_value_proc:"
"ompi_hash_table_init() has not been called");
return OMPI_ERR_BAD_PARAM;
}
#endif
for(node = (ompi_proc_hash_node_t*)ompi_list_get_first(list);
node != (ompi_proc_hash_node_t*)ompi_list_get_end(list);
node = (ompi_proc_hash_node_t*)ompi_list_get_next(node)) {
if (memcmp(&node->hn_key,proc,sizeof(ompi_process_name_t)) == 0) {
node->hn_value = value;
return OMPI_SUCCESS;
}
}
node = (ompi_proc_hash_node_t*)ompi_list_remove_first(&ht->ht_nodes);
if(NULL == node) {
node = OBJ_NEW(ompi_proc_hash_node_t);
if(NULL == node)
return OMPI_ERR_OUT_OF_RESOURCE;
}
node->hn_key = *proc;
node->hn_value = value;
ompi_list_append(list, (ompi_list_item_t*)node);
ht->ht_size++;
return OMPI_SUCCESS;
}
int ompi_hash_table_remove_proc(
ompi_hash_table_t* ht,
const ompi_process_name_t* proc)
{
uint32_t key = (proc->cellid << 24) + (proc->jobid << 16) + proc->vpid;
ompi_list_t* list = ht->ht_table + (key & ht->ht_mask);
ompi_proc_hash_node_t *node;
#if OMPI_ENABLE_DEBUG
if(ht->ht_table_size == 0) {
ompi_output(0, "ompi_hash_table_remove_value_proc:"
"ompi_hash_table_init() has not been called");
return OMPI_ERR_BAD_PARAM;
}
#endif
for(node = (ompi_proc_hash_node_t*)ompi_list_get_first(list);
node != (ompi_proc_hash_node_t*)ompi_list_get_end(list);
node = (ompi_proc_hash_node_t*)ompi_list_get_next(node)) {
if (memcmp(&node->hn_key,proc,sizeof(ompi_process_name_t)) == 0) {
ompi_list_remove_item(list, (ompi_list_item_t*)node);
ompi_list_append(&ht->ht_nodes, (ompi_list_item_t*)node);
ht->ht_size--;
return OMPI_SUCCESS;
}
}
return OMPI_ERR_NOT_FOUND;
}

69
src/class/ompi_proc_table.h Обычный файл
Просмотреть файл

@ -0,0 +1,69 @@
/*
* $HEADER$
*
*/
/** @file
*
* A hash table indexed by ompi_process_name_t.
*/
#ifndef OMPI_PROC_TABLE_H
#define OMPI_PROC_TABLE_H
#include "class/ompi_hash_table.h"
#include "mca/ns/ns.h"
#if defined(c_plusplus) || defined(__cplusplus)
extern "C" {
#endif
/**
* Retrieve value via ompi_process_name_t key.
*
* @param table The input hash table (IN).
* @param key The input key (IN).
* @return The value associated with the key or NULL if the item is not found.
*
*/
OMPI_DECLSPEC void *ompi_hash_table_get_proc(
ompi_hash_table_t* table,
const ompi_process_name_t* key);
/**
* Set value based on uint32_t key.
*
* @param table The input hash table (IN).
* @param key The input key (IN).
* @param value The value to be associated with the key (IN).
* @return OMPI return code.
*
*/
OMPI_DECLSPEC int ompi_hash_table_set_proc(
ompi_hash_table_t* table,
const ompi_process_name_t*,
void* value);
/**
* Remove value based on uint32_t key.
*
* @param table The input hash table (IN).
* @param key The input key (IN).
* @return OMPI return code.
*
*/
OMPI_DECLSPEC int ompi_hash_table_remove_proc(
ompi_hash_table_t* table,
const ompi_process_name_t* key);
#if defined(c_plusplus) || defined(__cplusplus)
}
#endif
#endif /* OMPI_HASH_TABLE_H */