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 hash table Weights for the queue must be flaots
The standard array objects in php and even spl have a large amount of overhead. The point of this class is to have the size as close to the optimal as possible
$deleted : string
Holds \0\0 followed by an all \FF string of length $this->key_size -1 Used to indicate that a slot once held data but that data was deleted.
Such a slot tells a lookup to keep going, but on an insert can be overwritten in the inserted key is not already in the table
__construct(string $fname, integer $num_values, integer $key_size, integer $value_size, integer $save_frequency = self::DEFAULT_SAVE_FREQUENCY)
Makes a persistently stored (i.e., on disk and ram) hash table using the supplied parameters
string | $fname | filename to use when storing the hash table to disk |
integer | $num_values | number of key value pairs the table can hold |
integer | $key_size | number of bytes to store a hash table key |
integer | $value_size | number of bytes to store a hash table value |
integer | $save_frequency | how many non read operation before saving to disk |
insert(string $key, string $value, integer $probe = false) : boolean
Inserts the provided $key - $value pair into the hash table
string | $key | the key to use for the insert (will be needed for lookup) |
string | $value | the value associated with $key |
integer | $probe | if the location in the hash table is already known to be $probe then this variable can be used to save a lookup |
whether the insert was successful or not
lookup(string $key, integer $return_probe_value = self::RETURN_VALUE) : mixed
Tries to lookup the key in the hash table either return the location where it was found or the value associated with the key.
string | $key | key to look up in the hash table |
integer | $return_probe_value | one of self::ALWAYS_RETURN_PROBE, self::RETURN_PROBE_ON_KEY_FOUND, self::RETURN_VALUE, or self::BOTH. Here value means the value associated with the key and probe is either the location in the array where the key was found or the first location in the array where it was determined the key could not be found. |
would be string if the value is being returned, an int if the probe is being returned, and false if the key is not found
lookupArray(string $key, array $null_array, integer $return_probe_value = self::RETURN_VALUE) : mixed
Tries to lookup the key in the hash table either return the location where it was found or the value associated with the key.
If the key is not at the initial probe value, linear search in the table is done. The values which cut-off the search are stored in $null_array. Using an array allows for flexibility since a deleted entry needs to be handled different when doing a lookup then when doing an insert.
string | $key | key to look up in the hash table |
array | $null_array | key values that would cut-off the search for key if the initial probe failed |
integer | $return_probe_value | one of self::ALWAYS_RETURN_PROBE, self::RETURN_PROBE_ON_KEY_FOUND, or self::RETURN_VALUE. Here value means the value associated with the key and probe is either the location in the array where the key was found or the first location in the array where it was determined the key could not be found. |
would be string if the value is being returned, an int if the probe is being returned, and false if the key is not found
delete(string $key, integer $probe = false) : boolean
Deletes the data associated with the provided key from the hash table
string | $key | the key to delete the entry for |
integer | $probe | if the location in the hash table is already known to be $probe then this variable can be used to save a lookup |
whether or not something was deleted