https://github.com/sokil/php-list
Priority list
https://github.com/sokil/php-list
php priority-list weight-list
Last synced: 29 days ago
JSON representation
Priority list
- Host: GitHub
- URL: https://github.com/sokil/php-list
- Owner: sokil
- License: mit
- Created: 2014-11-23T18:29:29.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2021-02-16T21:41:17.000Z (over 4 years ago)
- Last Synced: 2025-03-30T07:22:30.089Z (about 2 months ago)
- Topics: php, priority-list, weight-list
- Language: PHP
- Size: 29.3 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Lists
=====[](https://travis-ci.org/sokil/php-list)
[](https://packagist.org/packages/sokil/php-list)
[](https://coveralls.io/r/sokil/php-list)
[](https://packagist.org/packages/sokil/php-list)
[](https://packagist.org/packages/sokil/php-list/stats)* [Installation](#installation)
* [Priority List](#priority-list)
* [Weight List](#weight-list)## Installation
You can install library through Composer:
```javascript
{
"require": {
"sokil/php-list": "dev-master"
}
}
```## Priority Map
Priority map allows you to specify priority of items and
iterate through this list in order to priority.Add elements to list with priority:
```php
set('key1', 'value1', 10);
$list->set('key2', 'value2', 100);
```Get elements according to priority:
```php
$value) {
echo $key . ' - ' . $value;
}// this will print
// key2 - value2
// key1 - value1
```Get element by key:
```php
set('key1', 'value1', 10);
$list->get('key1');
```
## Weight ListWeight list allows you to specify values and relative weights, and randomly
get value according to it's weight.Imagine that we have three database servers with ip addresses: 10.0.0.1, 10.0.0.2 and 10.0.0.3.
We want to balance connections between nodes with weights 60%, 30% and 10%. So
most connections goes to server 10.0.0.1, than to 10.0.0.2 and than to 10.0.0.3.```
60,
'10.0.0.2' => 30,
'10.0.0.3' => 10,
]);$ipAddress = $list->getRandomValue();
```
Now we have address on every request relatively to it's weight.