apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pque...@apache.org
Subject svn commit: r545428 - in /apr/apr-util/trunk: include/apr_memcache.h memcache/apr_memcache.c
Date Fri, 08 Jun 2007 05:52:22 GMT
Author: pquerna
Date: Thu Jun  7 22:52:21 2007
New Revision: 545428

URL: http://svn.apache.org/viewvc?view=rev&rev=545428
Log:
Allow apr_memcache to use a pure CRC32 hash fucntion for server selection.  We maintain the
_default version, since it is identical to what the Perl memcache Client uses.

Fixes PR: 39604

Modified:
    apr/apr-util/trunk/include/apr_memcache.h
    apr/apr-util/trunk/memcache/apr_memcache.c

Modified: apr/apr-util/trunk/include/apr_memcache.h
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/include/apr_memcache.h?view=diff&rev=545428&r1=545427&r2=545428
==============================================================================
--- apr/apr-util/trunk/include/apr_memcache.h (original)
+++ apr/apr-util/trunk/include/apr_memcache.h Thu Jun  7 22:52:21 2007
@@ -116,6 +116,16 @@
                                             const char *data,
                                             apr_size_t data_len);
 
+/**
+ * Pure CRC32 Hash. Used by some clients.
+ */
+APR_DECLARE(apr_uint32_t) apr_memcache_hash_crc32(void *baton,
+                                                    const char *data,
+                                                    apr_size_t data_len);
+
+/**
+ * hash compatible with the standard Perl Client.
+ */
 APR_DECLARE(apr_uint32_t) apr_memcache_hash_default(void *baton,
                                                     const char *data,
                                                     apr_size_t data_len);

Modified: apr/apr-util/trunk/memcache/apr_memcache.c
URL: http://svn.apache.org/viewvc/apr/apr-util/trunk/memcache/apr_memcache.c?view=diff&rev=545428&r1=545427&r2=545428
==============================================================================
--- apr/apr-util/trunk/memcache/apr_memcache.c (original)
+++ apr/apr-util/trunk/memcache/apr_memcache.c Thu Jun  7 22:52:21 2007
@@ -488,7 +488,7 @@
   0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d,
 };
 
-APR_DECLARE(apr_uint32_t) apr_memcache_hash_default(void *baton, 
+APR_DECLARE(apr_uint32_t) apr_memcache_hash_crc32(void *baton, 
                                                     const char *data,
                                                     const apr_size_t data_len)
 {
@@ -499,7 +499,17 @@
     for (i = 0; i < data_len; i++)
         crc = (crc >> 8) ^ crc32tab[(crc ^ (data[i])) & 0xff];
     
-    return ((~crc >> 16) & 0x7fff);
+    return ~crc;
+}
+
+APR_DECLARE(apr_uint32_t) apr_memcache_hash_default(void *baton, 
+                                                    const char *data,
+                                                    const apr_size_t data_len)
+{
+    /* The default Perl Client doesn't actually use just crc32 -- it shifts it again
+     * like this....
+     */
+    return ((apr_memcache_hash_crc32(baton, data, data_len) >> 16) & 0x7fff);
 }
 
 APR_DECLARE(apr_uint32_t) apr_memcache_hash(apr_memcache_t *mc,



Mime
View raw message