btmux-0.6-rc4/doc/
btmux-0.6-rc4/event/
btmux-0.6-rc4/game/
btmux-0.6-rc4/game/maps/
btmux-0.6-rc4/game/mechs/
btmux-0.6-rc4/game/text/help/
btmux-0.6-rc4/game/text/help/cat_faction/
btmux-0.6-rc4/game/text/help/cat_inform/
btmux-0.6-rc4/game/text/help/cat_misc/
btmux-0.6-rc4/game/text/help/cat_mux/
btmux-0.6-rc4/game/text/help/cat_mux/cat_commands/
btmux-0.6-rc4/game/text/help/cat_mux/cat_functions/
btmux-0.6-rc4/game/text/help/cat_templates/
btmux-0.6-rc4/game/text/wizhelp/
btmux-0.6-rc4/include/
btmux-0.6-rc4/misc/
btmux-0.6-rc4/python/
btmux-0.6-rc4/src/hcode/btech/
btmux-0.6-rc4/tree/
/*
 * htab.c - table hashing routines 
 */

#include "copyright.h"
#include "config.h"
#include "db.h"
#include "externs.h"
#include "htab.h"
#include "alloc.h"
#include "mudconf.h"

static int nhrbtab_compare(int left, int right, void *arg)
{
	return (right - left);
}

void nhashinit(RBTAB * htab, int size)
{
	memset(htab, 0, sizeof(RBTAB));
	htab->tree = rb_init((void *) nhrbtab_compare, NULL);
	htab->last = NULL;
}

void nhashreset(RBTAB * htab)
{
	htab->checks = 0;
	htab->scans = 0;
	htab->hits = 0;
};

/*
 * ---------------------------------------------------------------------------
 * * hashfind: Look up an entry in a hash table and return a pointer to its
 * * hash data.
 */

void *nhashfind(int val, RBTAB * htab)
{
	htab->checks++;
	return rb_find(htab->tree, (void *) val);
}

/*
 * ---------------------------------------------------------------------------
 * * hashadd: Add a new entry to a hash table.
 */

int nhashadd(int val, void *hashdata, RBTAB * htab)
{
	if(rb_exists(htab->tree, (void *) val))
		return (-1);
	rb_insert(htab->tree, (void *) val, hashdata);
	return 0;

}

/*
 * ---------------------------------------------------------------------------
 * * hashdelete: Remove an entry from a hash table.
 */

void nhashdelete(int val, RBTAB * htab)
{
	rb_delete(htab->tree, (void *) val);
	return;
}

/*
 * ---------------------------------------------------------------------------
 * * hashflush: free all the entries in a hashtable.
 */

void nhashflush(RBTAB * htab, int size)
{
	rb_destroy(htab->tree);
	htab->tree = rb_init((void *)nhrbtab_compare, NULL);
	htab->last = NULL;
}

/*
 * ---------------------------------------------------------------------------
 * * hashrepl: replace the data part of a hash entry.
 */

int nhashrepl(int val, void *hashdata, RBTAB * htab)
{
	struct int_dict_entry *ent;

	rb_insert(htab->tree, (void *) val, hashdata);
    return 1;
}