
metatable
IMPORTANT: Project has moved to github because of power of Git :-)
What is metatable?
metatable aims to provide simple interface to store and retrieve data. It is written entirely in PHP and uses only basic PHP functions, so no extensions are needed. But still metatable should be fast enough to be used as storage backend in some sort of applications. Data are stored in binary file in metatable's own format.
Data representation
metatable is big hashmap, which associates (row : string, column : string)
pair
to value. Currently supported value types are: string
, int
(32bit) and boolean
.
string
is uninterpreted, so other types may be stored in their binary form as
string
. Maximal lengths of row
and col
are 124 bytes.
metatable file is composed from frames and structure of frames written at the end
of file. Frames are named, name of frame consists from 4 bytes (there is possibility
to have at most 2^32 frames). Data itself are stored as sorted set of fixed-size
records in data
frame. Values of type string
are stored in another frame called
strs
. The last basic frame is indx
where „indexes“ are stored.
Basic usage
To open up metatable file use metatable::open()
:
```
$table = metatable::open('foo'); ```
Either FALSE
or newly created instance of metatable
is returned. metatable
object has only a few public methods – get()
, set()
, index()
, unindex()
and
close()
. get()
and set()
are used to retrieve and store values. When passing
NULL
to set()
as value, record is deleted.
``` $table->set('foo', 'bar', 5);
$table->get('foo', 'bar'); // => array('foo' => array('bar' => 5))
$table->set('foo', 'bar', NULL);
$table->get('foo', 'bar'); // => array() ```
index()
and unindex()
creates and drops indexes. Index is precomputed saved
value, where data are stored in data
frame. Indexes can be created only of there
are some values to index.
The last method close()
saves structure informations and closes metatable file.
metatable is constructed in way that each instance is „transaction“ – all
operations are performed or none of them – data integrity is assured.
Advanced usage
metatable::open()
flags
metatable::open()
takes two arguments – $filename
and $flags
, where $flags
is integer – or
-ed list of flags defined in metatable
class constants. Possible
flags are:
READONLY
– metatable is opened readonly, cannot doset()
and is not saved on closing (defautly turned off)READWRITE
– all operations are possible (defaulty on)STRINGS_GC
– strings are garbage collected (defaultly on)AUTOCLOSE
– automatically saved on instance destruction (defaultly off)
What next?
That is all of metatable. If you want to try, go to download section.