Attention needed

Saeghe is a difficult name to pronounce. Therefore, Saeghe project has been renamed to phpkg.

This website no longer receives updates.

Please visit phpkg website at phpkg.com

Introduction

The Tree class is part of the Datatype package. You can use this class to define any tree structures. Here you can see its API and see how to use it.

Usage

You can make a new instance of this class by passing a root to the constructor and then use the following methods:

$tree = new Tree('/');

assert_true($tree->root === '/');
assert_true($tree->vertices() instanceof Collection);
assert_true($tree->edges() instanceof Collection);
assert_true(['/'] === $tree->vertices()->items());
assert_true([] === $tree->edges()->items());

Methods

Here you can see a list of the available methods on the tree:


edge

Signature

public function edge($vertex, $leaf): static

Definition

It adds an edge to the tree.

Examples

$tree = new Tree('/');
$tree->edge('/', 'home');
assert_true(['/', 'home'] === $tree->vertices()->items());
assert_true([new Pair('/', 'home')] == $tree->edges()->items());

edges

Signature

public function edges(): Collection

Definition

It returns a collection of defined edges.

Examples

$tree = new Tree('/');
$tree->edge('/', 'home');
assert_true([new Pair('/', 'home')] == $tree->edges()->items());

vertices

Signature

public function vertices(): Collection

Definition

It returns a collection of added vertices.

Examples

$tree = new Tree('/');
$tree->edge('/', 'home');
assert_true(['/', 'home'] === $tree->vertices()->items());