cppcheck: fix warnings
[awesomized/libmemcached] / libhashkit / jenkins.cc
index c2001cb5b88f88add482532a86c584d1c78d0735..3c6558a42ad9a21d9980dcb8983056f9dd073e1e 100644 (file)
@@ -1,3 +1,40 @@
+/*  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
+ * 
+ *  HashKit library
+ *
+ *  Copyright (C) 2011-2012 Data Differential, http://datadifferential.com/
+ *  Copyright (C) 2006-2009 Brian Aker All rights reserved.
+ *
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions are
+ *  met:
+ *
+ *      * Redistributions of source code must retain the above copyright
+ *  notice, this list of conditions and the following disclaimer.
+ *
+ *      * Redistributions in binary form must reproduce the above
+ *  copyright notice, this list of conditions and the following disclaimer
+ *  in the documentation and/or other materials provided with the
+ *  distribution.
+ *
+ *      * The names of its contributors may not be used to endorse or
+ *  promote products derived from this software without specific prior
+ *  written permission.
+ *
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
 /*
 *
 * By Bob Jenkins, 2006.  bob_jenkins@burtleburtle.net.  You may use this
@@ -56,16 +93,17 @@ use a bitmask.  For example, if you need only 10 bits, do
 In which case, the hash table should have hashsize(10) elements.
 */
 
-uint32_t hashkit_jenkins(const char *key, size_t length, void *context)
+uint32_t hashkit_jenkins(const char *key, size_t length, void *)
 {
   uint32_t a,b,c;                                          /* internal state */
-  union { const void *ptr; size_t i; } u;     /* needed for Mac Powerbook G4 */
-  (void)context;
+#ifndef WORDS_BIGENDIAN
+  union { const void *ptr; size_t i; } u;
+  u.ptr = key;
+#endif
 
   /* Set up the internal state */
   a = b = c = 0xdeadbeef + ((uint32_t)length) + JENKINS_INITVAL;
 
-  u.ptr = key;
 #ifndef WORDS_BIGENDIAN
   if ((u.i & 0x3) == 0)
   {
@@ -135,23 +173,28 @@ uint32_t hashkit_jenkins(const char *key, size_t length, void *context)
              b+=k[2]+(((uint32_t)k[3])<<16);
              a+=k[0]+(((uint32_t)k[1])<<16);
              break;
-    case 11: c+=((uint32_t)k8[10])<<16;     /* fall through */
+    case 11: c+=((uint32_t)k8[10])<<16;
+             /* fall through */
     case 10: c+=k[4];
              b+=k[2]+(((uint32_t)k[3])<<16);
              a+=k[0]+(((uint32_t)k[1])<<16);
              break;
-    case 9 : c+=k8[8];                      /* fall through */
+    case 9 : c+=k8[8];
+             /* fall through */
     case 8 : b+=k[2]+(((uint32_t)k[3])<<16);
              a+=k[0]+(((uint32_t)k[1])<<16);
              break;
-    case 7 : b+=((uint32_t)k8[6])<<16;      /* fall through */
+    case 7 : b+=((uint32_t)k8[6])<<16;
+             /* fall through */
     case 6 : b+=k[2];
              a+=k[0]+(((uint32_t)k[1])<<16);
              break;
-    case 5 : b+=k8[4];                      /* fall through */
+    case 5 : b+=k8[4];
+             /* fall through */
     case 4 : a+=k[0]+(((uint32_t)k[1])<<16);
              break;
-    case 3 : a+=((uint32_t)k8[2])<<16;      /* fall through */
+    case 3 : a+=((uint32_t)k8[2])<<16;
+             /* fall through */
     case 2 : a+=k[0];
              break;
     case 1 : a+=k8[0];
@@ -190,16 +233,27 @@ uint32_t hashkit_jenkins(const char *key, size_t length, void *context)
     switch(length)                   /* all the case statements fall through */
     {
     case 12: c+=((uint32_t)k[11])<<24;
+             /* fall through */
     case 11: c+=((uint32_t)k[10])<<16;
+             /* fall through */
     case 10: c+=((uint32_t)k[9])<<8;
+             /* fall through */
     case 9 : c+=k[8];
+             /* fall through */
     case 8 : b+=((uint32_t)k[7])<<24;
+             /* fall through */
     case 7 : b+=((uint32_t)k[6])<<16;
+             /* fall through */
     case 6 : b+=((uint32_t)k[5])<<8;
+             /* fall through */
     case 5 : b+=k[4];
+             /* fall through */
     case 4 : a+=((uint32_t)k[3])<<24;
+             /* fall through */
     case 3 : a+=((uint32_t)k[2])<<16;
+             /* fall through */
     case 2 : a+=((uint32_t)k[1])<<8;
+             /* fall through */
     case 1 : a+=k[0];
              break;
     case 0 : return c;