A Discrete-Event Network Simulator
API
hash-fnv.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2012 Lawrence Livermore National Laboratory
4  *
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
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
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
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Peter D. Barnes, Jr. <pdbarnes@llnl.gov>
19  *
20  * This copyright notice applies strictly to the wrapper material.
21  *
22  * The FNV source code itself is in the public domain. The FNV source
23  * code sections are marked by
24  * // Begin <fnv-file> ---->
25  * and
26  * // End <fnv-file> ---->
27  * comments.
28  *
29  * Code changes from the FNV distribution are marked with `//PDB'
30  * In addition comment blocks have been converted to Doxygen format.
31  */
32 
33 #include <sys/types.h>
34 #include <stdlib.h>
35 
36 #include "log.h"
37 #include "hash-fnv.h"
38 
46 namespace ns3 {
47 
48 NS_LOG_COMPONENT_DEFINE ("Hash-Fnv");
49 
50 namespace Hash {
51 
52 namespace Function {
53 
55 namespace Fnv1aImplementation {
56 
57 /*************************************************
58  ** class FnvHashImplementation
59  ************************************************/
60 
67 extern "C" {
68 
69 // Changes from FNV distribution are marked with `//PDB'
70 //
71 
72 // Begin fnv.h ----------------------------------->
73 
74 /*
75  * fnv - Fowler/Noll/Vo- hash code
76  *
77  * @(#) $Revision: 5.4 $
78  * @(#) $Id: fnv.h,v 5.4 2009/07/30 22:49:13 chongo Exp $
79  * @(#) $Source: /usr/local/src/cmd/fnv/RCS/fnv.h,v $
80  *
81  ***
82  *
83  * Fowler/Noll/Vo- hash
84  *
85  * The basis of this hash algorithm was taken from an idea sent
86  * as reviewer comments to the IEEE POSIX P1003.2 committee by:
87  *
88  * Phong Vo (http://www.research.att.com/info/kpv/)
89  * Glenn Fowler (http://www.research.att.com/~gsf/)
90  *
91  * In a subsequent ballot round:
92  *
93  * Landon Curt Noll (http://www.isthe.com/chongo/)
94  *
95  * improved on their algorithm. Some people tried this hash
96  * and found that it worked rather well. In an EMail message
97  * to Landon, they named it the ``Fowler/Noll/Vo'' or FNV hash.
98  *
99  * FNV hashes are designed to be fast while maintaining a low
100  * collision rate. The FNV speed allows one to quickly hash lots
101  * of data while maintaining a reasonable collision rate. See:
102  *
103  * http://www.isthe.com/chongo/tech/comp/fnv/index.html
104  *
105  * for more details as well as other forms of the FNV hash.
106  *
107  ***
108  *
109  * NOTE: The FNV-0 historic hash is not recommended. One should use
110  * the FNV-1 hash instead.
111  *
112  * To use the 32 bit FNV-0 historic hash, pass FNV0_32_INIT as the
113  * Fnv32_t hashval argument to fnv_32_buf() or fnv_32_str().
114  *
115  * To use the 64 bit FNV-0 historic hash, pass FNV0_64_INIT as the
116  * Fnv64_t hashval argument to fnv_64_buf() or fnv_64_str().
117  *
118  * To use the recommended 32 bit FNV-1 hash, pass FNV1_32_INIT as the
119  * Fnv32_t hashval argument to fnv_32_buf() or fnv_32_str().
120  *
121  * To use the recommended 64 bit FNV-1 hash, pass FNV1_64_INIT as the
122  * Fnv64_t hashval argument to fnv_64_buf() or fnv_64_str().
123  *
124  * To use the recommended 32 bit FNV-1a hash, pass FNV1_32A_INIT as the
125  * Fnv32_t hashval argument to fnv_32a_buf() or fnv_32a_str().
126  *
127  * To use the recommended 64 bit FNV-1a hash, pass FNV1A_64_INIT as the
128  * Fnv64_t hashval argument to fnv_64a_buf() or fnv_64a_str().
129  *
130  ***
131  *
132  * Please do not copyright this code. This code is in the public domain.
133  *
134  * LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
135  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
136  * EVENT SHALL LANDON CURT NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
137  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
138  * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
139  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
140  * PERFORMANCE OF THIS SOFTWARE.
141  *
142  * By:
143  * chongo <Landon Curt Noll> /\oo/\
144  * http://www.isthe.com/chongo/
145  *
146  * Share and Enjoy! :-)
147  */
148 
149 #if !defined(__FNV_H__)
150 
151 #define __FNV_H__
152 
153 
154 //#include <sys/types.h> //PDB
155 
156 #define FNV_VERSION "5.0.2"
162 typedef u_int32_t Fnv32_t;
163 
164 
171 // Use fully qualified type so this define works outside this scope //PDB
172 #define FNV0_32_INIT ((Fnv1aImplementation::Fnv32_t)0)
173 
174 
187 // Use fully qualified type so this define works outside this scope //PDB
188 #define FNV1_32_INIT ((Fnv1aImplementation::Fnv32_t)0x811c9dc5)
189 
190 #define FNV1_32A_INIT FNV1_32_INIT
191 
192 
196 //#include "longlong.h" //PDB - assume `unsigned long long' is 64 bit
197 #define HAVE_64BIT_LONG_LONG
198 
199 
200 
204 #if defined(HAVE_64BIT_LONG_LONG)
205 typedef u_int64_t Fnv64_t;
206 #else /* HAVE_64BIT_LONG_LONG */
207 typedef struct {
208  u_int32_t w32[2]; /* w32[0] is low order, w32[1] is high order word */
209 } Fnv64_t;
210 #endif /* HAVE_64BIT_LONG_LONG */
211 
212 
219 // Use fully qualified type so this define works outside this scope //PDB
220 #if defined(HAVE_64BIT_LONG_LONG)
221 #define FNV0_64_INIT ((Fnv1aImplementation::Fnv64_t)0)
222 #else /* HAVE_64BIT_LONG_LONG */
223 extern const Fnv64_t fnv0_64_init;
224 #define FNV0_64_INIT (Fnv1aImplementation::fnv0_64_init)
225 #endif /* HAVE_64BIT_LONG_LONG */
226 
227 
240 #if defined(HAVE_64BIT_LONG_LONG)
241 #define FNV1_64_INIT ((Fnv1aImplementation::Fnv64_t)0xcbf29ce484222325ULL)
242 
243 #define FNV1A_64_INIT FNV1_64_INIT
244 #else /* HAVE_64BIT_LONG_LONG */
245 extern const fnv1_64_init;
246 extern const Fnv64_t fnv1a_64_init;
247 #define FNV1_64_INIT (fnv1_64_init)
248 
249 #define FNV1A_64_INIT (fnv1a_64_init)
250 #endif /* HAVE_64BIT_LONG_LONG */
251 
252 
256 enum fnv_type {
257  FNV_NONE = 0,
258  FNV0_32 = 1,
259  FNV1_32 = 2,
260  FNV1a_32 = 3,
261  FNV0_64 = 4,
262  FNV1_64 = 5,
263  FNV1a_64 = 6,
264 };
265 
266 //PDB test vector declarations deleted
267 
268 /*
269  * external functions //PDB converted to forward declarations
270  */
274 /* extern */ Fnv32_t fnv_32_buf(void *buf, size_t len, Fnv32_t hval);
276 /* extern */ Fnv32_t fnv_32_str(char *str, Fnv32_t hval);
277 
278 /* hash_32a.c */
279 /* extern */ Fnv32_t fnv_32a_buf(void *buf, size_t len, Fnv32_t hashval);
280 /* extern */ Fnv32_t fnv_32a_str(char *buf, Fnv32_t hashval);
281 
282 /* hash_64.c */
284 /* extern */ Fnv64_t fnv_64_buf(void *buf, size_t len, Fnv64_t hval);
286 /* extern */ Fnv64_t fnv_64_str(char *str, Fnv64_t hval);
287 
288 /* hash_64a.c */
289 /* extern */ Fnv64_t fnv_64a_buf(void *buf, size_t len, Fnv64_t hashval);
290 /* extern */ Fnv64_t fnv_64a_str(char *buf, Fnv64_t hashval);
291 
292 //PDB test vector declarations deleted
293 
294 
295 #endif /* __FNV_H__ */
296 
297 // End fnv.h ------------------------------->
298 
299 // Begin hash_32a.c ------------------------------>
300 
301 /*
302  * hash_32 - 32 bit Fowler/Noll/Vo FNV-1a hash code
303  *
304  * @(#) $Revision: 5.1 $
305  * @(#) $Id: hash_32a.c,v 5.1 2009/06/30 09:13:32 chongo Exp $
306  * @(#) $Source: /usr/local/src/cmd/fnv/RCS/hash_32a.c,v $
307  *
308  ***
309  *
310  * Fowler/Noll/Vo hash
311  *
312  * The basis of this hash algorithm was taken from an idea sent
313  * as reviewer comments to the IEEE POSIX P1003.2 committee by:
314  *
315  * Phong Vo (http://www.research.att.com/info/kpv/)
316  * Glenn Fowler (http://www.research.att.com/~gsf/)
317  *
318  * In a subsequent ballot round:
319  *
320  * Landon Curt Noll (http://www.isthe.com/chongo/)
321  *
322  * improved on their algorithm. Some people tried this hash
323  * and found that it worked rather well. In an EMail message
324  * to Landon, they named it the ``Fowler/Noll/Vo'' or FNV hash.
325  *
326  * FNV hashes are designed to be fast while maintaining a low
327  * collision rate. The FNV speed allows one to quickly hash lots
328  * of data while maintaining a reasonable collision rate. See:
329  *
330  * http://www.isthe.com/chongo/tech/comp/fnv/index.html
331  *
332  * for more details as well as other forms of the FNV hash.
333  ***
334  *
335  * To use the recommended 32 bit FNV-1a hash, pass FNV1_32A_INIT as the
336  * Fnv32_t hashval argument to fnv_32a_buf() or fnv_32a_str().
337  *
338  ***
339  *
340  * Please do not copyright this code. This code is in the public domain.
341  *
342  * LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
343  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
344  * EVENT SHALL LANDON CURT NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
345  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
346  * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
347  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
348  * PERFORMANCE OF THIS SOFTWARE.
349  *
350  * By:
351  * chongo <Landon Curt Noll> /\oo/\
352  * http://www.isthe.com/chongo/
353  *
354  * Share and Enjoy! :-)
355  */
356 
357 //#include <stdlib.h> //PDB
358 //#include "fnv.h" //PDB
359 
360 
364 #define FNV_32_PRIME ((Fnv1aImplementation::Fnv32_t)0x01000193)
365 
366 
380 Fnv32_t
381 fnv_32a_buf(void *buf, size_t len, Fnv32_t hval)
382 {
383  unsigned char *bp = (unsigned char *)buf; /* start of buffer */
384  unsigned char *be = bp + len; /* beyond end of buffer */
385 
386  /*
387  * FNV-1a hash each octet in the buffer
388  */
389  while (bp < be) {
390 
391  /* xor the bottom with the current octet */
392  hval ^= (Fnv32_t)*bp++;
393 
394  /* multiply by the 32 bit FNV magic prime mod 2^32 */
395 #if defined(NO_FNV_GCC_OPTIMIZATION)
396  hval *= FNV_32_PRIME;
397 #else
398  hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24);
399 #endif
400  }
401 
402  /* return our new hash value */
403  return hval;
404 }
405 
406 
419 Fnv32_t
420 fnv_32a_str(char *str, Fnv32_t hval)
421 {
422  unsigned char *s = (unsigned char *)str; /* unsigned string */
423 
424  /*
425  * FNV-1a hash each octet in the buffer
426  */
427  while (*s) {
428 
429  /* xor the bottom with the current octet */
430  hval ^= (Fnv32_t)*s++;
431 
432  /* multiply by the 32 bit FNV magic prime mod 2^32 */
433 #if defined(NO_FNV_GCC_OPTIMIZATION)
434  hval *= FNV_32_PRIME;
435 #else
436  hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24);
437 #endif
438  }
439 
440  /* return our new hash value */
441  return hval;
442 }
443 
444 // End hash_32a.c -------------------------->
445 
446 // Begin hash_64a.c------------------------------->
447 
448 /*
449  * hash_64 - 64 bit Fowler/Noll/Vo-0 FNV-1a hash code
450  *
451  * @(#) $Revision: 5.1 $
452  * @(#) $Id: hash_64a.c,v 5.1 2009/06/30 09:01:38 chongo Exp $
453  * @(#) $Source: /usr/local/src/cmd/fnv/RCS/hash_64a.c,v $
454  *
455  ***
456  *
457  * Fowler/Noll/Vo hash
458  *
459  * The basis of this hash algorithm was taken from an idea sent
460  * as reviewer comments to the IEEE POSIX P1003.2 committee by:
461  *
462  * Phong Vo (http://www.research.att.com/info/kpv/)
463  * Glenn Fowler (http://www.research.att.com/~gsf/)
464  *
465  * In a subsequent ballot round:
466  *
467  * Landon Curt Noll (http://www.isthe.com/chongo/)
468  *
469  * improved on their algorithm. Some people tried this hash
470  * and found that it worked rather well. In an EMail message
471  * to Landon, they named it the ``Fowler/Noll/Vo'' or FNV hash.
472  *
473  * FNV hashes are designed to be fast while maintaining a low
474  * collision rate. The FNV speed allows one to quickly hash lots
475  * of data while maintaining a reasonable collision rate. See:
476  *
477  * http://www.isthe.com/chongo/tech/comp/fnv/index.html
478  *
479  * for more details as well as other forms of the FNV hash.
480  *
481  ***
482  *
483  * To use the recommended 64 bit FNV-1a hash, pass FNV1A_64_INIT as the
484  * Fnv64_t hashval argument to fnv_64a_buf() or fnv_64a_str().
485  *
486  ***
487  *
488  * Please do not copyright this code. This code is in the public domain.
489  *
490  * LANDON CURT NOLL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
491  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
492  * EVENT SHALL LANDON CURT NOLL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
493  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
494  * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
495  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
496  * PERFORMANCE OF THIS SOFTWARE.
497  *
498  * By:
499  * chongo <Landon Curt Noll> /\oo/\
500  * http://www.isthe.com/chongo/
501  *
502  * Share and Enjoy! :-)
503  */
504 
505 //#include <stdlib.h> //PDB
506 //#include "fnv.h" //PDB
507 
508 
512 #if !defined(HAVE_64BIT_LONG_LONG)
513 const Fnv64_t fnv1a_64_init = { 0x84222325, 0xcbf29ce4 };
514 #endif /* ! HAVE_64BIT_LONG_LONG */
515 
516 
521 #if defined(HAVE_64BIT_LONG_LONG)
522 #define FNV_64_PRIME ((Fnv1aImplementation::Fnv64_t)0x100000001b3ULL)
523 #else /* HAVE_64BIT_LONG_LONG */
524 #define FNV_64_PRIME_LOW ((unsigned long)0x1b3) /* lower bits of FNV prime */
525 #define FNV_64_PRIME_SHIFT (8) /* top FNV prime shift above 2^32 */
526 #endif /* HAVE_64BIT_LONG_LONG */
527 
543 Fnv64_t
544 fnv_64a_buf(void *buf, size_t len, Fnv64_t hval)
545 {
546  unsigned char *bp = (unsigned char *)buf; /* start of buffer */
547  unsigned char *be = bp + len; /* beyond end of buffer */
548 
549 #if defined(HAVE_64BIT_LONG_LONG)
550  /*
551  * FNV-1a hash each octet of the buffer
552  */
553  while (bp < be) {
554 
555  /* xor the bottom with the current octet */
556  hval ^= (Fnv64_t)*bp++;
557 
558  /* multiply by the 64 bit FNV magic prime mod 2^64 */
559 #if defined(NO_FNV_GCC_OPTIMIZATION)
560  hval *= FNV_64_PRIME;
561 #else /* NO_FNV_GCC_OPTIMIZATION */
562  hval += (hval << 1) + (hval << 4) + (hval << 5) +
563  (hval << 7) + (hval << 8) + (hval << 40);
564 #endif /* NO_FNV_GCC_OPTIMIZATION */
565  }
566 
567 #else /* HAVE_64BIT_LONG_LONG */
568 
569  unsigned long val[4]; /* hash value in base 2^16 */
570  unsigned long tmp[4]; /* tmp 64 bit value */
571 
572  /*
573  * Convert Fnv64_t hval into a base 2^16 array
574  */
575  val[0] = hval.w32[0];
576  val[1] = (val[0] >> 16);
577  val[0] &= 0xffff;
578  val[2] = hval.w32[1];
579  val[3] = (val[2] >> 16);
580  val[2] &= 0xffff;
581 
582  /*
583  * FNV-1a hash each octet of the buffer
584  */
585  while (bp < be) {
586 
587  /* xor the bottom with the current octet */
588  val[0] ^= (unsigned long)*bp++;
589 
590  /*
591  * multiply by the 64 bit FNV magic prime mod 2^64
592  *
593  * Using 0x100000001b3 we have the following digits base 2^16:
594  *
595  * 0x0 0x100 0x0 0x1b3
596  *
597  * which is the same as:
598  *
599  * 0x0 1<<FNV_64_PRIME_SHIFT 0x0 FNV_64_PRIME_LOW
600  */
601  /* multiply by the lowest order digit base 2^16 */
602  tmp[0] = val[0] * FNV_64_PRIME_LOW;
603  tmp[1] = val[1] * FNV_64_PRIME_LOW;
604  tmp[2] = val[2] * FNV_64_PRIME_LOW;
605  tmp[3] = val[3] * FNV_64_PRIME_LOW;
606  /* multiply by the other non-zero digit */
607  tmp[2] += val[0] << FNV_64_PRIME_SHIFT; /* tmp[2] += val[0] * 0x100 */
608  tmp[3] += val[1] << FNV_64_PRIME_SHIFT; /* tmp[3] += val[1] * 0x100 */
609  /* propagate carries */
610  tmp[1] += (tmp[0] >> 16);
611  val[0] = tmp[0] & 0xffff;
612  tmp[2] += (tmp[1] >> 16);
613  val[1] = tmp[1] & 0xffff;
614  val[3] = tmp[3] + (tmp[2] >> 16);
615  val[2] = tmp[2] & 0xffff;
616  /*
617  * Doing a val[3] &= 0xffff; is not really needed since it simply
618  * removes multiples of 2^64. We can discard these excess bits
619  * outside of the loop when we convert to Fnv64_t.
620  */
621  }
622 
623  /*
624  * Convert base 2^16 array back into an Fnv64_t
625  */
626  hval.w32[1] = ((val[3]<<16) | val[2]);
627  hval.w32[0] = ((val[1]<<16) | val[0]);
628 
629 #endif /* HAVE_64BIT_LONG_LONG */
630 
631  /* return our new hash value */
632  return hval;
633 }
634 
635 
648 Fnv64_t
649 fnv_64a_str(char *str, Fnv64_t hval)
650 {
651  unsigned char *s = (unsigned char *)str; /* unsigned string */
652 
653 #if defined(HAVE_64BIT_LONG_LONG)
654 
655  /*
656  * FNV-1a hash each octet of the string
657  */
658  while (*s) {
659 
660  /* xor the bottom with the current octet */
661  hval ^= (Fnv64_t)*s++;
662 
663  /* multiply by the 64 bit FNV magic prime mod 2^64 */
664 #if defined(NO_FNV_GCC_OPTIMIZATION)
665  hval *= FNV_64_PRIME;
666 #else /* NO_FNV_GCC_OPTIMIZATION */
667  hval += (hval << 1) + (hval << 4) + (hval << 5) +
668  (hval << 7) + (hval << 8) + (hval << 40);
669 #endif /* NO_FNV_GCC_OPTIMIZATION */
670  }
671 
672 #else /* !HAVE_64BIT_LONG_LONG */
673 
674  unsigned long val[4]; /* hash value in base 2^16 */
675  unsigned long tmp[4]; /* tmp 64 bit value */
676 
677  /*
678  * Convert Fnv64_t hval into a base 2^16 array
679  */
680  val[0] = hval.w32[0];
681  val[1] = (val[0] >> 16);
682  val[0] &= 0xffff;
683  val[2] = hval.w32[1];
684  val[3] = (val[2] >> 16);
685  val[2] &= 0xffff;
686 
687  /*
688  * FNV-1a hash each octet of the string
689  */
690  while (*s) {
691 
692  /* xor the bottom with the current octet */
693 
694  /*
695  * multiply by the 64 bit FNV magic prime mod 2^64
696  *
697  * Using 1099511628211, we have the following digits base 2^16:
698  *
699  * 0x0 0x100 0x0 0x1b3
700  *
701  * which is the same as:
702  *
703  * 0x0 1<<FNV_64_PRIME_SHIFT 0x0 FNV_64_PRIME_LOW
704  */
705  /* multiply by the lowest order digit base 2^16 */
706  tmp[0] = val[0] * FNV_64_PRIME_LOW;
707  tmp[1] = val[1] * FNV_64_PRIME_LOW;
708  tmp[2] = val[2] * FNV_64_PRIME_LOW;
709  tmp[3] = val[3] * FNV_64_PRIME_LOW;
710  /* multiply by the other non-zero digit */
711  tmp[2] += val[0] << FNV_64_PRIME_SHIFT; /* tmp[2] += val[0] * 0x100 */
712  tmp[3] += val[1] << FNV_64_PRIME_SHIFT; /* tmp[3] += val[1] * 0x100 */
713  /* propagate carries */
714  tmp[1] += (tmp[0] >> 16);
715  val[0] = tmp[0] & 0xffff;
716  tmp[2] += (tmp[1] >> 16);
717  val[1] = tmp[1] & 0xffff;
718  val[3] = tmp[3] + (tmp[2] >> 16);
719  val[2] = tmp[2] & 0xffff;
720  /*
721  * Doing a val[3] &= 0xffff; is not really needed since it simply
722  * removes multiples of 2^64. We can discard these excess bits
723  * outside of the loop when we convert to Fnv64_t.
724  */
725  val[0] ^= (unsigned long)(*s++);
726  }
727 
728  /*
729  * Convert base 2^16 array back into an Fnv64_t
730  */
731  hval.w32[1] = ((val[3]<<16) | val[2]);
732  hval.w32[0] = ((val[1]<<16) | val[0]);
733 
734 #endif /* !HAVE_64BIT_LONG_LONG */
735 
736  /* return our new hash value */
737  return hval;
738 }
739 
740 // End hash_64a.c--------------------------->
741 
742 } /* extern "C" */
743 
744 //-----------------------------------------------------------------------------
745  // \defgroup hash_fnv
747 
748 } // namespace Fnv1aImplementation
749 
750 
752 {
753  clear ();
754 }
755 
756 uint32_t
757 Fnv1a::GetHash32 (const char * buffer, const size_t size)
758 {
759  m_hash32 =
760  Fnv1aImplementation::fnv_32a_buf ((void *)buffer, size, m_hash32);
761  return m_hash32;
762 }
763 
764 uint64_t
765 Fnv1a::GetHash64 (const char * buffer, const size_t size)
766 {
767  m_hash64 =
768  Fnv1aImplementation::fnv_64a_buf ((void *)buffer, size, m_hash64);
769  return m_hash64;
770 }
771 
772 void
774 {
777 }
778 
779 } // namespace Function
780 
781 } // namespace Hash
782 
783 } // namespace ns3
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
#define FNV_32_PRIME
32 bit magic FNV-1a prime
Definition: hash-fnv.cc:364
u_int32_t Fnv32_t
32 bit FNV-0 hash type
Definition: hash-fnv.cc:162
ns3::Hash::Function::Fnv1a declaration.
Fnv32_t fnv_32a_buf(void *buf, size_t len, Fnv32_t hashval)
fnv_32a_buf - perform a 32 bit Fowler/Noll/Vo FNV-1a hash on a buffer
Definition: hash-fnv.cc:381
#define FNV1_32A_INIT
32 bit FNV-1 and FNV-1a non-zero initial basis
Definition: hash-fnv.cc:190
uint32_t m_hash32
Cache last hash value, for incremental hashing.
Definition: hash-fnv.h:105
uint64_t GetHash64(const char *buffer, const size_t size)
Compute 64-bit hash of a byte buffer.
Definition: hash-fnv.cc:765
Fnv64_t fnv_64a_buf(void *buf, size_t len, Fnv64_t hashval)
fnv_64a_buf - perform a 64 bit Fowler/Noll/Vo FNV-1a hash on a buffer
Definition: hash-fnv.cc:544
Fnv32_t fnv_32a_str(char *buf, Fnv32_t hashval)
fnv_32a_str - perform a 32 bit Fowler/Noll/Vo FNV-1a hash on a string
Definition: hash-fnv.cc:420
#define FNV1A_64_INIT
64 bit FNV-1 non-zero initial basis
Definition: hash-fnv.cc:243
Fnv64_t fnv_64a_str(char *buf, Fnv64_t hashval)
fnv_64a_str - perform a 64 bit Fowler/Noll/Vo FNV-1a hash on a buffer
Definition: hash-fnv.cc:649
#define FNV_64_PRIME
FNV-1a defines the initial basis to be non-zero.
Definition: hash-fnv.cc:522
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Fnv64_t fnv_64_str(char *str, Fnv64_t hval)
fnv_64a_str - perform a 64 bit Fowler/Noll/Vo FNV-1a hash on a buffer
uint32_t GetHash32(const char *buffer, const size_t size)
Compute 32-bit hash of a byte buffer.
Definition: hash-fnv.cc:757
Fnv32_t fnv_32_str(char *str, Fnv32_t hval)
fnv_32a_str - perform a 32 bit Fowler/Noll/Vo FNV-1a hash on a string
virtual void clear(void)
Restore initial state.
Definition: hash-fnv.cc:773
Debug message logging.
uint64_t m_hash64
Cache last hash value, for incremental hashing.
Definition: hash-fnv.h:106
Fnv64_t fnv_64_buf(void *buf, size_t len, Fnv64_t hval)
fnv_64a_buf - perform a 64 bit Fowler/Noll/Vo FNV-1a hash on a buffer
Fnv1a()
Constructor.
Definition: hash-fnv.cc:751
u_int64_t Fnv64_t
64 bit FNV-0 hash
Definition: hash-fnv.cc:205
Fnv32_t fnv_32_buf(void *buf, size_t len, Fnv32_t hval)
fnv_32a_buf - perform a 32 bit Fowler/Noll/Vo FNV-1a hash on a buffer