00001
00002
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
00035
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
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
00061
00062
00063 void nhashdelete(int val, RBTAB * htab)
00064 {
00065 rb_delete(htab->tree, (void *) val);
00066 return;
00067 }
00068
00069
00070
00071
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
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 }