src/nrbtab.c

Go to the documentation of this file.
00001 /*
00002  * htab.c - table hashing routines 
00003  */
00004 
00005 #include "copyright.h"
00006 #include "config.h"
00007 #include "db.h"
00008 #include "externs.h"
00009 #include "htab.h"
00010 #include "alloc.h"
00011 #include "mudconf.h"
00012 
00013 static int nhrbtab_compare(int left, int right, void *arg)
00014 {
00015         return (right - left);
00016 }
00017 
00018 void nhashinit(RBTAB * htab, int size)
00019 {
00020         memset(htab, 0, sizeof(RBTAB));
00021         htab->tree = rb_init((void *) nhrbtab_compare, NULL);
00022         htab->last = NULL;
00023 }
00024 
00025 void nhashreset(RBTAB * htab)
00026 {
00027         htab->checks = 0;
00028         htab->scans = 0;
00029         htab->hits = 0;
00030 };
00031 
00032 /*
00033  * ---------------------------------------------------------------------------
00034  * * hashfind: Look up an entry in a hash table and return a pointer to its
00035  * * hash data.
00036  */
00037 
00038 void *nhashfind(int val, RBTAB * htab)
00039 {
00040         htab->checks++;
00041         return rb_find(htab->tree, (void *) val);
00042 }
00043 
00044 /*
00045  * ---------------------------------------------------------------------------
00046  * * hashadd: Add a new entry to a hash table.
00047  */
00048 
00049 int nhashadd(int val, void *hashdata, RBTAB * htab)
00050 {
00051         if(rb_exists(htab->tree, (void *) val))
00052                 return (-1);
00053         rb_insert(htab->tree, (void *) val, hashdata);
00054         return 0;
00055 
00056 }
00057 
00058 /*
00059  * ---------------------------------------------------------------------------
00060  * * hashdelete: Remove an entry from a hash table.
00061  */
00062 
00063 void nhashdelete(int val, RBTAB * htab)
00064 {
00065         rb_delete(htab->tree, (void *) val);
00066         return;
00067 }
00068 
00069 /*
00070  * ---------------------------------------------------------------------------
00071  * * hashflush: free all the entries in a hashtable.
00072  */
00073 
00074 void nhashflush(RBTAB * htab, int size)
00075 {
00076         rb_destroy(htab->tree);
00077         htab->tree = rb_init((void *)nhrbtab_compare, NULL);
00078         htab->last = NULL;
00079 }
00080 
00081 /*
00082  * ---------------------------------------------------------------------------
00083  * * hashrepl: replace the data part of a hash entry.
00084  */
00085 
00086 int nhashrepl(int val, void *hashdata, RBTAB * htab)
00087 {
00088         struct int_dict_entry *ent;
00089 
00090         rb_insert(htab->tree, (void *) val, hashdata);
00091     return 1;
00092 }

Generated on Mon May 28 04:25:25 2007 for BattletechMUX by  doxygen 1.4.7