Ori.livneh has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/118962

Change subject: HashRing constructor: accept a list of locations and a 'weight' 
arg
......................................................................

HashRing constructor: accept a list of locations and a 'weight' arg

This bit of syntactic sugar makes it easier to intialize a HashRing where all
locatiosn are to be assigned the same weight.

Change-Id: Ibdc61bf3a1648bd8fe175c3896c27a25e2186cc5
---
M includes/libs/HashRing.php
1 file changed, 14 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/62/118962/1

diff --git a/includes/libs/HashRing.php b/includes/libs/HashRing.php
index 6925c7f..ace3505 100644
--- a/includes/libs/HashRing.php
+++ b/includes/libs/HashRing.php
@@ -35,12 +35,20 @@
        const RING_SIZE = 268435456; // 2^28
 
        /**
-        * @param array $map (location => weight)
-        */
-       public function __construct( array $map ) {
-               $map = array_filter( $map, function ( $w ) {
-                       return $w > 0;
-               } );
+        * @param array $map If the $weight parameter is unset, $map should be 
an
+        *   associative array mapping locations to weights. If $weight is set,
+        *   $map should be a list of locations. They will each be assigned a
+        *   weight of $weight.
+        * @param int|null $weight If set, specifies the weight to assign all
+        *   locations in the $map hash.
+     */
+       public function __construct( array $map, int $weight = null ) {
+
+               if ( is_int( $weight) ) {
+                       $map = array_fill_keys( array_keys( $map, $weight ) );
+               }
+               $map = array_filter( $map );
+
                if ( !count( $map ) ) {
                        throw new UnexpectedValueException( "Ring is empty or 
all weights are zero." );
                }

-- 
To view, visit https://gerrit.wikimedia.org/r/118962
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibdc61bf3a1648bd8fe175c3896c27a25e2186cc5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to