source: trunk/symtab/pbgs_hash_functions.h @ 1742

Last change on this file since 1742 was 1742, checked in by vla24, 7 years ago

SymbolTable?: Fixed custom hashing function for parallel bitstream based grouping

File size: 1.8 KB
Line 
1#ifndef HASH_FUNCTIONS_H
2#define HASH_FUNCTIONS_H
3
4#ifdef DEBUG_HASH_FUNCTION
5#include <stdio.h>
6#endif
7#include "library_conversion.h"
8
9// T is hashvalue type
10// hashBitSize is the number of bits in hashvalue1 and hashvalue2
11// bucketBitSize is the number of bits of the returned value
12// PRE-CONDITION: hashBitSize < bucketBitSize
13template <class T>
14static unsigned int inline shortHashFunction(const T* hashvalue1, const T* hashvalue2, unsigned int hashBitSize, unsigned int bucketBitSize);
15
16// PRE-CONDITION: hashBitSize >= bucketBitSize
17template <class T>
18static unsigned int inline longHashFunction(const T* hashvalue1, const T* hashvalue2, unsigned int hashBitSize, unsigned int bucketBitSize);
19
20
21template <class T>
22inline unsigned int shortHashFunction(const T* hashvalue1, const T* hashvalue2, unsigned int hashBitSize, unsigned int bucketBitSize)
23{
24#ifdef DEBUG_HASH_FUNCTION
25    unsigned int shift = bucketBitSize - hashBitSize;
26    printf ("hashvalue1: %x | hashvalue2: %x | hashBitSize: %i | bucketBitSize: %i\n", *hashvalue1, *hashvalue2, hashBitSize, bucketBitSize);
27    printf ("bucketBitSize - hashBitSize: %i | hashvalue2 << %i = %x\n", shift, shift, (*hashvalue2 << shift));
28#endif
29    return *hashvalue1 ^ (*hashvalue2 << (bucketBitSize - hashBitSize));
30}
31
32template <class T>
33inline unsigned int longHashFunction(const T* hashvalue1, const T* hashvalue2, unsigned int hashBitSize, unsigned int bucketBitSize)
34{
35#ifdef DEBUG_HASH_FUNCTION
36    printf ("hashvalue1: %x | hashvalue2: %x | hashBitSize: %i | bucketBitSize: %i\n", *hashvalue1, *hashvalue2, hashBitSize, bucketBitSize);
37    printf ("hashBitSize - bucketBitSize: %i | hashvalue2 >> %i = %x\n", hashBitSize - bucketBitSize, hashBitSize - bucketBitSize, (*hashvalue2 >> hashBitSize - bucketBitSize));
38#endif
39    return *hashvalue1 ^ (*hashvalue2 >> (hashBitSize - bucketBitSize));
40}
41
42#endif // HASH_FUNCTIONS_H
Note: See TracBrowser for help on using the repository browser.