Huffman Zipper  v-1.0
Data Compression and Decompression using Greedy Huffman Algorithm
HashCode.cpp
Go to the documentation of this file.
1 
7 #include"HashCode.h"
8 
9 int hashCode(int key) {
10  return key & HASH_MASK;
11 }
12 
13 int hashCode(bool key) {
14  return hashCode(static_cast<int>(key));
15 }
16 
17 int hashCode(char key) {
18  return hashCode(static_cast<int>(key));
19 }
20 
21 int hashCode(unsigned int key) {
22  return hashCode(static_cast<int>(key));
23 }
24 
25 int hashCode(long key) {
26  return hashCode(static_cast<int>(key));
27 }
28 
29 int hashCode(unsigned long key) {
30  return hashCode(static_cast<int>(key));
31 }
32 
33 int hashCode(short key) {
34  return hashCode(static_cast<int>(key));
35 }
36 
37 int hashCode(unsigned short key) {
38  return hashCode(static_cast<int>(key));
39 }
40 
41 #ifdef _WIN64
42 int hashCode(uintptr_t key) {
43  return hashCode(static_cast<unsigned long>(key));
44 }
45 #endif // _WIN64
46 
47 
48 int hashCode(void* key) {
49  return hashCode(reinterpret_cast<uintptr_t>(key));
50 }
51 
52 int hashCode(const char* base, size_t numBytes) {
53  unsigned hash = HASH_SEED;
54  for (size_t i = 0; i < numBytes; i++) {
55  hash = HASH_MULTIPLIER * hash + base[i];
56  }
57  return hashCode(hash);
58 }
59 
60 int hashCode(const char* str) {
61  return hashCode(str, strlen(str));
62 }
63 
64 int hashCode(const std::string& str) {
65  return hashCode(str.data(), str.length());
66 }
67 
68 int hashCode(double key) {
69  return hashCode(reinterpret_cast<const char*>(&key), sizeof(double));
70 }
71 
72 int hashCode(float key) {
73  return hashCode(reinterpret_cast<const char*>(&key), sizeof(float));
74 }
75 
76 int hashCode(long double key) {
77  return hashCode(reinterpret_cast<const char*>(&key), sizeof(long double));
78 }
int hashCode(int key)
Returns a hash code for the specified key, which is always a nonnegative integer.
Definition: HashCode.cpp:9
This file contains prototype for the hashCode functions used in class HashMap.