usermode/library/common/cuckoo_hash/CHash.h

00001 //metadoc CHash copyright Steve Dekorte 2009
00002 //metadoc CHash license BSD revised
00003 
00004 #ifndef CHASH_DEFINED
00005 #define CHASH_DEFINED 1
00006 
00007 #include "Common.h"
00008 #include <stddef.h>
00009 #include "PortableStdint.h"
00010 
00011 #ifdef __cplusplus
00012 extern "C" {
00013 #endif
00014 
00015 #define CHASH_MAXLOOP 5
00016         
00017 typedef int (CHashEqualFunc)(void *, void *);
00018 typedef intptr_t (CHashHashFunc)(void *);
00019 
00020 typedef struct
00021 {
00022         void *k;
00023         void *v;
00024 } CHashRecord;
00025         
00026 typedef struct
00027 {
00028         unsigned char *records;
00029         size_t size;
00030         size_t keyCount;
00031         CHashHashFunc *hash1;
00032         CHashHashFunc *hash2;
00033         CHashEqualFunc *equals;
00034         intptr_t mask;
00035         int isResizing;
00036 } CHash;
00037 
00038 BASEKIT_API CHash *CHash_new(void);
00039 BASEKIT_API void CHash_copy_(CHash *self, const CHash *other);
00040 BASEKIT_API CHash *CHash_clone(CHash *self);
00041 BASEKIT_API void CHash_free(CHash *self);
00042 
00043 BASEKIT_API void CHash_setHash1Func_(CHash *self, CHashHashFunc *f);
00044 BASEKIT_API void CHash_setHash2Func_(CHash *self, CHashHashFunc *f);
00045 BASEKIT_API void CHash_setEqualFunc_(CHash *self, CHashEqualFunc *f);
00046 
00047 BASEKIT_API void CHash_removeKey_(CHash *self, void *k);
00048 BASEKIT_API void CHash_clear(CHash *self);
00049 BASEKIT_API size_t CHash_size(CHash *self); // actually the keyCount
00050 
00051 BASEKIT_API size_t CHash_memorySize(CHash *self);
00052 BASEKIT_API void CHash_compact(CHash *self);
00053 
00054 // private methods -------------------------------
00055 
00056 BASEKIT_API void CHash_setSize_(CHash *self, size_t size); 
00057 BASEKIT_API int CHash_insert_(CHash *self, CHashRecord *x); 
00058 BASEKIT_API void CHash_grow(CHash *self); 
00059 BASEKIT_API void CHash_shrink(CHash *self); 
00060 BASEKIT_API void CHash_show(CHash *self);
00061 BASEKIT_API void CHash_updateMask(CHash *self); 
00062 BASEKIT_API float CHash_density(CHash *self); 
00063 
00064 #include "CHash_inline.h"
00065 
00066 
00067 #ifdef __cplusplus
00068 }
00069 #endif
00070 #endif

Generated on Sat Apr 23 11:43:34 2011 for Mnemosyne by  doxygen 1.4.7