$list[]=$item; // append with the default priority. It may not be the last item if other items in the list are prioritized after the default priority
$list[$index]=$item; // $index must be between 0 and $list->Count-1. This sets the element regardless of priority. Priority stays the same.
$list[$index]=$item; // $index is $list->Count. This appends the item to the end of the list with the same priority as the last item in the list.
unset($list[$index]); // remove the item at $index
if(isset($list[$index])) // if the list has an item at $index
foreach($list as $index=>$item) // traverse each item in the list in proper priority order and add/insert order
$n=count($list); // returns the number of items in the list
To extend TPriorityList for doing your own operations with each addition or removal,
override {@link insertAtIndexInPriority()} and {@link removeAtIndexInPriority()} and then call the parent.
显示文件
Open project: pradosoft/prado
Class Usage Examples
Method | Description | |
---|---|---|
__construct ( $data = null, $readOnly = false, $defaultPriority = 10, $precision = 8 ) | Constructor. | |
add ( $item, $priority = null ) : integer | Appends an item into the list at the end of the specified priority. The position of the added item may not be at the end of the list. | |
clear ( ) | Removes all items in the priority list by calling removeAtIndexInPriority from the last item to the first. | |
contains ( $item ) : boolean | ||
copyFrom ( $data ) | Copies iterable data into the priority list. | |
count ( ) : integer | Returns the number of items in the list. | |
getCount ( ) : integer | Returns the total number of items in the list | |
getDefaultPriority ( ) : numeric | ||
getIterator ( ) : Iterator | Returns an iterator for traversing the items in the list. | |
getPrecision ( ) : integer | ||
getPriorities ( ) : array | This returns a list of the priorities within this list, ordered lowest to highest. | |
getPriorityCount ( $priority = null ) : integer | Gets the number of items at a priority within the list | |
indexOf ( $item ) : integer | ||
insertAfter ( $indexitem, $item ) : integer | This inserts an item after another item within the list. It uses the same priority as the found index item and places the new item after it. | |
insertAt ( $index, $item ) | Inserts an item at an index. It reads the priority of the item at index within the flattened list and then inserts the item at that priority-index. | |
insertAtIndexInPriority ( $item, $index = false, $priority = null, $preserveCache = false ) | Inserts an item at the specified index within a priority. Override and call this method to insert your own functionality. | |
insertBefore ( $indexitem, $item ) : integer | This inserts an item before another item within the list. It uses the same priority as the found index item and places the new item before it. | |
itemAt ( $index ) : mixed | Returns the item at the index of a flattened priority list. | |
itemAtIndexInPriority ( $index, $priority = null ) : mixed | Returns the item at an index within a priority | |
itemsAtPriority ( $priority = null ) : array | Gets all the items at a specific priority. | |
mergeWith ( $data ) | Merges iterable data into the priority list. | |
offsetExists ( $offset ) : boolean | Returns whether there is an element at the specified offset. | |
offsetGet ( $offset ) : mixed | Returns the element at the specified offset. | |
offsetSet ( $offset, $item ) | Sets the element at the specified offset. This method is required by the interface \ArrayAccess. | |
offsetUnset ( $offset ) | Unsets the element at the specified offset. | |
priorityAt ( $index, $withindex = false ) : numeric | array | Retutrns the priority of an item at a particular flattened index. | |
priorityOf ( $item, $withindex = false ) : numeric | array | Returns the priority of a particular item | |
remove ( $item, $priority = false ) : integer | Removes an item from the priority list. | |
removeAt ( $index ) : mixed | Removes an item at the specified index in the flattened list. | |
removeAtIndexInPriority ( $index, $priority = null ) : mixed | Removes the item at a specific index within a priority. Override and call this method to insert your own functionality. | |
toArray ( ) : array | ||
toArrayAbovePriority ( $priority, $inclusive = true ) : array | Combines the map elements which have a priority above the parameter value | |
toArrayBelowPriority ( $priority, $inclusive = false ) : array | Combines the map elements which have a priority below the parameter value | |
toPriorityArray ( ) : array |
Method | Description | |
---|---|---|
flattenPriorities ( ) : array | This flattens the priority list into a flat array [0,. | |
setDefaultPriority ( $value ) | This must be called internally or when instantiated. | |
setPrecision ( $value ) | This must be called internally or when instantiated. | |
sortPriorities ( ) | This orders the priority list internally. |
public __construct ( $data = null, $readOnly = false, $defaultPriority = 10, $precision = 8 ) |
public clear ( ) |
public copyFrom ( $data ) |
protected flattenPriorities ( ) : array | ||
return | array | array of items in the list in priority and index order |
public getDefaultPriority ( ) : numeric | ||
return | numeric | gets the default priority of inserted items without a specified priority |
public getIterator ( ) : Iterator | ||
return | Iterator | an iterator for traversing the items in the list. |
public getPrecision ( ) : integer | ||
return | integer | The precision of numeric priorities, defaults to 8 |
public getPriorities ( ) : array | ||
return | array | the array of priority numerics in decreasing priority order |
public getPriorityCount ( $priority = null ) : integer | ||
return | integer | the number of items in the list at the specified priority |
public insertAfter ( $indexitem, $item ) : integer | ||
return | integer | where the item has been inserted in the flattened list |
public insertAt ( $index, $item ) |
public insertAtIndexInPriority ( $item, $index = false, $priority = null, $preserveCache = false ) |
public insertBefore ( $indexitem, $item ) : integer | ||
return | integer | where the item has been inserted in the flattened list |
public itemAtIndexInPriority ( $index, $priority = null ) : mixed | ||
return | mixed | the element at the offset, false if no element is found at the offset |
public itemsAtPriority ( $priority = null ) : array | ||
return | array | all items at priority in index order, null if there are no items at that priority |
public mergeWith ( $data ) |
public offsetExists ( $offset ) : boolean | ||
return | boolean |
public offsetSet ( $offset, $item ) |
public offsetUnset ( $offset ) |
public priorityAt ( $index, $withindex = false ) : numeric | array | ||
return | numeric | array | the priority of the item in the list, false if not found. if withindex is true, an array is returned of [0 => $priority, 1 => $priorityIndex, 2 => flattenedIndex, 'priority' => $priority, 'index' => $priorityIndex, 'absindex' => flattenedIndex] |
public priorityOf ( $item, $withindex = false ) : numeric | array | ||
return | numeric | array | the priority of the item in the list, false if not found. if withindex is true, an array is returned of [0 => $priority, 1 => $priorityIndex, 2 => flattenedIndex, 'priority' => $priority, 'index' => $priorityIndex, 'absindex' => flattenedIndex] |
public removeAtIndexInPriority ( $index, $priority = null ) : mixed | ||
return | mixed | the removed item. |
protected setDefaultPriority ( $value ) |
protected setPrecision ( $value ) |
protected sortPriorities ( ) |
public toArrayAbovePriority ( $priority, $inclusive = true ) : array | ||
return | array | the array of priorities keys with values of arrays of items that are above a specified priority. The priorities are sorted so important priorities, lower numerics, are first. |
public toArrayBelowPriority ( $priority, $inclusive = false ) : array | ||
return | array | the array of priorities keys with values of arrays of items that are below a specified priority. The priorities are sorted so important priorities, lower numerics, are first. |
public toPriorityArray ( ) : array | ||
return | array | the array of priorities keys with values of arrays of items. The priorities are sorted so important priorities, lower numerics, are first. |