Array keys are casted to integers if they look like numbers (WTF?). If a hash
authorJan Schneider <jan@horde.org>
Thu, 16 Dec 2010 13:37:46 +0000 (14:37 +0100)
committerJan Schneider <jan@horde.org>
Thu, 16 Dec 2010 13:37:46 +0000 (14:37 +0100)
happens to be a number, ksort() fails because integers are always sorted after
strings. Add a string to the hash key to make sure it's never casted to an
integer.

framework/Support/lib/Horde/Support/ConsistentHash.php

index 6177f93..ec1820c 100644 (file)
@@ -2,14 +2,14 @@
 /**
  * @category   Horde
  * @package    Support
- * @copyright  2007-2009 The Horde Project (http://www.horde.org/)
+ * @copyright  2007-2010 The Horde Project (http://www.horde.org/)
  * @license    http://opensource.org/licenses/bsd-license.php
  */
 
 /**
  * @category   Horde
  * @package    Support
- * @copyright  2007-2009 The Horde Project (http://www.horde.org/)
+ * @copyright  2007-2010 The Horde Project (http://www.horde.org/)
  * @license    http://opensource.org/licenses/bsd-license.php
  *
  * For a thorough description of consistent hashing, see
@@ -18,8 +18,8 @@
  * http://www8.org/w8-papers/2a-webserver/caching/paper2.html
  *
  * @TODO Ideas for future enhancement:
- *   - provide a callback when a point is moved on the circle, so that the calling
- *     code can take an action (say, tranferring data).
+ *   - provide a callback when a point is moved on the circle, so that the
+ *     calling code can take an action (say, transferring data).
  */
 class Horde_Support_ConsistentHash
 {
@@ -230,7 +230,7 @@ class Horde_Support_ConsistentHash
      */
     public function hash($key)
     {
-        return substr(hash('md5', $key), 0, 8);
+        return 'h' . substr(hash('md5', $key), 0, 8);
     }
 
     /**