OLD | NEW |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | 1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 /* | 2 /* |
3 * Copyright (c) 2012 Lawrence Livermore National Laboratory | 3 * Copyright (c) 2012 Lawrence Livermore National Laboratory |
4 * | 4 * |
5 * This program is free software; you can redistribute it and/or modify | 5 * This program is free software; you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 2 as | 6 * it under the terms of the GNU General Public License version 2 as |
7 * published by the Free Software Foundation; | 7 * published by the Free Software Foundation; |
8 * | 8 * |
9 * This program is distributed in the hope that it will be useful, | 9 * This program is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
15 * along with this program; if not, write to the Free Software | 15 * along with this program; if not, write to the Free Software |
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
17 * | 17 * |
18 * Author: Peter D. Barnes, Jr. <pdbarnes@llnl.gov> | 18 * Author: Peter D. Barnes, Jr. <pdbarnes@llnl.gov> |
19 */ | 19 */ |
20 | 20 |
21 #ifndef HASH_FNV_H | 21 #ifndef HASH_FNV_H |
22 #define HASH_FNV_H | 22 #define HASH_FNV_H |
23 | 23 |
24 #include "hash-function.h" | 24 #include "hash-function.h" |
25 | 25 |
26 namespace ns3 { | 26 namespace ns3 { |
27 | 27 |
28 namespace Hash { | 28 namespace Hash { |
29 | 29 |
30 namespace Function { | 30 namespace Function { |
31 | 31 |
32 /** | 32 /** |
33 * \ingroup hash | 33 * \ingroup hash |
34 * | 34 * |
35 * \brief Fnv1a hash function implementation | 35 * \brief Fnv1a hash function implementation |
36 * | 36 * |
| 37 * This is the venerable Fowler-Noll-Vo hash, version 1A. (See the |
| 38 * <a href="http://isthe.com/chongo/tech/comp/fnv/">FNV page</a>.) |
| 39 * |
| 40 * The implementation here is taken directly from the published FNV· |
| 41 * <a href="http://isthe.com/chongo/tech/comp/fnv/#FNV-reference-source"> |
| 42 * reference code</a>, |
| 43 * with minor modifications to wrap into this class. See the |
| 44 * hash-fnv.cc file for details. |
| 45 * |
37 */ | 46 */ |
38 class Fnv1a : public Implementation | 47 class Fnv1a : public Implementation |
39 { | 48 { |
40 public: | 49 public: |
41 /** | 50 /** |
| 51 * Constructor |
| 52 */ |
| 53 Fnv1a (); |
| 54 /** |
42 * Compute 32-bit hash of a byte buffer | 55 * Compute 32-bit hash of a byte buffer |
43 * | 56 * |
| 57 * Call clear () between calls to GetHash32() to reset the |
| 58 * internal state and hash each buffer separately. |
| 59 * |
| 60 * If you don't call clear() between calls to GetHash32, |
| 61 * you can hash successive buffers. The final return value |
| 62 * will be the cumulative hash across all calls. |
| 63 * |
44 * \param [in] buffer pointer to the beginning of the buffer | 64 * \param [in] buffer pointer to the beginning of the buffer |
45 * \param [in] size length of the buffer, in bytes | 65 * \param [in] size length of the buffer, in bytes |
46 * \return 32-bit hash of the buffer | 66 * \return 32-bit hash of the buffer |
47 */ | 67 */ |
48 Hash32_t GetHash32 (const char * buffer, const size_t size); | 68 uint32_t GetHash32 (const char * buffer, const size_t size); |
49 /** | 69 /** |
50 * Compute 64-bit hash of a byte buffer. | 70 * Compute 64-bit hash of a byte buffer. |
51 * | 71 * |
| 72 * Call clear () between calls to GetHash64() to reset the |
| 73 * internal state and hash each buffer separately. |
| 74 * |
| 75 * If you don't call clear() between calls to GetHash64, |
| 76 * you can hash successive buffers. The final return value |
| 77 * will be the cumulative hash across all calls. |
| 78 * |
52 * \param [in] buffer pointer to the beginning of the buffer | 79 * \param [in] buffer pointer to the beginning of the buffer |
53 * \param [in] size length of the buffer, in bytes | 80 * \param [in] size length of the buffer, in bytes |
54 * \return 64-bit hash of the buffer | 81 * \return 64-bit hash of the buffer |
55 */ | 82 */ |
56 Hash64_t GetHash64 (const char * buffer, const size_t size); | 83 uint64_t GetHash64 (const char * buffer, const size_t size); |
57 /** | 84 /** |
58 * Restore initial state | 85 * Restore initial state |
59 */ | 86 */ |
60 virtual void clear (void); | 87 virtual void clear (void); |
61 | 88 |
62 private: | 89 private: |
63 /** | 90 /** |
64 * Seed value | 91 * Seed value |
65 */ | 92 */ |
66 enum seed | 93 enum seed |
67 { | 94 { |
68 SEED = 0x8BADF00D // Ate bad food | 95 SEED = 0x8BADF00D // Ate bad food |
69 }; | 96 }; |
| 97 //@{ |
| 98 /** |
| 99 * Cache last hash value, for incremental hashing |
| 100 */ |
| 101 uint32_t m_hash32; |
| 102 uint64_t m_hash64; |
| 103 //@} |
70 | 104 |
71 }; // class Fnv1a | 105 }; // class Fnv1a |
72 | 106 |
73 } // namespace Function | 107 } // namespace Function |
74 | 108 |
75 } // namespace Hash | 109 } // namespace Hash |
76 | 110 |
77 } // namespace ns3 | 111 } // namespace ns3 |
78 | 112 |
79 #endif /* HASH_FNV_H */ | 113 #endif /* HASH_FNV_H */ |
OLD | NEW |