Skip to content

Latest commit

 

History

History
205 lines (116 loc) · 3.72 KB

tree.md

File metadata and controls

205 lines (116 loc) · 3.72 KB

dastal - v5.0.0 / Tree

Interface: Tree<T>

Represents a tree data structure (source).

A tree is a widely used abstract data type that simulates a hierarchical tree structure. It can defined recursively as a collection of nodes (starting at a root node), where each node consists of a value and a list of references to other nodes ('children'), with the constraints that no reference is duplicated and none point to the root.

At a Glance

Iterate

  • Iterate the tree: {@link [Symbol.iterator]}

Get

  • Get the size of the tree: size
  • Check if the tree contains a given element: contains

Set

Add

  • Add 1 element: add

Remove

  • Delete a given element: delete
  • Remove all elements: clear

Type parameters

Name
T

Hierarchy

Table of contents

Properties

Methods

Properties

size

Readonly size: number

The number of elements in the collection.

Inherited from

Collection.size

Defined in

src/collection/collection.ts:5

Methods

[iterator]

[iterator](): Iterator<T, any, undefined>

Returns

Iterator<T, any, undefined>

Inherited from

Collection.[iterator]

Defined in

node_modules/typescript/lib/lib.es2015.iterable.d.ts:51


add

add(element): Tree<T>

Inserts an element into the tree.

Parameters

Name Type Description
element T The element to be inserted.

Returns

Tree<T>

The tree object.

Defined in

src/tree/tree.ts:38


clear

clear(): void

Removes all elements.

Returns

void

Defined in

src/tree/tree.ts:42


delete

delete(element): boolean

Delete an element from the tree.

Parameters

Name Type Description
element T The element to delete.

Returns

boolean

true if the element was found and deleted, otherwise false.

Defined in

src/tree/tree.ts:50


has

has(element): boolean

Check if an element is in the tree.

Parameters

Name Type Description
element T The element to find.

Returns

boolean

true if the element was found, otherwise false.

Defined in

src/tree/tree.ts:58


update

update(curElement, newElement): boolean

Update a specific element.

Parameters

Name Type Description
curElement T The element to update.
newElement T The new element to insert.

Returns

boolean

true if curElement was found and updated, otherwise false.

Defined in

src/tree/tree.ts:67