1.0.1 • Published 4 years ago

@rbxts/object-stack v1.0.1

Weekly downloads
2
License
ISC
Repository
github
Last release
4 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 "@rbxts/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;
}