Panda3D
addHash.cxx
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file addHash.cxx
10  * @author drose
11  * @date 2006-09-01
12  */
13 
14 #include "addHash.h"
15 
16 /**
17  * Adds a linear sequence of bytes to the hash.
18  */
19 size_t AddHash::
20 add_hash(size_t start, const uint8_t *bytes, size_t num_bytes) {
21  size_t num_words = num_bytes >> 2;
22  size_t remaining_bytes = num_bytes - (num_words << 2);
23  size_t hash = (size_t)hashword((const uint32_t *)bytes, num_words, (uint32_t)start);
24 
25  switch (remaining_bytes) {
26  case 3:
27  {
28  uint32_t remaining;
29  remaining = (bytes[num_bytes - 3] << 16) | (bytes[num_bytes - 2] << 8) | (bytes[num_bytes - 1]);
30  hash = (size_t)hashword(&remaining, 1, (uint32_t)hash);
31  }
32  break;
33 
34  case 2:
35  {
36  uint32_t remaining;
37  remaining = (bytes[num_bytes - 2] << 8) | (bytes[num_bytes - 1]);
38  hash = (size_t)hashword(&remaining, 1, (uint32_t)hash);
39  }
40  break;
41 
42  case 1:
43  {
44  uint32_t remaining;
45  remaining = (bytes[num_bytes - 1]);
46  hash = (size_t)hashword(&remaining, 1, (uint32_t)hash);
47  }
48  break;
49 
50  default:
51  break;
52  }
53  return hash;
54 }
static size_t add_hash(size_t start, const uint32_t *words, size_t num_words)
Adds a linear sequence of uint32 words to the hash.
Definition: addHash.I:18
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.