\seekquarry\yioop\libraryStringArray

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

Summary

Methods
Properties
Constants
__construct()
load()
save()
checkSave()
get()
put()
$filename
$unsaved_operations
$save_frequency
$num_values
$data_size
$string_array_size
$string_array
DEFAULT_SAVE_FREQUENCY
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Constants

DEFAULT_SAVE_FREQUENCY

DEFAULT_SAVE_FREQUENCY

If not specified in the constructor, this will be the number of operations between saves

Properties

$filename

$filename : string

Name of the file in which to store the PersistentStructure

Type

string

$unsaved_operations

$unsaved_operations : integer

Number of operations since the last save

Type

integer

$save_frequency

$save_frequency : integer

Number of operation between saves. If == -1 never save using checkSave

Type

integer

$num_values

$num_values : integer

Number of items to be stored in the StringArray

Type

integer

$data_size

$data_size : integer

Size of each item in bytes to be stored

Type

integer

$string_array_size

$string_array_size : integer

Number of bytes of storage need by the string array

Type

integer

$string_array

$string_array : string

Character string used to store the packed data of the StringArray

Type

string

Methods

__construct()

__construct(string  $fname, integer  $num_values, integer  $data_size, integer  $save_frequency = self::DEFAULT_SAVE_FREQUENCY) 

Initiliazes 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.

Parameters

string $fname

the name of the file to store data persistently in

integer $num_values

the number of items the StringArray will store

integer $data_size

the size in bytes of a single item

integer $save_frequency

how often the StringArray should be stored to disk

load()

load(string  $fname) : object

Load a StringArray from a file

Parameters

string $fname

the name of the file to load the StringArray from

Returns

object —

the PersistentStructure loaded

save()

save() 

Save the StringArray to its filename

checkSave()

checkSave() 

Add one to the unsaved_operations count. If this goes above the save_frquency then save the PersistentStructure to secondary storage

get()

get(integer  $i) : string

Looks up the ith item in the StringArray

Parameters

integer $i

array index of item to look up

Returns

string —

the looked-up item of length $this->data_size

put()

put(integer  $i, string  $data) 

Puts data into the ith item of the StringArray

Parameters

integer $i

array index of where to store data

string $data

at least $this->data_size many bytes of data to store