DEFAULT_SAVE_FREQUENCY
DEFAULT_SAVE_FREQUENCY
If not specified in the constructor, this will be the number of operations between saves
Code used to manage a memory efficient priority queue.
Weights for the queue must be flaots. The queue itself is implemented using heaps
__construct(string $fname, integer $num_values, integer $value_size, string $min_or_max, object $notifier = null, integer $save_frequency = self::DEFAULT_SAVE_FREQUENCY, string $adjust_weight_callback = null)
Makes a priority queue (implemented as an array heap) with the given operating parameters
string | $fname | filename to store the data associated with the queue |
integer | $num_values | number of values the queue can hold |
integer | $value_size | the size in a bytes of a value |
string | $min_or_max | whether this priority queue return least or most weight values when polled |
object | $notifier | object to call when a value changes in the queue |
integer | $save_frequency | how often the data in the queue should be save to disk. (It's default location is RAM) |
string | $adjust_weight_callback | name of a function to be called if an element in the priority has moved because its weight was adjusted this allows other data structures the ability to know where the element has moved to in the priority queue |
poll(integer $i = 1) : mixed
Removes and returns the ith element out of the Priority queue.
Since this is a priority queue the first element in the queue will either be the min or max (depending on queue type) element stored. If $i is not in range an error message is written to the log. This operation also performs a check to see if the queue should be saved to disk
integer | $i | element to get out of the queue |
array data if the value of $i is between 1 and count, false otherwise
insert(string $data, integer $weight) : mixed
Inserts a new item into the priority queue.
string | $data | what to insert into the queue |
integer | $weight | how much the new data should be weighted |
index location in queue where item was stored if successful, otherwise false.
normalize(integer $new_total = \seekquarry\yioop\configs\NUM_URLS_QUEUE_RAM)
Scaless the weights of elements in the queue so that the sum fo the new weights is $new_total
This function is used periodically to prevent the queue from being gummed up because all of the weights stored in it are too small.
integer | $new_total | what the new sum of weights of elements in the queue will be after normalization |
percolateUp(integer $i) : integer
If the $ith element in the PriorityQueue violates the heap property with its parent node (children should be of lower priority than the parent), this function tries modify the heap to restore the heap property.
integer | $i | node to consider in restoring the heap property |
final position $ith node ends up at
percolateDown(integer $i)
If the ith element in the PriorityQueue violates the heap property with some child node (children should be of lower priority than the parent), this function tries modify the heap to restore the heap property.
integer | $i | node to consider in restoring the heap property |
compare(integer $value1, integer $value2) : integer
Computes the difference of the two values $value1 and $value2
Which is subtracted from which is determined by whether this is a min_or_max priority queue
integer | $value1 | a value to take the difference between |
integer | $value2 | the other value |
the differences
putRow(integer $i, array $row)
Add data to the $i row of the priority queue viewed as an array Calls the notifier associated with this queue about the change in data's location
integer | $i | location to add data |
array | $row | data to add (a two element array in the form key, int value). |