Panda3D

addHash.cxx

00001 // Filename: addHash.cxx
00002 // Created by:  drose (01Sep06)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "addHash.h"
00016 
00017 ////////////////////////////////////////////////////////////////////
00018 //     Function: AddHash::add_hash
00019 //       Access: Public, Static
00020 //  Description: Adds a linear sequence of bytes to the hash.
00021 ////////////////////////////////////////////////////////////////////
00022 size_t AddHash::
00023 add_hash(size_t start, const PN_uint8 *bytes, size_t num_bytes) {
00024   size_t num_words = num_bytes >> 2;
00025   size_t remaining_bytes = num_bytes - (num_words << 2);
00026   size_t hash = (size_t)hashword((const PN_uint32 *)bytes, num_words, (PN_uint32)start);
00027 
00028   switch (remaining_bytes) {
00029   case 3:
00030     {
00031       PN_uint32 remaining;
00032       remaining = (bytes[num_bytes - 3] << 16) | (bytes[num_bytes - 2] << 8) | (bytes[num_bytes - 1]);
00033       hash = (size_t)hashword(&remaining, 1, (PN_uint32)hash);
00034     }
00035     break;
00036 
00037   case 2:
00038     {
00039       PN_uint32 remaining;
00040       remaining = (bytes[num_bytes - 2] << 8) | (bytes[num_bytes - 1]);
00041       hash = (size_t)hashword(&remaining, 1, (PN_uint32)hash);
00042     }
00043     break;
00044 
00045   case 1:
00046     {
00047       PN_uint32 remaining;
00048       remaining = (bytes[num_bytes - 1]);
00049       hash = (size_t)hashword(&remaining, 1, (PN_uint32)hash);
00050     }
00051     break;
00052 
00053   default:
00054     break;
00055   }
00056   return hash;
00057 }
 All Classes Functions Variables Enumerations