Skip to main content
Version: v1

TreeView Class

A view of a distributed tree.

Signature

export declare abstract class TreeView

Constructors

Constructor Description
(constructor)(root, forest) Constructs a new instance of the TreeView class

Properties

Property Type Description
forest Forest
root NodeId
size number

Methods

Method Return Type Description
[Symbol.iterator]() IterableIterator<TreeViewNode>
assertConsistent() void Asserts that the view's internal state is consistent. Useful for testing/validation.
delta(view) Delta<NodeId> Calculate the difference between two TreeViews
equals(view) boolean
findIndexWithinTrait(place) PlaceIndex
getIndexInTrait(id) TraitNodeIndex
getParentViewNode(id) TreeViewNode
getTrait(traitLocation) readonly NodeId[]
getTraitLabel(id) TraitLabel
getTraitLocation(id) TraitLocation
getViewNode(id) TreeViewNode
hasEqualForest(view, strict) boolean
hasNode(id) boolean
tryGetIndexInTrait(id) TraitNodeIndex | undefined
tryGetParentViewNode(id) TreeViewNode | undefined
tryGetTraitLabel(id) TraitLabel | undefined
tryGetTraitLocation(id) TraitLocation | undefined
tryGetViewNode(id) TreeViewNode | undefined

Constructor Details

(constructor)

Constructs a new instance of the TreeView class

Signature

protected constructor(root: NodeId, forest: Forest);

Parameters

Parameter Type Description
root NodeId
forest Forest

Property Details

forest

Signature

protected readonly forest: Forest;

Type: Forest

root

Signature

readonly root: NodeId;

Type: NodeId

size

Signature

get size(): number;

Type: number

Method Details

[Symbol.iterator]

Signature

[Symbol.iterator](): IterableIterator<TreeViewNode>;

Returns

Return type: IterableIterator<TreeViewNode>

assertConsistent

Asserts that the view's internal state is consistent. Useful for testing/validation.

Signature

assertConsistent(): void;

delta

Calculate the difference between two TreeViews

Signature

delta(view: TreeView): Delta<NodeId>;

Parameters

Parameter Type Description
view TreeView the other view to compare to this one

Returns

A Delta which nodes must be changed, added, and removed to get from this to view. The views must share a root.

Return type: Delta<NodeId>

equals

Signature

abstract equals(view: TreeView): boolean;

Parameters

Parameter Type Description
view TreeView

Returns

true iff the given view is equal to this view

Return type: boolean

findIndexWithinTrait

Signature

findIndexWithinTrait(place: TreeViewPlace): PlaceIndex;

Parameters

Parameter Type Description
place TreeViewPlace

Returns

the index just after place (which specifies a location between items). Performance note: this is O(siblings in trait).

Return type: PlaceIndex

getIndexInTrait

Signature

getIndexInTrait(id: NodeId): TraitNodeIndex;

Parameters

Parameter Type Description
id NodeId

Returns

the index within the trait under which the node with the given id resides. The node must exist in this view and must have a parent. Performance note: this is O(siblings in trait).

Return type: TraitNodeIndex

getParentViewNode

Signature

getParentViewNode(id: NodeId): TreeViewNode;

Parameters

Parameter Type Description
id NodeId

Returns

the parent of the node with the given id. Fails if the node does not exist in this view or if it is the root node.

Return type: TreeViewNode

getTrait

Signature

getTrait(traitLocation: TraitLocation): readonly NodeId[];

Parameters

Parameter Type Description
traitLocation TraitLocation

Returns

the trait at the given location. If no such trait exists, returns an empty trait.

Return type: readonly NodeId[]

getTraitLabel

Signature

getTraitLabel(id: NodeId): TraitLabel;

Parameters

Parameter Type Description
id NodeId

Returns

the label of the trait under which a node with the given id resides. Fails if the node does not exist in this view or if it is the root node.

Return type: TraitLabel

getTraitLocation

Signature

getTraitLocation(id: NodeId): TraitLocation;

Parameters

Parameter Type Description
id NodeId

Returns

the trait location of the node with the given id. Fails if the node does not exist in this view or of it is the root node

Return type: TraitLocation

getViewNode

Signature

getViewNode(id: NodeId): TreeViewNode;

Parameters

Parameter Type Description
id NodeId

Returns

the node associated with the given id in this view. Fails if the node does not exist in this view.

Return type: TreeViewNode

hasEqualForest

Signature

hasEqualForest(view: TreeView, strict?: boolean): boolean;

Parameters

Parameter Modifiers Type Description
view TreeView
strict optional boolean if true, the views' forests must be the same object, otherwise they must merely be equivalent

Returns

true iff the given view's forest of nodes is equivalent to this view's forest of nodes

Return type: boolean

hasNode

Signature

hasNode(id: NodeId): boolean;

Parameters

Parameter Type Description
id NodeId

Returns

true iff a node with the given id exists in this view

Return type: boolean

tryGetIndexInTrait

Signature

tryGetIndexInTrait(id: NodeId): TraitNodeIndex | undefined;

Parameters

Parameter Type Description
id NodeId

Returns

the index within the trait under which the node with the given id resides, or undefined if the node does not exist in this view or does not have a parent. Performance note: this is O(siblings in trait).

Return type: TraitNodeIndex | undefined

tryGetParentViewNode

Signature

tryGetParentViewNode(id: NodeId): TreeViewNode | undefined;

Parameters

Parameter Type Description
id NodeId

Returns

the parent of the node with the given id. Returns undefined if the node does not exist in this view or if it is the root node.

Return type: TreeViewNode | undefined

tryGetTraitLabel

Signature

tryGetTraitLabel(id: NodeId): TraitLabel | undefined;

Parameters

Parameter Type Description
id NodeId

Returns

the label of the trait under which a node with the given id resides, or undefined if the node is not present in this view or if it is the root node

Return type: TraitLabel | undefined

tryGetTraitLocation

Signature

tryGetTraitLocation(id: NodeId): TraitLocation | undefined;

Parameters

Parameter Type Description
id NodeId

Returns

the trait location of the node with the given id, or undefined if the node does not exist in this view or if it is the root node

Return type: TraitLocation | undefined

tryGetViewNode

Signature

tryGetViewNode(id: NodeId): TreeViewNode | undefined;

Parameters

Parameter Type Description
id NodeId

Returns

the node associated with the given id in this view, or undefined if the node does not exist in this view

Return type: TreeViewNode | undefined