summaryrefslogtreecommitdiffstats
path: root/src/misc/st
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2008-01-30 20:01:00 -0800
committerAlan Mishchenko <alanmi@berkeley.edu>2008-01-30 20:01:00 -0800
commit0c6505a26a537dc911b6566f82d759521e527c08 (patch)
treef2687995efd4943fe3b1307fce7ef5942d0a57b3 /src/misc/st
parent4d30a1e4f1edecff86d5066ce4653a370e59e5e1 (diff)
downloadabc-0c6505a26a537dc911b6566f82d759521e527c08.tar.gz
abc-0c6505a26a537dc911b6566f82d759521e527c08.tar.bz2
abc-0c6505a26a537dc911b6566f82d759521e527c08.zip
Version abc80130_2
Diffstat (limited to 'src/misc/st')
-rw-r--r--src/misc/st/st.c115
-rw-r--r--src/misc/st/st.h52
-rw-r--r--src/misc/st/stmm.c105
-rw-r--r--src/misc/st/stmm.h10
4 files changed, 161 insertions, 121 deletions
diff --git a/src/misc/st/st.c b/src/misc/st/st.c
index 13e9bd6a..872fe51b 100644
--- a/src/misc/st/st.c
+++ b/src/misc/st/st.c
@@ -8,12 +8,31 @@
*
*/
#include <stdio.h>
-#include "util.h"
+#include <stdlib.h>
#include "st.h"
+#ifndef ABS
+# define ABS(a) ((a) < 0 ? -(a) : (a))
+#endif
+
+#ifndef ALLOC
+#define ALLOC(type, num) ((type *) malloc(sizeof(type) * (num)))
+#endif
+
+#ifndef FREE
+#define FREE(obj) ((obj) ? (free((char *) (obj)), (obj) = 0) : 0)
+#endif
+
+#ifndef REALLOC
+#define REALLOC(type, obj, num) \
+ ((obj) ? ((type *) realloc((char *)(obj), sizeof(type) * (num))) : \
+ ((type *) malloc(sizeof(type) * (num))))
+#endif
+
#define ST_NUMCMP(x,y) ((x) != (y))
#define ST_NUMHASH(x,size) (ABS((long)x)%(size))
-#define ST_PTRHASH(x,size) ((int)((unsigned long)(x)>>2)%size)
+//#define ST_PTRHASH(x,size) ((int)((unsigned long)(x)>>2)%size) // 64-bit bug fix 9/17/2007
+#define ST_PTRHASH(x,size) ((int)(((unsigned long)(x)>>2)%size))
#define EQUAL(func, x, y) \
((((func) == st_numcmp) || ((func) == st_ptrcmp)) ?\
(ST_NUMCMP((x),(y)) == 0) : ((*func)((x), (y)) == 0))
@@ -41,8 +60,8 @@ int reorder_flag;
st_table *new;
new = ALLOC(st_table, 1);
- if (new == NIL(st_table)) {
- return NIL(st_table);
+ if (new == NULL) {
+ return NULL;
}
new->compare = compare;
new->hash = hash;
@@ -55,9 +74,9 @@ int reorder_flag;
}
new->num_bins = size;
new->bins = ALLOC(st_table_entry *, size);
- if (new->bins == NIL(st_table_entry *)) {
+ if (new->bins == NULL) {
FREE(new);
- return NIL(st_table);
+ return NULL;
}
for(i = 0; i < size; i++) {
new->bins[i] = 0;
@@ -85,7 +104,7 @@ st_table *table;
for(i = 0; i < table->num_bins ; i++) {
ptr = table->bins[i];
- while (ptr != NIL(st_table_entry)) {
+ while (ptr != NULL) {
next = ptr->next;
FREE(ptr);
ptr = next;
@@ -96,7 +115,7 @@ st_table *table;
}
#define PTR_NOT_EQUAL(table, ptr, user_key)\
-(ptr != NIL(st_table_entry) && !EQUAL(table->compare, user_key, (ptr)->key))
+(ptr != NULL && !EQUAL(table->compare, user_key, (ptr)->key))
#define FIND_ENTRY(table, hash_val, key, ptr, last) \
(last) = &(table)->bins[hash_val];\
@@ -104,7 +123,7 @@ st_table *table;
while (PTR_NOT_EQUAL((table), (ptr), (key))) {\
(last) = &(ptr)->next; (ptr) = *(last);\
}\
- if ((ptr) != NIL(st_table_entry) && (table)->reorder_flag) {\
+ if ((ptr) != NULL && (table)->reorder_flag) {\
*(last) = (ptr)->next;\
(ptr)->next = (table)->bins[hash_val];\
(table)->bins[hash_val] = (ptr);\
@@ -123,10 +142,10 @@ char **value;
FIND_ENTRY(table, hash_val, key, ptr, last);
- if (ptr == NIL(st_table_entry)) {
+ if (ptr == NULL) {
return 0;
} else {
- if (value != NIL(char *)) {
+ if (value != NULL) {
*value = ptr->record;
}
return 1;
@@ -146,10 +165,10 @@ int *value;
FIND_ENTRY(table, hash_val, key, ptr, last);
- if (ptr == NIL(st_table_entry)) {
+ if (ptr == NULL) {
return 0;
} else {
- if (value != NIL(int)) {
+ if (value != 0) {
*value = (long) ptr->record;
}
return 1;
@@ -187,7 +206,7 @@ char *value;
FIND_ENTRY(table, hash_val, key, ptr, last);
- if (ptr == NIL(st_table_entry)) {
+ if (ptr == NULL) {
if (table->num_entries/table->num_bins >= table->max_density) {
if (rehash(table) == ST_OUT_OF_MEM) {
return ST_OUT_OF_MEM;
@@ -195,7 +214,7 @@ char *value;
hash_val = do_hash(key, table);
}
new = ALLOC(st_table_entry, 1);
- if (new == NIL(st_table_entry)) {
+ if (new == NULL) {
return ST_OUT_OF_MEM;
}
new->key = key;
@@ -227,7 +246,7 @@ char *value;
}
hash_val = do_hash(key, table);
new = ALLOC(st_table_entry, 1);
- if (new == NIL(st_table_entry)) {
+ if (new == NULL) {
return ST_OUT_OF_MEM;
}
new->key = key;
@@ -251,7 +270,7 @@ char ***slot;
FIND_ENTRY(table, hash_val, key, ptr, last);
- if (ptr == NIL(st_table_entry)) {
+ if (ptr == NULL) {
if (table->num_entries / table->num_bins >= table->max_density) {
if (rehash(table) == ST_OUT_OF_MEM) {
return ST_OUT_OF_MEM;
@@ -259,7 +278,7 @@ char ***slot;
hash_val = do_hash(key, table);
}
new = ALLOC(st_table_entry, 1);
- if (new == NIL(st_table_entry)) {
+ if (new == NULL) {
return ST_OUT_OF_MEM;
}
new->key = key;
@@ -267,10 +286,10 @@ char ***slot;
new->next = table->bins[hash_val];
table->bins[hash_val] = new;
table->num_entries++;
- if (slot != NIL(char **)) *slot = &new->record;
+ if (slot != NULL) *slot = &new->record;
return 0;
} else {
- if (slot != NIL(char **)) *slot = &ptr->record;
+ if (slot != NULL) *slot = &ptr->record;
return 1;
}
}
@@ -288,10 +307,10 @@ char ***slot;
FIND_ENTRY(table, hash_val, key, ptr, last);
- if (ptr == NIL(st_table_entry)) {
+ if (ptr == NULL) {
return 0;
} else {
- if (slot != NIL(char **)) {
+ if (slot != NULL) {
*slot = &ptr->record;
}
return 1;
@@ -317,7 +336,7 @@ register st_table *table;
}
table->num_entries = 0;
table->bins = ALLOC(st_table_entry *, table->num_bins);
- if (table->bins == NIL(st_table_entry *)) {
+ if (table->bins == NULL) {
table->bins = old_bins;
table->num_bins = old_num_bins;
table->num_entries = old_num_entries;
@@ -331,7 +350,7 @@ register st_table *table;
/* copy data over */
for (i = 0; i < old_num_bins; i++) {
ptr = old_bins[i];
- while (ptr != NIL(st_table_entry)) {
+ while (ptr != NULL) {
next = ptr->next;
hash_val = do_hash(ptr->key, table);
ptr->next = table->bins[hash_val];
@@ -354,25 +373,25 @@ st_table *old_table;
int i, j, num_bins = old_table->num_bins;
new_table = ALLOC(st_table, 1);
- if (new_table == NIL(st_table)) {
- return NIL(st_table);
+ if (new_table == NULL) {
+ return NULL;
}
*new_table = *old_table;
new_table->bins = ALLOC(st_table_entry *, num_bins);
- if (new_table->bins == NIL(st_table_entry *)) {
+ if (new_table->bins == NULL) {
FREE(new_table);
- return NIL(st_table);
+ return NULL;
}
for(i = 0; i < num_bins ; i++) {
- new_table->bins[i] = NIL(st_table_entry);
+ new_table->bins[i] = NULL;
ptr = old_table->bins[i];
- while (ptr != NIL(st_table_entry)) {
+ while (ptr != NULL) {
new = ALLOC(st_table_entry, 1);
- if (new == NIL(st_table_entry)) {
+ if (new == NULL) {
for (j = 0; j <= i; j++) {
newptr = new_table->bins[j];
- while (newptr != NIL(st_table_entry)) {
+ while (newptr != NULL) {
next = newptr->next;
FREE(newptr);
newptr = next;
@@ -380,7 +399,7 @@ st_table *old_table;
}
FREE(new_table->bins);
FREE(new_table);
- return NIL(st_table);
+ return NULL;
}
*new = *ptr;
new->next = new_table->bins[i];
@@ -405,12 +424,12 @@ char **value;
FIND_ENTRY(table, hash_val, key, ptr ,last);
- if (ptr == NIL(st_table_entry)) {
+ if (ptr == NULL) {
return 0;
}
*last = ptr->next;
- if (value != NIL(char *)) *value = ptr->record;
+ if (value != NULL) *value = ptr->record;
*keyp = ptr->key;
FREE(ptr);
table->num_entries--;
@@ -431,12 +450,12 @@ char **value;
FIND_ENTRY(table, hash_val, key, ptr ,last);
- if (ptr == NIL(st_table_entry)) {
+ if (ptr == NULL) {
return 0;
}
*last = ptr->next;
- if (value != NIL(char *)) *value = ptr->record;
+ if (value != NULL) *value = ptr->record;
*keyp = (long) ptr->key;
FREE(ptr);
table->num_entries--;
@@ -455,7 +474,7 @@ char *arg;
for(i = 0; i < table->num_bins; i++) {
last = &table->bins[i]; ptr = *last;
- while (ptr != NIL(st_table_entry)) {
+ while (ptr != NULL) {
retval = (*func)(ptr->key, ptr->record, arg);
switch (retval) {
case ST_CONTINUE:
@@ -528,11 +547,11 @@ st_table *table;
st_generator *gen;
gen = ALLOC(st_generator, 1);
- if (gen == NIL(st_generator)) {
- return NIL(st_generator);
+ if (gen == NULL) {
+ return NULL;
}
gen->table = table;
- gen->entry = NIL(st_table_entry);
+ gen->entry = NULL;
gen->index = 0;
return gen;
}
@@ -546,16 +565,16 @@ char **value_p;
{
register int i;
- if (gen->entry == NIL(st_table_entry)) {
+ if (gen->entry == NULL) {
/* try to find next entry */
for(i = gen->index; i < gen->table->num_bins; i++) {
- if (gen->table->bins[i] != NIL(st_table_entry)) {
+ if (gen->table->bins[i] != NULL) {
gen->index = i+1;
gen->entry = gen->table->bins[i];
break;
}
}
- if (gen->entry == NIL(st_table_entry)) {
+ if (gen->entry == NULL) {
return 0; /* that's all folks ! */
}
}
@@ -576,21 +595,21 @@ long *value_p;
{
register int i;
- if (gen->entry == NIL(st_table_entry)) {
+ if (gen->entry == NULL) {
/* try to find next entry */
for(i = gen->index; i < gen->table->num_bins; i++) {
- if (gen->table->bins[i] != NIL(st_table_entry)) {
+ if (gen->table->bins[i] != NULL) {
gen->index = i+1;
gen->entry = gen->table->bins[i];
break;
}
}
- if (gen->entry == NIL(st_table_entry)) {
+ if (gen->entry == NULL) {
return 0; /* that's all folks ! */
}
}
*key_p = gen->entry->key;
- if (value_p != NIL(long)) {
+ if (value_p != 0) {
*value_p = (long) gen->entry->record;
}
gen->entry = gen->entry->next;
diff --git a/src/misc/st/st.h b/src/misc/st/st.h
index c51873e9..b15f3c83 100644
--- a/src/misc/st/st.h
+++ b/src/misc/st/st.h
@@ -14,6 +14,10 @@
#ifndef ST_INCLUDED
#define ST_INCLUDED
+#ifdef __cplusplus
+extern "C" {
+#endif
+
typedef struct st_table_entry st_table_entry;
struct st_table_entry {
char *key;
@@ -48,28 +52,28 @@ enum st_retval {ST_CONTINUE, ST_STOP, ST_DELETE};
typedef enum st_retval (*ST_PFSR)();
typedef int (*ST_PFI)();
-EXTERN st_table *st_init_table_with_params ARGS((ST_PFI, ST_PFI, int, int, double, int));
-EXTERN st_table *st_init_table ARGS((ST_PFI, ST_PFI));
-EXTERN void st_free_table ARGS((st_table *));
-EXTERN int st_lookup ARGS((st_table *, char *, char **));
-EXTERN int st_lookup_int ARGS((st_table *, char *, int *));
-EXTERN int st_insert ARGS((st_table *, char *, char *));
-EXTERN int st_add_direct ARGS((st_table *, char *, char *));
-EXTERN int st_find_or_add ARGS((st_table *, char *, char ***));
-EXTERN int st_find ARGS((st_table *, char *, char ***));
-EXTERN st_table *st_copy ARGS((st_table *));
-EXTERN int st_delete ARGS((st_table *, char **, char **));
-EXTERN int st_delete_int ARGS((st_table *, long *, char **));
-EXTERN int st_foreach ARGS((st_table *, ST_PFSR, char *));
-EXTERN int st_strhash ARGS((char *, int));
-EXTERN int st_numhash ARGS((char *, int));
-EXTERN int st_ptrhash ARGS((char *, int));
-EXTERN int st_numcmp ARGS((char *, char *));
-EXTERN int st_ptrcmp ARGS((char *, char *));
-EXTERN st_generator *st_init_gen ARGS((st_table *));
-EXTERN int st_gen ARGS((st_generator *, char **, char **));
-EXTERN int st_gen_int ARGS((st_generator *, char **, long *));
-EXTERN void st_free_gen ARGS((st_generator *));
+extern st_table *st_init_table_with_params (ST_PFI, ST_PFI, int, int, double, int);
+extern st_table *st_init_table (ST_PFI, ST_PFI);
+extern void st_free_table (st_table *);
+extern int st_lookup (st_table *, char *, char **);
+extern int st_lookup_int (st_table *, char *, int *);
+extern int st_insert (st_table *, char *, char *);
+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 *);
+extern int st_delete (st_table *, char **, char **);
+extern int st_delete_int (st_table *, long *, char **);
+extern int st_foreach (st_table *, ST_PFSR, char *);
+extern int st_strhash (char *, int);
+extern int st_numhash (char *, int);
+extern int st_ptrhash (char *, int);
+extern int st_numcmp (char *, char *);
+extern int st_ptrcmp (char *, char *);
+extern st_generator *st_init_gen (st_table *);
+extern int st_gen (st_generator *, char **, char **);
+extern int st_gen_int (st_generator *, char **, long *);
+extern void st_free_gen (st_generator *);
#define ST_DEFAULT_MAX_DENSITY 5
@@ -85,4 +89,8 @@ EXTERN void st_free_gen ARGS((st_generator *));
#define ST_OUT_OF_MEM -10000
+#ifdef __cplusplus
+}
+#endif
+
#endif /* ST_INCLUDED */
diff --git a/src/misc/st/stmm.c b/src/misc/st/stmm.c
index b75b0134..8dfacfe4 100644
--- a/src/misc/st/stmm.c
+++ b/src/misc/st/stmm.c
@@ -8,12 +8,17 @@
*
*/
#include <stdio.h>
-#include "util.h"
+#include "extra.h"
#include "stmm.h"
+#ifndef ABS
+# define ABS(a) ((a) < 0 ? -(a) : (a))
+#endif
+
#define STMM_NUMCMP(x,y) ((x) != (y))
#define STMM_NUMHASH(x,size) (ABS((long)x)%(size))
-#define STMM_PTRHASH(x,size) ((int)((unsigned long)(x)>>2)%size)
+//#define STMM_PTRHASH(x,size) ((int)((unsigned long)(x)>>2)%size) // 64-bit bug fix 9/17/2007
+#define STMM_PTRHASH(x,size) ((int)(((unsigned long)(x)>>2)%size))
#define EQUAL(func, x, y) \
((((func) == stmm_numcmp) || ((func) == stmm_ptrcmp)) ?\
(STMM_NUMCMP((x),(y)) == 0) : ((*func)((x), (y)) == 0))
@@ -41,8 +46,8 @@ stmm_init_table_with_params (compare, hash, size, density, grow_factor,
stmm_table *new;
new = ALLOC (stmm_table, 1);
- if (new == NIL (stmm_table)) {
- return NIL (stmm_table);
+ if (new == NULL) {
+ return NULL;
}
new->compare = compare;
new->hash = hash;
@@ -55,9 +60,9 @@ stmm_init_table_with_params (compare, hash, size, density, grow_factor,
}
new->num_bins = size;
new->bins = ALLOC (stmm_table_entry *, size);
- if (new->bins == NIL (stmm_table_entry *)) {
+ if (new->bins == NULL) {
FREE (new);
- return NIL (stmm_table);
+ return NULL;
}
for (i = 0; i < size; i++) {
new->bins[i] = 0;
@@ -90,7 +95,7 @@ stmm_free_table (table)
for ( i = 0; i < table->num_bins; i++ )
{
ptr = table->bins[i];
- while ( ptr != NIL( stmm_table_entry ) )
+ while ( ptr != NULL )
{
next = ptr->next;
FREE( ptr );
@@ -101,7 +106,7 @@ stmm_free_table (table)
// no need to deallocate entries because they are in the memory manager now
// added by alanmi
if ( table->pMemMan )
- Extra_MmFixedStop (table->pMemMan, 0);
+ Extra_MmFixedStop (table->pMemMan);
FREE (table->bins);
FREE (table);
}
@@ -123,7 +128,7 @@ stmm_clean (table)
#define PTR_NOT_EQUAL(table, ptr, user_key)\
-(ptr != NIL(stmm_table_entry) && !EQUAL(table->compare, user_key, (ptr)->key))
+(ptr != NULL && !EQUAL(table->compare, user_key, (ptr)->key))
#define FIND_ENTRY(table, hash_val, key, ptr, last) \
(last) = &(table)->bins[hash_val];\
@@ -131,7 +136,7 @@ stmm_clean (table)
while (PTR_NOT_EQUAL((table), (ptr), (key))) {\
(last) = &(ptr)->next; (ptr) = *(last);\
}\
- if ((ptr) != NIL(stmm_table_entry) && (table)->reorder_flag) {\
+ if ((ptr) != NULL && (table)->reorder_flag) {\
*(last) = (ptr)->next;\
(ptr)->next = (table)->bins[hash_val];\
(table)->bins[hash_val] = (ptr);\
@@ -150,11 +155,11 @@ stmm_lookup (table, key, value)
FIND_ENTRY (table, hash_val, key, ptr, last);
- if (ptr == NIL (stmm_table_entry)) {
+ if (ptr == NULL) {
return 0;
}
else {
- if (value != NIL (char *))
+ if (value != NULL)
{
*value = ptr->record;
}
@@ -175,11 +180,11 @@ stmm_lookup_int (table, key, value)
FIND_ENTRY (table, hash_val, key, ptr, last);
- if (ptr == NIL (stmm_table_entry)) {
+ if (ptr == NULL) {
return 0;
}
else {
- if (value != NIL (int))
+ if (value != 0)
{
*value = (long) ptr->record;
}
@@ -223,7 +228,7 @@ stmm_insert (table, key, value)
FIND_ENTRY (table, hash_val, key, ptr, last);
- if (ptr == NIL (stmm_table_entry)) {
+ if (ptr == NULL) {
if (table->num_entries / table->num_bins >= table->max_density) {
if (rehash (table) == STMM_OUT_OF_MEM) {
return STMM_OUT_OF_MEM;
@@ -233,7 +238,7 @@ stmm_insert (table, key, value)
// new = ALLOC( stmm_table_entry, 1 );
new = (stmm_table_entry *) Extra_MmFixedEntryFetch (table->pMemMan);
- if (new == NIL (stmm_table_entry)) {
+ if (new == NULL) {
return STMM_OUT_OF_MEM;
}
@@ -269,7 +274,7 @@ stmm_add_direct (table, key, value)
// new = ALLOC( stmm_table_entry, 1 );
new = (stmm_table_entry *) Extra_MmFixedEntryFetch (table->pMemMan);
- if (new == NIL (stmm_table_entry)) {
+ if (new == NULL) {
return STMM_OUT_OF_MEM;
}
@@ -294,7 +299,7 @@ stmm_find_or_add (table, key, slot)
FIND_ENTRY (table, hash_val, key, ptr, last);
- if (ptr == NIL (stmm_table_entry)) {
+ if (ptr == NULL) {
if (table->num_entries / table->num_bins >= table->max_density) {
if (rehash (table) == STMM_OUT_OF_MEM) {
return STMM_OUT_OF_MEM;
@@ -304,7 +309,7 @@ stmm_find_or_add (table, key, slot)
// new = ALLOC( stmm_table_entry, 1 );
new = (stmm_table_entry *) Extra_MmFixedEntryFetch (table->pMemMan);
- if (new == NIL (stmm_table_entry)) {
+ if (new == NULL) {
return STMM_OUT_OF_MEM;
}
@@ -313,12 +318,12 @@ stmm_find_or_add (table, key, slot)
new->next = table->bins[hash_val];
table->bins[hash_val] = new;
table->num_entries++;
- if (slot != NIL (char **))
+ if (slot != NULL)
*slot = &new->record;
return 0;
}
else {
- if (slot != NIL (char **))
+ if (slot != NULL)
*slot = &ptr->record;
return 1;
}
@@ -337,11 +342,11 @@ stmm_find (table, key, slot)
FIND_ENTRY (table, hash_val, key, ptr, last);
- if (ptr == NIL (stmm_table_entry)) {
+ if (ptr == NULL) {
return 0;
}
else {
- if (slot != NIL (char **))
+ if (slot != NULL)
{
*slot = &ptr->record;
}
@@ -368,7 +373,7 @@ rehash (table)
}
table->num_entries = 0;
table->bins = ALLOC (stmm_table_entry *, table->num_bins);
- if (table->bins == NIL (stmm_table_entry *)) {
+ if (table->bins == NULL) {
table->bins = old_bins;
table->num_bins = old_num_bins;
table->num_entries = old_num_entries;
@@ -382,7 +387,7 @@ rehash (table)
/* copy data over */
for (i = 0; i < old_num_bins; i++) {
ptr = old_bins[i];
- while (ptr != NIL (stmm_table_entry)) {
+ while (ptr != NULL) {
next = ptr->next;
hash_val = do_hash (ptr->key, table);
ptr->next = table->bins[hash_val];
@@ -405,15 +410,15 @@ stmm_copy (old_table)
int i, /*j, */ num_bins = old_table->num_bins;
new_table = ALLOC (stmm_table, 1);
- if (new_table == NIL (stmm_table)) {
- return NIL (stmm_table);
+ if (new_table == NULL) {
+ return NULL;
}
*new_table = *old_table;
new_table->bins = ALLOC (stmm_table_entry *, num_bins);
- if (new_table->bins == NIL (stmm_table_entry *)) {
+ if (new_table->bins == NULL) {
FREE (new_table);
- return NIL (stmm_table);
+ return NULL;
}
// allocate the memory manager for the new table
@@ -421,20 +426,20 @@ stmm_copy (old_table)
Extra_MmFixedStart (sizeof (stmm_table_entry));
for (i = 0; i < num_bins; i++) {
- new_table->bins[i] = NIL (stmm_table_entry);
+ new_table->bins[i] = NULL;
ptr = old_table->bins[i];
- while (ptr != NIL (stmm_table_entry)) {
+ while (ptr != NULL) {
// new = ALLOC( stmm_table_entry, 1 );
new =
(stmm_table_entry *) Extra_MmFixedEntryFetch (new_table->
pMemMan);
- if (new == NIL (stmm_table_entry)) {
+ if (new == NULL) {
/*
for ( j = 0; j <= i; j++ )
{
newptr = new_table->bins[j];
- while ( newptr != NIL( stmm_table_entry ) )
+ while ( newptr != NULL )
{
next = newptr->next;
FREE( newptr );
@@ -442,11 +447,11 @@ stmm_copy (old_table)
}
}
*/
- Extra_MmFixedStop (new_table->pMemMan, 0);
+ Extra_MmFixedStop (new_table->pMemMan);
FREE (new_table->bins);
FREE (new_table);
- return NIL (stmm_table);
+ return NULL;
}
*new = *ptr;
new->next = new_table->bins[i];
@@ -471,12 +476,12 @@ stmm_delete (table, keyp, value)
FIND_ENTRY (table, hash_val, key, ptr, last);
- if (ptr == NIL (stmm_table_entry)) {
+ if (ptr == NULL) {
return 0;
}
*last = ptr->next;
- if (value != NIL (char *))
+ if (value != NULL)
*value = ptr->record;
*keyp = ptr->key;
// FREE( ptr );
@@ -500,12 +505,12 @@ stmm_delete_int (table, keyp, value)
FIND_ENTRY (table, hash_val, key, ptr, last);
- if (ptr == NIL (stmm_table_entry)) {
+ if (ptr == NULL) {
return 0;
}
*last = ptr->next;
- if (value != NIL (char *))
+ if (value != NULL)
*value = ptr->record;
*keyp = (long) ptr->key;
// FREE( ptr );
@@ -528,7 +533,7 @@ stmm_foreach (table, func, arg)
for (i = 0; i < table->num_bins; i++) {
last = &table->bins[i];
ptr = *last;
- while (ptr != NIL (stmm_table_entry)) {
+ while (ptr != NULL) {
retval = (*func) (ptr->key, ptr->record, arg);
switch (retval) {
case STMM_CONTINUE:
@@ -604,11 +609,11 @@ stmm_init_gen (table)
stmm_generator *gen;
gen = ALLOC (stmm_generator, 1);
- if (gen == NIL (stmm_generator)) {
- return NIL (stmm_generator);
+ if (gen == NULL) {
+ return NULL;
}
gen->table = table;
- gen->entry = NIL (stmm_table_entry);
+ gen->entry = NULL;
gen->index = 0;
return gen;
}
@@ -622,16 +627,16 @@ stmm_gen (gen, key_p, value_p)
{
register int i;
- if (gen->entry == NIL (stmm_table_entry)) {
+ if (gen->entry == NULL) {
/* try to find next entry */
for (i = gen->index; i < gen->table->num_bins; i++) {
- if (gen->table->bins[i] != NIL (stmm_table_entry)) {
+ if (gen->table->bins[i] != NULL) {
gen->index = i + 1;
gen->entry = gen->table->bins[i];
break;
}
}
- if (gen->entry == NIL (stmm_table_entry)) {
+ if (gen->entry == NULL) {
return 0; /* that's all folks ! */
}
}
@@ -652,21 +657,21 @@ stmm_gen_int (gen, key_p, value_p)
{
register int i;
- if (gen->entry == NIL (stmm_table_entry)) {
+ if (gen->entry == NULL) {
/* try to find next entry */
for (i = gen->index; i < gen->table->num_bins; i++) {
- if (gen->table->bins[i] != NIL (stmm_table_entry)) {
+ if (gen->table->bins[i] != NULL) {
gen->index = i + 1;
gen->entry = gen->table->bins[i];
break;
}
}
- if (gen->entry == NIL (stmm_table_entry)) {
+ if (gen->entry == NULL) {
return 0; /* that's all folks ! */
}
}
*key_p = gen->entry->key;
- if (value_p != NIL (long))
+ if (value_p != 0)
{
*value_p = (long) gen->entry->record;
}
diff --git a/src/misc/st/stmm.h b/src/misc/st/stmm.h
index 1fe3dfd2..4330416e 100644
--- a/src/misc/st/stmm.h
+++ b/src/misc/st/stmm.h
@@ -14,6 +14,10 @@
#ifndef STMM_INCLUDED
#define STMM_INCLUDED
+#ifdef __cplusplus
+extern "C" {
+#endif
+
#include "extra.h"
typedef struct stmm_table_entry stmm_table_entry;
@@ -93,7 +97,7 @@ EXTERN void stmm_clean ARGS ((stmm_table *));
// added by Zhihong: no need for memory allocation
#define stmm_foreach_item2(tb, /* stmm_generator */gen, key, value) \
- for(gen.table=(tb), gen.entry=NIL(stmm_table_entry), gen.index=0; \
+ for(gen.table=(tb), gen.entry=NULL, gen.index=0; \
stmm_gen(&(gen),key,value);)
#define stmm_foreach_item(table, gen, key, value) \
@@ -116,4 +120,8 @@ EXTERN void stmm_clean ARGS ((stmm_table *));
*/
+#ifdef __cplusplus
+}
+#endif
+
#endif /* STMM_INCLUDED */