Skip to content

Latest commit

 

History

History
389 lines (216 loc) · 7.72 KB

aatree.md

File metadata and controls

389 lines (216 loc) · 7.72 KB

dastal - v5.0.0 / AATree

Class: AATree<T>

An AA tree is a form of balanced tree used for storing and retrieving ordered data efficiently (source).

AA trees are named for Arne Andersson, their inventor. They are a variation of the red–black tree, which supports efficient addition and deletion of entries. Unlike red–black trees, additional constraints on the balancing mechanism greatly simplifies the implementation as well as maintenance operations; While a red–black tree needs to consider seven different shapes to properly balance the tree, an AA tree only needs to consider two shapes.

The performance of an AA tree is equivalent to the performance of a red–black tree. While an AA tree makes more rotations than a red-black tree, the simpler algorithms tend to be faster, which balances out to similar performance. A red-black tree is more consistent in its performance, but an AA tree tends to be flatter, which results in slightly faster search times.

Type parameters

Name
T

Implements

Table of contents

Constructors

Accessors

Methods

Constructors

constructor

new AATree<T>(compareFn, elements?)

Instantiate a tree.

Type parameters

Name
T

Parameters

Name Type Description
compareFn CompareFn<T> The function to determine the order of elements.
elements? Iterable<T> A set of elements to initialize the tree with.

Defined in

src/tree/aaTree.ts:56

new AATree<T>(compareFn, allowDuplicates, elements?)

Instantiate a tree.

Type parameters

Name
T

Parameters

Name Type Description
compareFn CompareFn<T> The function to determine the order of elements.
allowDuplicates boolean Whether to allow duplicates
elements? Iterable<T> A set of elements to initialize the tree with.

Defined in

src/tree/aaTree.ts:63

Accessors

size

get size(): number

The number of elements in the collection.

Returns

number

Implementation of

SortedTree.size

Defined in

src/tree/aaTree.ts:183

Methods

[iterator]

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

Receive an iterator through the list.

Note: Unexpected behavior can occur if the collection is modified during iteration.

Returns

Iterator<T, any, undefined>

An iterator through the list

Implementation of

SortedTree.[iterator]

Defined in

src/tree/aaTree.ts:199


add

add(element): AATree<T>

Inserts an element into the tree.

Parameters

Name Type
element T

Returns

AATree<T>

Implementation of

SortedTree.add

Defined in

src/tree/aaTree.ts:87


clear

clear(): void

Removes all elements.

Returns

void

Implementation of

SortedTree.clear

Defined in

src/tree/aaTree.ts:117


comparator

comparator(): CompareFn<T>

Returns

CompareFn<T>

Implementation of

SortedTree.comparator

Defined in

src/tree/aaTree.ts:122


delete

delete(element): boolean

Delete an element from the tree.

Parameters

Name Type
element T

Returns

boolean

Implementation of

SortedTree.delete

Defined in

src/tree/aaTree.ts:126


has

has(element): boolean

Check if an element is in the tree.

Parameters

Name Type
element T

Returns

boolean

Implementation of

SortedTree.has

Defined in

src/tree/aaTree.ts:139


max

max(): undefined | T

Get the maximum element.

Returns

undefined | T

Implementation of

SortedTree.max

Defined in

src/tree/aaTree.ts:143


min

min(): undefined | T

Get the minimum element.

Returns

undefined | T

Implementation of

SortedTree.min

Defined in

src/tree/aaTree.ts:147


pop

pop(): undefined | T

Remove the maximum element.

Returns

undefined | T

Implementation of

SortedTree.pop

Defined in

src/tree/aaTree.ts:151


shift

shift(): undefined | T

Remove the minimum element.

Returns

undefined | T

Implementation of

SortedTree.shift

Defined in

src/tree/aaTree.ts:167


sorted

sorted(): Iterable<T>

Iterate through the tree in sorted order (i.e in-order traversal).

Note: Unexpected behavior can occur if the collection is modified during iteration.

Returns

Iterable<T>

Implementation of

SortedTree.sorted

Defined in

src/tree/aaTree.ts:187


update

update(curElement, newElement): boolean

Update a specific element.

Parameters

Name Type
curElement T
newElement T

Returns

boolean

Implementation of

SortedTree.update

Defined in

src/tree/aaTree.ts:205