stmm.h 4.2 KB
Newer Older
Alan Mishchenko committed
1 2 3 4 5 6 7 8 9 10 11 12 13
/*
 * Revision Control Information
 *
 * /projects/hsis/CVS/utilities/st/st.h,v
 * serdar
 * 1.1
 * 1993/07/29 01:00:21
 *
 */
/* LINTLIBRARY */

/* /projects/hsis/CVS/utilities/st/st.h,v 1.1 1993/07/29 01:00:21 serdar Exp */

14 15
#ifndef ABC__misc__st__stmm_h
#define ABC__misc__st__stmm_h
Alan Mishchenko committed
16

17
#include "misc/util/abc_global.h"
Alan Mishchenko committed
18

19
ABC_NAMESPACE_HEADER_START
20 21


22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
/* These are potential duplicates. */
#ifndef EXTERN
#   ifdef __cplusplus
#       ifdef ABC_NAMESPACE
#           define EXTERN extern
#       else
#           define EXTERN extern "C"
#       endif
#   else
#       define EXTERN extern
#   endif
#endif

#ifndef ARGS
#define ARGS(protos) protos
#endif
38 39 40

typedef int (*stmm_compare_func_type)(const char*, const char*);
typedef int (*stmm_hash_func_type)(const char*, int);
Alan Mishchenko committed
41

Alan Mishchenko committed
42 43 44 45 46 47 48 49 50 51 52 53 54
typedef struct stmm_table_entry stmm_table_entry;
typedef struct stmm_table stmm_table;
typedef struct stmm_generator stmm_generator;

struct stmm_table_entry
{
    char *key;
    char *record;
    stmm_table_entry *next;
};

struct stmm_table
{
55 56
    stmm_compare_func_type compare;
    stmm_hash_func_type hash;
Alan Mishchenko committed
57 58 59 60 61 62 63 64
    int num_bins;
    int num_entries;
    int max_density;
    int reorder_flag;
    double grow_factor;
    stmm_table_entry **bins;
    // memory manager to improve runtime and prevent memory fragmentation
    // added by alanmi - January 16, 2003
65
    void * pMemMan;
Alan Mishchenko committed
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
};

struct stmm_generator
{
    stmm_table *table;
    stmm_table_entry *entry;
    int index;
};

#define stmm_is_member(table,key) stmm_lookup(table,key,(char **) 0)
#define stmm_count(table) ((table)->num_entries)

enum stmm_retval
{ STMM_CONTINUE, STMM_STOP, STMM_DELETE };

81
typedef enum stmm_retval (*STMM_PFSR) (char *, char *, char *);
Alan Mishchenko committed
82 83

EXTERN stmm_table *stmm_init_table_with_params
84 85
ARGS ((stmm_compare_func_type compare, stmm_hash_func_type hash, int size, int density, double grow_factor, int reorder_flag));
EXTERN stmm_table *stmm_init_table ARGS ((stmm_compare_func_type, stmm_hash_func_type));
Alan Mishchenko committed
86 87 88 89 90 91 92 93 94 95 96
EXTERN void stmm_free_table ARGS ((stmm_table *));
EXTERN int stmm_lookup ARGS ((stmm_table *, char *, char **));
EXTERN int stmm_lookup_int ARGS ((stmm_table *, char *, int *));
EXTERN int stmm_insert ARGS ((stmm_table *, char *, char *));
EXTERN int stmm_add_direct ARGS ((stmm_table *, char *, char *));
EXTERN int stmm_find_or_add ARGS ((stmm_table *, char *, char ***));
EXTERN int stmm_find ARGS ((stmm_table *, char *, char ***));
EXTERN stmm_table *stmm_copy ARGS ((stmm_table *));
EXTERN int stmm_delete ARGS ((stmm_table *, char **, char **));
EXTERN int stmm_delete_int ARGS ((stmm_table *, long *, char **));
EXTERN int stmm_foreach ARGS ((stmm_table *, STMM_PFSR, char *));
97 98 99 100 101
EXTERN int stmm_strhash ARGS ((const char *, int));
EXTERN int stmm_numhash ARGS ((const char *, int));
EXTERN int stmm_ptrhash ARGS ((const char *, int));
EXTERN int stmm_numcmp ARGS ((const char *, const char *));
EXTERN int stmm_ptrcmp ARGS ((const char *, const char *));
Alan Mishchenko committed
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
EXTERN stmm_generator *stmm_init_gen ARGS ((stmm_table *));
EXTERN int stmm_gen ARGS ((stmm_generator *, char **, char **));
EXTERN int stmm_gen_int ARGS ((stmm_generator *, char **, long *));
EXTERN void stmm_free_gen ARGS ((stmm_generator *));
// additional functions
EXTERN void stmm_clean ARGS ((stmm_table *));



#define STMM_DEFAULT_MAX_DENSITY        5
#define STMM_DEFAULT_INIT_TABLE_SIZE   11
#define STMM_DEFAULT_GROW_FACTOR      2.0
#define STMM_DEFAULT_REORDER_FLAG       0

// added by Zhihong: no need for memory allocation
#define stmm_foreach_item2(tb, /* stmm_generator */gen, key, value) \
Alan Mishchenko committed
118
    for(gen.table=(tb), gen.entry=NULL, gen.index=0; \
Alan Mishchenko committed
119 120 121 122 123 124 125 126 127 128 129 130 131
        stmm_gen(&(gen),key,value);)

#define stmm_foreach_item(table, gen, key, value) \
    for(gen=stmm_init_gen(table); stmm_gen(gen,key,value) || (stmm_free_gen(gen),0);)

#define stmm_foreach_item_int(table, gen, key, value) \
    for(gen=stmm_init_gen(table); stmm_gen_int(gen,key,value) || (stmm_free_gen(gen),0);)

#define STMM_OUT_OF_MEM -10000

/*

// consider adding these other other similar definitions
132 133 134 135 136 137
#define st__table       stmm_table
#define st__insert      stmm_insert
#define st__delete      stmm_delete
#define st__lookup      stmm_lookup
#define st__init_table  stmm_init_table
#define st__free_table  stmm_free_table
Alan Mishchenko committed
138 139 140

*/

141 142 143 144 145


ABC_NAMESPACE_HEADER_END


Alan Mishchenko committed
146

Alan Mishchenko committed
147
#endif /* STMM_INCLUDED */