Class StorableTree

Description

An implementation of the TreeInSql pattern

We do not keep *anything* in memory here: every function call (children(), parent(), etc) will lead to an SQL request in the underlying storage.

Note that all operations here are O(1) in terms of the number SQL requests, except insertion and deletion which will be O(N).

Database setup:

  1. CREATE TABLE `storabletree` (
  2. `path` varchar(255) NOT NULL default '',
  3. `id` int(11) NOT NULL default '0',
  4. PRIMARY KEY (`path`),
  5. UNIQUE KEY `id` (`id`)
  6. ) TYPE=MyISAM COMMENT='TreeInSql implementation test (KEYLENGTH=4)';

Located in /StorableTree.php (line 54)

Storable
   |
   --StorableTree
Direct descendents
Class Description
Project A project.
Method Summary
void dprint_r ()
string find_empty_slot ([string $p = ''])
void move_subtree (mixed $from, mixed $to)
the parent ()
void save ()
void set_parent ([mixed $p = ''])
an subtree ([mixed $depth = true])
Variables
Methods
direct_children (line 76)
  • return: immediate children of this node
the direct_children ()
dprint_r (line 210)

print a debug version of this leaf

void dprint_r ()
find_empty_slot (line 184)
  • return: an unused slot
  • todo: locking is of course required around this
string find_empty_slot ([string $p = ''])
  • string $p: the parent path
move_subtree (line 127)

This moves all the childs matching the $from pattern to the $to parent pattern

Generally, this replaces $from with $to, taking special measures that no conflict with existing targets exist.

The node exactly matching $from will not be moved, and therefore needs to be done seperatly

void move_subtree (mixed $from, mixed $to)
parent (line 87)
  • return: parent of this node
the parent ()
save (line 171)

overload parent save function to make sure that the 'path' is

proper

void save ()

Redefinition of:
Storable::save()
Save the object in underlying storage.
set_parent (line 101)

change the parent of this node

this takes effect immediatly, without requiring a save()

void set_parent ([mixed $p = ''])
subtree (line 59)
an subtree ([mixed $depth = true])

Inherited Methods

Inherited From Storable

Storable::Storable()
Storable::backup_data()
Storable::connect()
Storable::count()
Storable::disconnect()
Storable::exists()
Storable::feed_hash()
Storable::get()
Storable::get_data()
Storable::handle_result()
Storable::is_limited()
Storable::next()
Storable::num_rows()
Storable::num_rows_unlimited()
Storable::offset()
Storable::remove()
Storable::save()
Storable::set()
Storable::set_data()
Storable::start_request()
Storable::tablename()
Storable::where_clause()

Documentation generated on Tue, 11 Jan 2005 01:38:31 -0500 by phpDocumentor 1.3.0RC3