libmemcached: fix #41 (ensure stable sort on host key collision)
authorMichael Wallner <mike@php.net>
Tue, 21 Jan 2020 16:38:13 +0000 (17:38 +0100)
committerMichael Wallner <mike@php.net>
Tue, 21 Jan 2020 16:38:13 +0000 (17:38 +0100)
libmemcached/hosts.cc

index 97f7c35b74d50ddd15fbd8169a02403f3520dec5..98cb3f7d48dc777c1d4ca18f1c3f75b7a471f771 100644 (file)
@@ -120,7 +120,18 @@ static int continuum_item_cmp(const void *t1, const void *t2)
   WATCHPOINT_ASSERT(ct1->value != 153);
   if (ct1->value == ct2->value)
   {
-    return 0;
+    if (ct1->index == ct2->index)
+    {
+      return 0;
+    }
+    else if (ct1->index > ct2->index)
+    {
+      return 1;
+    }
+    else
+    {
+      return -1;
+    }
   }
   else if (ct1->value > ct2->value)
   {