@euriklis/ds-architect
v0.3.0
Published
`@euriklis/ds-architect` is a modular and extensible library that provides a rich ecosystem for graph and network-based data structures. Designed with both academic rigor and practical application in mind, this library offers powerful graph algorithms and
Maintainers
Readme
@euriklis/ds-architect is a modular and extensible library that provides a rich ecosystem for graph and network-based data structures. Designed with both academic rigor and practical application in mind, this library offers powerful graph algorithms and network functionalities while also including additional data structure components (like AVL trees, BSTs, queues, and heaps) for broader algorithmic programming.
Features
Graph Structures
- Create, update, and remove nodes and edges using a robust, type-safe API.
- Support for both directed and symmetric (undirected) graphs.
- Generate adjacency matrices and perform common traversals (BFS, DFS).
Create subgraphs and compute unions, differences, or Kronecker products of graphs.
Check connectivity, find cycles, detect Hamiltonian cycles, and test bipartiteness.
Generate n-dimensional cube graphs.
BaseNetwork & Extended Functionality
- Integrate domain-specific attributes (e.g.,
model,prompt,callback,modelOptions) into graph nodes. - Extend basic graph behavior to support network operations such as centrality measures and neural network concepts.
- Asynchronous traversal methods (e.g.,
BFSAsync,DFSAsync) for integrating LLM or other async operations.
- Integrate domain-specific attributes (e.g.,
Compute shortest paths and minimum spanning trees.
Additional Data Structures
Along with graphs,
ds-architectincludes other fundamental data structures—like queues, heaps, and trees—to support algorithmic programming.Designed to be lightweight: you can import only what you need without the overhead of heavy mathematics libraries.
Installation
Install via npm:
npm install @euriklis/ds-architectOr via bun:
bun install @euriklis/ds-architectDocumentation
Sub-library overview
Below is a brief summary of the main modules shipped with this package. Each class has additional examples and details in its corresponding documentation file linked above.
DataNode
DataNode<T>– Base class for all nodes. Providesidanddatagetters and setters along with a constructor that accepts optional data and id.
DoublyLinkedList
DoublyLinkedList<T>– A bidirectional list with optional size limit. Common methods includeaddLast,removeFirst,removeLast,insertBefore,insertAfter,filter,traverse,merge, and iteration with[Symbol.iterator]. Additional helpers provideremove,values,loop,every,any,copy,clean,isSame, andisExactlySame.
Queue
Queue<T>– FIFO queue built on a linked list. Supportsenqueue,enqueueMany,dequeue,dequeueMany,traverse,filter,merge,[Symbol.iterator], and helpers likecontains,reverse,clean,copy, andtoArray.
Stack
DynamicStack<T>– Resizable LIFO stack withpush,pushMany,pop,popMany,filter,traverse,loop,append,popAndTraverse,clear,copy, and iteration.StaticStack<T>– Array-backed variant with similar API for fixed-size use cases and identical helper methods.
BST
BST<T>– Binary search tree providinginsert,insertMany,delete,deleteNode,binarySearch,BFS,DFS, and iteration support. Additional helpers covermin/maxlookups, predecessor/successor queries, height calculation,filter,clean,copy,toArray,print,isSame,isExactlySame, and id-basedhas.
AVLTree
AVLTree<T>– Self-balancing tree that extendsBSTand rebalances oninsertordelete. Includescopyandprintutilities, and exposes rotation helpers likesingleLeftRotation,singleRightRotation,doubleLeftRightRotation, anddoubleRightLeftRotation.
Heap
Heap<T>andPrimaryHeap<T>– Binary heap implementations. Key methods areadd,search,remove,merge,searchIndex, and staticfromto build a heap from an array. Further utilities includetoArray, iteration via[Symbol.iterator], and configurablesize,typeandcompareproperties.
Graph and networks
Graph<T>– Generic graph structure withaddNode,removeNode,addEdge,removeEdge, data lookups, degree helpers, BFS/DFS traversals (sync or async), and utilities likesubgraph,union,difference,kronecker,isConnected,cycles,Hamiltonian,biGraph, andnCube. Additional algorithms includetopologicalOrder,bridges,directedBridges, and helpers likeclone,upgradeToBaseNetworkandupgradeToGraph.BaseNetwork– ExtendsGraphso nodes hold numeric values and edges carry weights.StateGraph– Lightweight graph focused on node/edge management without traversal algorithms.
Usage:
Here is a quick look at how to work with the library.
Basic Graph
import { Graph } from "@euriklis/ds-architect";
const g = new Graph<string>();
g.addNode({ name: "A", data: "hello" });
g.addNode({ name: "B", data: "world" });
g.addEdge({ source: "A", target: "B", data: null, params: {} });
console.log(g.inDegree("B")); // 1Building Your Own Structures
The DataNode class is the foundation for nodes used by the other data
structures. You can extend it to craft custom nodes for your own
structures and algorithms.
import { DataNode } from "@euriklis/ds-architect";
class MyNode<T> extends DataNode<T> {
// add extra properties or behavior here
}
const node = new MyNode({ foo: 42 });
console.log(node.id); // auto-generated UUIDCreate arrays, lists, or tree-like structures from these nodes to design tailored data structures for your application.
