Download the PHP package phillipsdata/priority-schedule without Composer
On this page you can find all versions of the php package phillipsdata/priority-schedule. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download phillipsdata/priority-schedule
More information about phillipsdata/priority-schedule
Files in phillipsdata/priority-schedule
Package priority-schedule
Short Description A priority schedule library
License MIT
Homepage http://github.com/phillipsdata/priority-schedule
Informations about the package priority-schedule
Priority Schedule
A priority schedule library.
This library provides data structures for performing Round Robin and First Available access to items.
Installation
Usage
There are two built-in priority schedules:
- Round Robin
- Returns the item with the least weight such that the weight of each of the items is proportional.
- First Available
- Returns items in the order added added (FIFO) such that only valid items are returned.
Round Robin
The Round Robin schedule allows you retrieve items in an evenly distributed manner, by specifying a comparator that defines the priority for items returned.
Suppose you have 3 bucket objects:
Bucket | Count |
---|---|
A | 0 |
B | 2 |
C | 4 |
Assuming each time we retrieve a bucket we increment its count, then add it back to the schedule, we would expect to retrieve buckets in the following order:
Output:
First Available
The First Available schedule allows you to retrieve elements in the order in which they were added (FIFO), skipping elements that are not eligible (think of the line to get into a night club) using a callback.
Suppose you have 3 bucket objects:
Bucket | Count |
---|---|
A | 0 |
B | 2 |
C | 4 |
Assuming each time we retrieve a bucket we decrement its count, then add it back to the schedule, we would expect to retrieve buckets in the following order:
This is because once a bucket reaches 0
we no longer consider it valid.
Output: