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