A TypeScript library that provides implementations of singly and doubly linked lists, designed to support both object-oriented and functional programming paradigms.
-
π§ Dual Programming Support: Facilitates both object-oriented and functional programming approaches, allowing developers to choose the style that best fits their project requirements.
-
π Type Safety: Utilizes Typescript generics and strict typing to ensure type correctness and reduce runtime errors.
-
β‘ Performance Optimization: Implements efficient memory usage and optimized operations to enhance performance.
-
π Modular Architecture: Enables tree-shakeable imports, allowing developers to include only the necessary modules and minimize bundle size.
-
ποΈ Extensibility: Provides abstract base classes and interfaces that can be extended to create custom linked list implementations tailored to specific needs.
- System Requirements
- Installation
- Getting Started
- Importing Modules
- Code documentation
- Issues and Support
- License
Package | Version |
---|---|
Node.js | β₯ 18.0.0 |
npm | β₯ 8.0.0 |
npm install abstract-linked-lists
yarn add abstract-linked-lists
pnpm install abstract-linked-lists
Here's a quick guide to help you get started with the library.
import { SinglyLinkedList, SinglyLinkedListNode } from 'abstract-linked-lists';
// Create a new list
const list = new SinglyLinkedList();
// Create node instances
const node_a = new SinglyLinkedListNode();
const node_b = new SinglyLinkedListNode();
// Add nodes to the list
list.pushNode(node_a);
list.pushNode(node_b);
// Iterate over list nodes
for (const node of list) {
console.log(node);
}
import { singlyLinkedList } from 'abstract-linked-lists';
const { create: createNode } = singlyLinkedList.node;
const { create: createList, pushNode } = singlyLinkedList.list;
const { inOrder } = singlyLinkedList.iterators;
// Create a new list
const list = createList();
// Create node instances
const node_a = createNode();
const node_b = createNode();
// Add nodes to the list
pushNode(list, node_a);
pushNode(list, node_b);
// Iterate over list nodes
const iterator = inOrder(list.head);
for (let curr = iterator.next(); !curr.done; curr = iterator.next()) {
const node = curr.value;
console.log(node);
}
The library offers flexible import options to suit different development needs. You can import everything at once, focus on specific list types, or select individual functions as needed.
To access all classes, interfaces, and functional APIs:
import {
// Concrete Classes
SinglyLinkedList,
SinglyLinkedListNode,
DoublyLinkedList,
DoublyLinkedListNode,
// Abstract Base Classes
AbstractLinkedList,
AbstractSinglyLinkedList,
AbstractSinglyLinkedListNode,
AbstractDoublyLinkedList,
AbstractDoublyLinkedListNode,
// Interfaces
ILinkedList,
ISinglyLinkedList,
ISinglyLinkedListNode,
IDoublyLinkedList,
IDoublyLinkedListNode,
// Functional APIs
singlyLinkedList,
doublyLinkedList,
} from 'abstract-linked-lists';
This approach is convenient when you need a broad range of functionalities from the library.
If you're working with a particular type of linked list, you can import related modules directly.
import {
node,
list,
iterators,
} from 'abstract-linked-lists/singly-linked-list';
import {
node,
list,
iterators,
} from 'abstract-linked-lists/doubly-linked-list';
This method helps keep your bundle size small by only including necessary modules.
For maximum control and minimal footprint, import individual functions or operations.
// Node operations
import {
create as createNode,
detach,
} from 'abstract-linked-lists/singly-linked-list/node';
// List operations
import {
create as createList,
clear,
nodeAt,
popNode,
pushNode,
shiftNode,
unshiftNode,
} from 'abstract-linked-lists/singly-linked-list/list';
// Iterators
import {
inOrder,
inReverseOrder,
} from 'abstract-linked-lists/singly-linked-list/iterators';
// Node operations
import {
create as createNode,
detach,
} from 'abstract-linked-lists/doubly-linked-list/node';
// List operations
import {
create as createList,
clear,
nodeAt,
popNode,
pushNode,
shiftNode,
unshiftNode,
} from 'abstract-linked-lists/doubly-linked-list/list';
// Iterators
import {
inOrder,
inReverseOrder,
} from 'abstract-linked-lists/doubly-linked-list/iterators';
By importing only what you need, you optimize performance and maintain a clean codebase.
The complete API reference of the library is available at the code documentation site.
If you encounter any issues or have questions, please open an issue.
This project is licensed under the MIT License.