1 | <?php |
||
29 | class HashRing { |
||
30 | /** @var Array (location => weight) */ |
||
31 | protected $sourceMap = []; |
||
32 | /** @var Array (location => (start, end)) */ |
||
33 | protected $ring = []; |
||
34 | |||
35 | /** @var Array (location => (start, end)) */ |
||
36 | protected $liveRing; |
||
37 | /** @var Array (location => UNIX timestamp) */ |
||
38 | protected $ejectionExpiries = []; |
||
39 | /** @var integer UNIX timestamp */ |
||
40 | protected $ejectionNextExpiry = INF; |
||
41 | |||
42 | const RING_SIZE = 268435456; // 2^28 |
||
43 | |||
44 | /** |
||
45 | * @param array $map (location => weight) |
||
46 | */ |
||
47 | public function __construct( array $map ) { |
||
80 | |||
81 | /** |
||
82 | * Get the location of an item on the ring |
||
83 | * |
||
84 | * @param string $item |
||
85 | * @return string Location |
||
86 | */ |
||
87 | public function getLocation( $item ) { |
||
92 | |||
93 | /** |
||
94 | * Get the location of an item on the ring, as well as the next locations |
||
95 | * |
||
96 | * @param string $item |
||
97 | * @param integer $limit Maximum number of locations to return |
||
98 | * @return array List of locations |
||
99 | */ |
||
100 | public function getLocations( $item, $limit ) { |
||
129 | |||
130 | /** |
||
131 | * Get the map of locations to weight (ignores 0-weight items) |
||
132 | * |
||
133 | * @return array |
||
134 | */ |
||
135 | public function getLocationWeights() { |
||
138 | |||
139 | /** |
||
140 | * Get a new hash ring with a location removed from the ring |
||
141 | * |
||
142 | * @param string $location |
||
143 | * @return HashRing|bool Returns false if no non-zero weighted spots are left |
||
144 | */ |
||
145 | public function newWithoutLocation( $location ) { |
||
151 | |||
152 | /** |
||
153 | * Remove a location from the "live" hash ring |
||
154 | * |
||
155 | * @param string $location |
||
156 | * @param integer $ttl Seconds |
||
157 | * @return bool Whether some non-ejected locations are left |
||
158 | */ |
||
159 | public function ejectFromLiveRing( $location, $ttl ) { |
||
170 | |||
171 | /** |
||
172 | * Get the "live" hash ring (which does not include ejected locations) |
||
173 | * |
||
174 | * @return HashRing |
||
175 | * @throws UnexpectedValueException |
||
176 | */ |
||
177 | public function getLiveRing() { |
||
206 | |||
207 | /** |
||
208 | * Get the location of an item on the "live" ring |
||
209 | * |
||
210 | * @param string $item |
||
211 | * @return string Location |
||
212 | * @throws UnexpectedValueException |
||
213 | */ |
||
214 | public function getLiveLocation( $item ) { |
||
217 | |||
218 | /** |
||
219 | * Get the location of an item on the "live" ring, as well as the next locations |
||
220 | * |
||
221 | * @param string $item |
||
222 | * @param integer $limit Maximum number of locations to return |
||
223 | * @return array List of locations |
||
224 | * @throws UnexpectedValueException |
||
225 | */ |
||
226 | public function getLiveLocations( $item, $limit ) { |
||
229 | |||
230 | /** |
||
231 | * Get the map of "live" locations to weight (ignores 0-weight items) |
||
232 | * |
||
233 | * @return array |
||
234 | * @throws UnexpectedValueException |
||
235 | */ |
||
236 | public function getLiveLocationWeights() { |
||
239 | } |
||
240 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..