PersistentStructure
in package
A PersistentStructure is a data structure which every so many operations will be saved to secondary storage (such as disk).
An operation occurs whenever the PersistentStructure's checkSave method is called. A PersistentStructure also supports the ability to be load (read in from) secondary storage.
Tags
Table of Contents
- DEFAULT_SAVE_FREQUENCY = 50000
- If not specified in the constructor, this will be the number of operations between saves
- $filename : string
- Name of the file in which to store the PersistentStructure
- $save_frequency : int
- Number of operation between saves. If == -1 never save using checkSave
- $unsaved_operations : int
- Number of operations since the last save
- __construct() : mixed
- Sets up the file name and save frequency for the PersistentStructure, initializes the oepration count
- checkSave() : mixed
- Add one to the unsaved_operations count. If this goes above the save_frquency then save the PersistentStructure to secondary storage
- load() : object
- Load a PersistentStructure from a file
- save() : mixed
- Save the PersistentStructure to its filename This method is generic but super memory inefficient, so reimplement for subclasses is needed
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
$filename
Name of the file in which to store the PersistentStructure
public
string
$filename
$save_frequency
Number of operation between saves. If == -1 never save using checkSave
public
int
$save_frequency
$unsaved_operations
Number of operations since the last save
public
int
$unsaved_operations
Methods
__construct()
Sets up the file name and save frequency for the PersistentStructure, initializes the oepration count
public
__construct(string $fname[, int $save_frequency = self::DEFAULT_SAVE_FREQUENCY ]) : mixed
Parameters
- $fname : string
-
the name of the file to store the PersistentStructure in
- $save_frequency : int = self::DEFAULT_SAVE_FREQUENCY
-
the number of operation before a save If <= 0 never check save
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 —load()
Load a PersistentStructure from a file
public
static load(string $fname) : object
Parameters
- $fname : string
-
the name of the file to load the PersistentStructure from
Return values
object —the PersistentStructure loaded
save()
Save the PersistentStructure to its filename This method is generic but super memory inefficient, so reimplement for subclasses is needed
public
save() : mixed