added fpHashFunction() and fpEqual()

CVS patchset: 2615
CVS date: 1998/12/26 18:29:32
This commit is contained in:
ewt 1998-12-26 18:29:32 +00:00
parent 429557f9d6
commit 008d124000
2 changed files with 26 additions and 3 deletions

View File

@ -66,3 +66,23 @@ fingerPrint fpLookup(char * fullName, int scareMemory) {
return fp;
}
unsigned int fpHashFunction(const void * key) {
const fingerPrint * fp = key;
unsigned int hash = 0;
char ch;
char * chptr;
ch = 0;
chptr = fp->basename;
while (*chptr) ch ^= *chptr++;
hash |= ch << 24;
hash |= (((fp->dev >> 8) ^ fp->dev) & 0xFF) << 16;
hash |= fp->ino & 0xFFFF;
return hash;
}
int fpEqual(const void * key1, const void * key2) {
return FP_EQUAL(*((const fingerPrint *) key1), *((fingerPrint *) key2));
}

View File

@ -9,12 +9,15 @@ typedef struct fingerprint_s {
/* Be carefull with the memory... assert(*fullName == '/' || !scareMemory) */
fingerPrint fpLookup(char * fullName, int scareMemory);
unsigned int fpHashFunction(const void * string);
int fpEqual(const void * key1, const void * key2);
/* only if !scarceMemory */
#define fpFree(a) free((a).basename)
#define FP_EQUAL(a, b) (((a).dev == (b).dev) && \
((a).ino == (b).ino) && \
!strcmp((a).basename, (b).basename))
#define FP_EQUAL(a, b) ((&(a) == &(b)) || \
(((a).dev == (b).dev) && \
((a).ino == (b).ino) && \
!strcmp((a).basename, (b).basename)))
#endif