StringArray
extends PersistentStructure
in package
Memory efficient implementation of persistent arrays
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
Tags
Table of Contents
- DEFAULT_SAVE_FREQUENCY = 50000
- If not specified in the constructor, this will be the number of operations between saves
- $data_size : int
- Size of each item in bytes to be stored
- $filename : string
- Name of the file in which to store the PersistentStructure
- $num_values : int
- Number of items to be stored in the StringArray
- $save_frequency : int
- Number of operation between saves. If == -1 never save using checkSave
- $string_array : string
- Character string used to store the packed data of the StringArray
- $string_array_size : int
- Number of bytes of storage need by the string array
- $unsaved_operations : int
- Number of operations since the last save
- __construct() : mixed
- Initializes the fields of the StringArray and its parent class PersistentStructure. Creates a null filled string array of size $this->string_array_size to stored data in.
- checkSave() : mixed
- Add one to the unsaved_operations count. If this goes above the save_frquency then save the PersistentStructure to secondary storage
- get() : string
- Looks up the ith item in the StringArray
- load() : object
- Load a StringArray from a file
- put() : mixed
- Puts data into the ith item of the StringArray
- save() : mixed
- Save the StringArray to its filename
Constants
DEFAULT_SAVE_FREQUENCY
If not specified in the constructor, this will be the number of operations between saves
public
int
DEFAULT_SAVE_FREQUENCY
= 50000
Properties
$data_size
Size of each item in bytes to be stored
public
int
$data_size
$filename
Name of the file in which to store the PersistentStructure
public
string
$filename
$num_values
Number of items to be stored in the StringArray
public
int
$num_values
$save_frequency
Number of operation between saves. If == -1 never save using checkSave
public
int
$save_frequency
$string_array
Character string used to store the packed data of the StringArray
public
string
$string_array
$string_array_size
Number of bytes of storage need by the string array
public
int
$string_array_size
$unsaved_operations
Number of operations since the last save
public
int
$unsaved_operations
Methods
__construct()
Initializes the fields of the StringArray and its parent class PersistentStructure. Creates a null filled string array of size $this->string_array_size to stored data in.
public
__construct(string $fname, int $num_values, int $data_size[, int $save_frequency = self::DEFAULT_SAVE_FREQUENCY ]) : mixed
Parameters
- $fname : string
-
the name of the file to store data persistently in
- $num_values : int
-
the number of items the StringArray will store
- $data_size : int
-
the size in bytes of a single item
- $save_frequency : int = self::DEFAULT_SAVE_FREQUENCY
-
how often the StringArray should be stored to disk
Return values
mixed —checkSave()
Add one to the unsaved_operations count. If this goes above the save_frquency then save the PersistentStructure to secondary storage
public
checkSave() : mixed
Return values
mixed —get()
Looks up the ith item in the StringArray
public
get(int $i) : string
Parameters
- $i : int
-
array index of item to look up
Return values
string —the looked-up item of length $this->data_size
load()
Load a StringArray from a file
public
static load(string $fname) : object
Parameters
- $fname : string
-
the name of the file to load the StringArray from
Return values
object —the PersistentStructure loaded
put()
Puts data into the ith item of the StringArray
public
put(int $i, string $data) : mixed
Parameters
- $i : int
-
array index of where to store data
- $data : string
-
at least $this->data_size many bytes of data to store
Return values
mixed —save()
Save the StringArray to its filename
public
save() : mixed