@stormking/datastructures
v1.1.0
Published
datastructure helper utility
Downloads
12
Maintainers
Readme
Datastructures Helper Lib
Include in Node
import { Task, Queue, Graph, Element, Connection, Node, Tree, List } from "@stormking/datastructures";
// or
const { Task, Queue, Graph, Element, Connection, Node, Tree, List } = require("@stormking/datastructures");
Include in Browser
import Tree from '@stormking/datastructures/dist/browser/tree.js'
import Queue from '@stormking/datastructures/dist/browser/queue.js'
import Tasks from '@stormking/datastructures/dist/browser/tasks.js'
import Lists from '@stormking/datastructures/dist/browser/lists.js'
Graph
An in-memory graph-db, trying to fill the role that NeDB fills for document databases.
let g = new Graph();
let a = g.createNode();
let b = g.createNode();
a.linkTo(b);
See tests for further usage.
Queue
A simple queue, implemented via dual-linked list for optimal performance.
let q = new Queue<number>();
q.push(5);
let x = q.shift();
q.unshift(x);
x = q.pop();
See tests for further usage.
Task
A task queue.
let q = new Task();
let result = await q.addTask(() => Date.now());
See tests for further usage.