st.h 3.24 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__st_h
#define ABC__misc__st__st_h
Alan Mishchenko committed
16 17
#define ST_INCLUDED

18
#include "src/misc/util/abc_global.h"
19 20 21

ABC_NAMESPACE_HEADER_START

22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40

/* 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


41 42
typedef int (*st_compare_func_type)(const char*, const char*);
typedef int (*st_hash_func_type)(const char*, int);
Alan Mishchenko committed
43

Alan Mishchenko committed
44 45
typedef struct st_table_entry st_table_entry;
struct st_table_entry {
46
    char *key;
Alan Mishchenko committed
47 48 49 50 51 52
    char *record;
    st_table_entry *next;
};

typedef struct st_table st_table;
struct st_table {
53 54
    st_compare_func_type compare;
    st_hash_func_type hash;
Alan Mishchenko committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
    int num_bins;
    int num_entries;
    int max_density;
    int reorder_flag;
    double grow_factor;
    st_table_entry **bins;
};

typedef struct st_generator st_generator;
struct st_generator {
    st_table *table;
    st_table_entry *entry;
    int index;
};

#define st_is_member(table,key) st_lookup(table,key,(char **) 0)
#define st_count(table) ((table)->num_entries)

enum st_retval {ST_CONTINUE, ST_STOP, ST_DELETE};

75
typedef enum st_retval (*ST_PFSR)(char *, char *, char *);
Alan Mishchenko committed
76 77
typedef int (*ST_PFI)();

78 79
extern st_table *st_init_table_with_params (st_compare_func_type compare, st_hash_func_type hash, int size, int density, double grow_factor, int reorder_flag);
extern st_table *st_init_table (st_compare_func_type, st_hash_func_type);
Alan Mishchenko committed
80
extern void st_free_table (st_table *);
81
extern int st_lookup (st_table *, const char *, char **);
Alan Mishchenko committed
82
extern int st_lookup_int (st_table *, char *, int *);
83
extern int st_insert (st_table *, const char *, char *);
Alan Mishchenko committed
84 85 86 87
extern int st_add_direct (st_table *, char *, char *);
extern int st_find_or_add (st_table *, char *, char ***);
extern int st_find (st_table *, char *, char ***);
extern st_table *st_copy (st_table *);
88
extern int st_delete (st_table *, const char **, char **);
Alan Mishchenko committed
89 90
extern int st_delete_int (st_table *, long *, char **);
extern int st_foreach (st_table *, ST_PFSR, char *);
91 92 93 94 95
extern int st_strhash (const char *, int);
extern int st_numhash (const char *, int);
extern int st_ptrhash (const char *, int);
extern int st_numcmp (const char *, const char *);
extern int st_ptrcmp (const char *, const char *);
Alan Mishchenko committed
96
extern st_generator *st_init_gen (st_table *);
97 98
extern int st_gen (st_generator *, const char **, char **);
extern int st_gen_int (st_generator *, const char **, long *);
Alan Mishchenko committed
99
extern void st_free_gen (st_generator *);
Alan Mishchenko committed
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114


#define ST_DEFAULT_MAX_DENSITY 5
#define ST_DEFAULT_INIT_TABLE_SIZE 11
#define ST_DEFAULT_GROW_FACTOR 2.0
#define ST_DEFAULT_REORDER_FLAG 0

#define st_foreach_item(table, gen, key, value) \
    for(gen=st_init_gen(table); st_gen(gen,key,value) || (st_free_gen(gen),0);)

#define st_foreach_item_int(table, gen, key, value) \
    for(gen=st_init_gen(table); st_gen_int(gen,key,value) || (st_free_gen(gen),0);)

#define ST_OUT_OF_MEM -10000

115 116 117 118 119


ABC_NAMESPACE_HEADER_END


Alan Mishchenko committed
120

Alan Mishchenko committed
121
#endif /* ST_INCLUDED */