get.c 522 Bytes
#include <search.h>
#include <sys/types.h>

#include "hash.h"
#include "interface/hashable.h"
#include "utils/hash.h"

static
inline
int
hashGetComp(const void * a, const void * b)
{
	return hashableGetHash((void*)b) - *(const unsigned long*)a;
}

void *
hashGet(Hash this, const char * search, size_t nsearch)
{
	unsigned long hash  = sdbm((const unsigned char *)search, nsearch);
	void *        found = tfind(&hash, &(this->root), hashGetComp);

	return (NULL != found)? *(void**)found : NULL;
}

// vim: set ts=4 sw=4: