// Copyright (C) 2004-2009 Christoph Kubisch & Eike Decker
// This file is part of the "Luxinia Engine".
// For conditions of distribution and use, see copyright notice in luxiniapublicsdk.txt
//
// <Author: Christoph Kubisch>

#ifndef __LUXCORE_CONTHASH_H__
#define __LUXCORE_CONTHASH_H__

#include <luxcore/contvector.h>

#ifdef __cplusplus
extern "C"{
#endif

	//////////////////////////////////////////////////////////////////////////
	// ContHash
	//	A Hash Table (with fixed bins)
	//	By default stores the pointer-value, unless valueSize
	//	is passed on creation, then the entire data from
	//	the pointer passed is copied.

	typedef struct lxContHash_s*	lxContHashPTR;

	// if valueSize > 0 then each hash entry allocates enough space
	// and copies the value on "add", otherwise just stores the
	// pointer itself.

		// numBins must be power of 2
	lxContHashPTR	lxContHash_new(uint numBins, uint valueSize);
	void	lxContHash_delete(lxContHashPTR cv);

	// return true on overwrite
	booln	lxContHash_set(lxContHashPTR cv, uint32 key, void *val);
	// return true on success and stores to outval
	booln	lxContHash_get(const lxContHashPTR cv, uint32 key, void** outval);

	// returns true on success
	booln	lxContHash_remove(lxContHashPTR cv, uint32 key);

	booln	lxContHash_isEmpty(lxContHashPTR cv);

	uint	lxContHash_getCount(const lxContHashPTR cv);
	void*	lxContHash_getNth(const lxContHashPTR cv, uint n);

	uint32	lxContHash_getFirstKey(const lxContHashPTR cv);
	uint32	lxContHash_getNextKey(const lxContHashPTR cv, uint32 key);

	// iterator returns fnData for next call
	typedef void* (lxContHash_Iterator_fn)(void* fnData, uint32 key, void *val);
	// you may remove the current item during iteration
	void	lxContHash_iterate(lxContHashPTR cv, lxContHash_Iterator_fn *itfunc, void *fnData);

	uint	lxContHash_shrink(lxContHashPTR cv);
	float	lxContHash_memRatio(lxContHashPTR cv);


	//////////////////////////////////////////////////////////////////////////
	// ContPtrHash
	//	same as above but optimized for pointer hashing

	typedef struct lxContPtrHash_s*	lxContPtrHashPTR;

	// numBins must be power of 2
	lxContPtrHashPTR	lxContPtrHash_new(uint numBins, uint valueSize);
	void	lxContPtrHash_delete(lxContPtrHashPTR cv);

	// return true on overwrite
	booln	lxContPtrHash_set(lxContPtrHashPTR cv, void* key, void *val);
	// return true on success and stores to outval
	booln	lxContPtrHash_get(const lxContPtrHashPTR cv, void* key, void** outval);
	// returns true on success
	booln	lxContPtrHash_remove(lxContPtrHashPTR cv, void* key);

	booln	lxContPtrHash_isEmpty(lxContPtrHashPTR cv);

	// iterator returns fnData for next call
	typedef void* (lxContPtrHash_Iterator_fn)(void* fnData, void* key, void *val);
	// you may remove the current item during iteration
	void	lxContPtrHash_iterate(lxContPtrHashPTR cv, lxContPtrHash_Iterator_fn *itfunc, void *fnData);


#ifdef __cplusplus
}
#endif


#endif
