1 | <?php |
||
12 | class Partition extends Map |
||
13 | { |
||
14 | |||
15 | /** |
||
16 | * The algorithm in use. |
||
17 | * |
||
18 | * @var PartitionAlgorithmInterface |
||
19 | */ |
||
20 | protected $algo; |
||
21 | |||
22 | /** |
||
23 | * Partition constructor. |
||
24 | * |
||
25 | * @param PartitionItem[] $elements |
||
26 | * The list of elements. |
||
27 | */ |
||
28 | 14 | public function __construct(array $elements = array()) |
|
33 | |||
34 | /** |
||
35 | * Add an item to the partition. |
||
36 | * |
||
37 | * @param PartitionItem $item |
||
38 | * The item to add to the partition. |
||
39 | * |
||
40 | * @return $this |
||
41 | * Return itself. |
||
42 | */ |
||
43 | 14 | public function addItem(PartitionItem $item) |
|
49 | |||
50 | /** |
||
51 | * Add items to the partition. |
||
52 | * |
||
53 | * @param PartitionItem[] $items |
||
54 | * The items to add to the partition. |
||
55 | * |
||
56 | * @return $this |
||
57 | * Return itself. |
||
58 | */ |
||
59 | 14 | public function addItems(array $items = array()) |
|
67 | |||
68 | /** |
||
69 | * Get an array of original items. |
||
70 | * |
||
71 | * @return array |
||
72 | * The original items. |
||
73 | */ |
||
74 | 14 | public function getRawItems() |
|
82 | |||
83 | /** |
||
84 | * Get the weight of the partition. |
||
85 | * |
||
86 | * @return int |
||
87 | * The partition's weight. |
||
88 | */ |
||
89 | 11 | public function getWeight() |
|
96 | |||
97 | /** |
||
98 | * Set the algorithm to use. |
||
99 | * |
||
100 | * @param BasePartitionAlgorithm $algo |
||
101 | * The algorithm to use. |
||
102 | */ |
||
103 | 14 | public function setAlgo(BasePartitionAlgorithm $algo) |
|
107 | |||
108 | /** |
||
109 | * Get the algorithm in use. |
||
110 | * |
||
111 | * @return PartitionAlgorithmInterface |
||
112 | * The algorithm in use. |
||
113 | */ |
||
114 | 14 | public function getAlgo() |
|
118 | |||
119 | /** |
||
120 | * Delete items from the partition. |
||
121 | * |
||
122 | * @param PartitionItem[] $items |
||
123 | * The items to delete. |
||
124 | */ |
||
125 | 3 | public function deleteItems(array $items = array()) |
|
131 | |||
132 | /** |
||
133 | * Delete an item from the partition. |
||
134 | * |
||
135 | * @param PartitionItem $item |
||
136 | * The item to delete. |
||
137 | */ |
||
138 | 3 | public function delete(PartitionItem $item) |
|
142 | |||
143 | /** |
||
144 | * Sort the items of the partition in a particular order. |
||
145 | * |
||
146 | * @param string $order |
||
147 | * ASC for ascending, DESC for descending. |
||
148 | * |
||
149 | * @return $this |
||
150 | */ |
||
151 | 11 | public function sortByValue($order = 'ASC') |
|
167 | } |
||
168 |