1.0.0 • Published 5 years ago

rbx-object-stack v1.0.0

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

ObjectStack

A Stack data structure which is formed by creating a singly linked-list on already existing objects. All you need to do is add a previousNode?: T field to your object you wish to use in the Stack.

See the index.d.ts file for documentation on each member and method.

Demo:

import ObjectStack from "rbx-object-stack";

interface Token {
	type: "a" | "b" | "c";
	previousNode?: Token;
}

const objectStack = new ObjectStack<Token>();

objectStack.push({ type: "b" });
objectStack.push({ type: "a" });
objectStack.push({ type: "c" });

objectStack.pop(); // { type: "c" }
objectStack.isEmpty(); // false

// iterates through the stack, from top to bottom
for (let token = objectStack.top; token; token = token.previousNode) {
	const x = token.type;
}