#ifndef CACHE_H
# define CACHE_H
# ifndef GPK_STD_H
#  include <gpk_std.h>
# endif
# ifndef GPK_STD_H
#  include <hash.h>
# endif
# include <assert.h>

template<class K, class V>
class readcache	{
	protected:
	int getidx(C K & k) C;
	hashitem<K,V> *tbl;

	private:
	readcache();
	readcache(C readcache<K,V>&);
	operator=(C readcache<K,V>&);

	V (*getdata)(C K&, void *, int);
	int (*hashfunction)(C K&, int);
	int n;

	unsigned hits, misses;
	void *c;
	int nc;

	public:
	readcache(int nn, int(*hashf)(C K&,int), V (*getd)(C K&, void *, int),
					void *cc=0, int ncc=0);
	virtual ~readcache()	{delete [] tbl;}
	BOOL check(C K& k) C;
	C V& get(C K& k);
	C V& operator[](C K& k)	{return get(k);}
	int size() C {return n;}
	int count() C;
	void flush();
	void set_c_nc(void *cc, int ncc=0)	{ flush(); c=cc; nc=ncc; }
	void *get_c() C	{return c;}
	int get_nc() C	{return nc;}
	unsigned num_hits() C	{return hits;}
	unsigned num_misses() C	{return misses;}
	};
#endif
