Sha256: 74755cd34779b98d477f264d36d22446b64957b6c3da56c460fb7827dcd8b287

Contents?: true

Size: 1.1 KB

Versions: 7

Compression:

Stored size: 1.1 KB

Contents

<?php

namespace Predis\Distribution;

class KetamaPureRing extends HashRing {
    const DEFAULT_REPLICAS = 160;

    public function __construct() {
        parent::__construct($this::DEFAULT_REPLICAS);
    }

    protected function addNodeToRing(&$ring, $node, $totalNodes, $replicas, $weightRatio) {
        $nodeObject = $node['object'];
        $nodeHash = $this->getNodeHash($nodeObject);
        $replicas = (int) floor($weightRatio * $totalNodes * ($replicas / 4));
        for ($i = 0; $i < $replicas; $i++) {
            $unpackedDigest = unpack('V4', md5("$nodeHash-$i", true));
            foreach ($unpackedDigest as $key) {
                $ring[$key] = $nodeObject;
            }
        }
    }

    public function generateKey($value) {
        $hash = unpack('V', md5($value, true));
        return $hash[1];
    }

    protected function wrapAroundStrategy($upper, $lower, $ringKeysCount) {
        // Binary search for the first item in _ringkeys with a value greater
        // or equal to the key. If no such item exists, return the first item.
        return $lower < $ringKeysCount ? $lower : 0;
    }
}

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
appstats-0.25.1 doc/benchmarks/Predis/Distribution/KetamaPureRing.php
appstats-0.25.0 doc/benchmarks/Predis/Distribution/KetamaPureRing.php
appstats-0.24.0 doc/benchmarks/Predis/Distribution/KetamaPureRing.php
appstats-0.23.5 doc/benchmarks/Predis/Distribution/KetamaPureRing.php
appstats-0.23.4 doc/benchmarks/Predis/Distribution/KetamaPureRing.php
appstats-0.23.3 doc/benchmarks/Predis/Distribution/KetamaPureRing.php
appstats-0.23.2 doc/benchmarks/Predis/Distribution/KetamaPureRing.php