or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

array-conversion.mdindex.mdtree-analysis.mdtree-construction.mdtree-iterators.mdtree-modification.mdtree-navigation.mdtree-traversal.md

tree-construction.mddocs/

0

# Tree Construction

1

2

Object initialization and SymbolTree instance creation for optimal performance.

3

4

## Capabilities

5

6

### SymbolTree Constructor

7

8

Creates a new SymbolTree instance with an optional description for the internal Symbol.

9

10

```javascript { .api }

11

/**

12

* Create a new SymbolTree instance

13

* @param {string} [description='SymbolTree data'] - Description used for the internal Symbol

14

*/

15

class SymbolTree {

16

constructor(description?: string);

17

}

18

```

19

20

**Usage Examples:**

21

22

```javascript

23

const SymbolTree = require("symbol-tree");

24

25

// Create with default description

26

const tree = new SymbolTree();

27

28

// Create with custom description for debugging

29

const domTree = new SymbolTree("DOM tree data");

30

```

31

32

### Object Initialization

33

34

Initialize an object right after creation to take advantage of V8's fast properties and enable object freezing.

35

36

```javascript { .api }

37

/**

38

* Initialize an object for tree operations (optional performance optimization)

39

* Time Complexity: O(1)

40

* @param {Object} object - Object to initialize

41

* @returns {Object} The same object that was passed in

42

*/

43

initialize(object: Object): Object;

44

```

45

46

**Usage Examples:**

47

48

```javascript

49

const tree = new SymbolTree();

50

51

// Basic initialization

52

const node = tree.initialize({ id: "node1", data: "value" });

53

54

// Initialize before freezing (common pattern)

55

const frozenNode = Object.freeze(

56

tree.initialize({ id: "node2", readonly: true })

57

);

58

59

// Initialize immediately after creation

60

class DOMNode {

61

constructor(tagName) {

62

this.tagName = tagName;

63

tree.initialize(this); // Optimize for tree operations

64

}

65

}

66

```

67

68

**Performance Notes:**

69

70

- Calling `initialize()` is optional but recommended for objects that will be heavily used in tree operations

71

- Helps V8 optimize property access patterns

72

- Particularly useful when you plan to freeze objects after tree setup

73

- Has no effect on tree functionality, only on performance characteristics