2.3.0 • Published 5 years ago

quercus v2.3.0

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

Quercus

Dynamic tree data structures in TypeScript

Introduction

Quercus allows you to create dynamic tree data structures of any size and depth. Even though the examples use strings as path items, any data type accepted as a Map key can be used.

Docs

Usage

npm install quercus

Example

import { NestedMapTree } from "quercus";

const tree = new NestedMapTree<string, number>();
tree.setPath(["foo", "bar"], 5);
tree.setPath(["foo", "bizz"], 12);
tree.setPath(["bar", "fazz"], 560);

Creates a tree like this:

        tree
        /  \
      foo   bar
      / \     \
    bar bizz  fazz
     |   |      |
     5   12    560

Nodes can be checked and retrieved using hasPath and getPath.

import { LookupStrategy, NestedMapTree } from "quercus";

const tree = new NestedMapTree<string, number>();
tree.setPath(["foo", "bar"], 5);
tree.setPath(["foo", "bizz"], 12);
tree.setPath(["bar", "fazz"], 560);

console.log(`foo->bar: ${tree.hasPath(["foo", "bar"])}`); // "foo->bar: true"
console.log(`bar: ${tree.hasPath(["bar"])}`); // "bar: true"
console.log(`lorem: ${tree.hasPath(["lorem"])}`); // "lorem: false"

console.log(
    `foo->bar: ${tree.hasPath(
        ["foo", "bar"],
        LookupStrategy.EXISTENCE_BY_VALUE
    )}`
); // "foo->bar: true"
console.log(`bar: ${tree.hasPath(["bar"], LookupStrategy.EXISTENCE_BY_VALUE)}`); // "bar: false"
console.log(
    `lorem: ${tree.hasPath(["lorem"], LookupStrategy.EXISTENCE_BY_VALUE)}`
); // "lorem: false"
import { NestedMapTree } from "quercus";

const tree = new NestedMapTree<string, number>();
tree.setPath(["foo", "bar"], 5);
tree.setPath(["foo", "bizz"], 12);
tree.setPath(["bar", "fazz"], 560);

/*
 *    {
 *        node: { value: 5, map: new Map() },
 *        matchedPath: ["foo", "bar"],
 *        trailingPath: []
 *    };
 */
tree.getPath(["foo", "bar"]);

/*
 *    {
 *        node: null,
 *        matchedPath: ["foo"],
 *        trailingPath: ["lorem"]
 *    };
 */
tree.getPath(["foo", "lorem"]);
3.0.0-0

5 years ago

2.3.0

5 years ago

2.2.10

6 years ago

2.2.9

6 years ago

2.2.8

6 years ago

2.2.7

6 years ago

2.2.6

6 years ago

2.2.5

6 years ago

2.2.4

6 years ago

2.2.3

6 years ago

2.2.2

6 years ago

2.2.1

6 years ago

2.2.0

6 years ago

2.1.0

6 years ago

2.0.0

6 years ago

1.0.0

6 years ago