Skip to content

A lightweight TypeScript library providing implementations of singly and doubly linked lists, designed for maximum flexibility and seamless support for both object-oriented and functional programming.

License

Notifications You must be signed in to change notification settings

styiannis/abstract-linked-lists

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Abstract Linked Lists

A TypeScript library that provides implementations of singly and doubly linked lists, designed to support both object-oriented and functional programming paradigms.

Key Features

  • πŸ”§ 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.

Table of Contents

System Requirements

Package Version
Node.js β‰₯ 18.0.0
npm β‰₯ 8.0.0

Installation

Install via npm

npm install abstract-linked-lists

Install via yarn

yarn add abstract-linked-lists

Install via pnpm

pnpm install abstract-linked-lists

Getting Started

Here's a quick guide to help you get started with the library.

Using Class-Based Implementation

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);
}

Using Functional Implementation

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);
}

Importing Modules

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.

Importing the Entire Package

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.

Importing Specific List Types

If you're working with a particular type of linked list, you can import related modules directly.

For Singly Linked List:

import {
  node,
  list,
  iterators,
} from 'abstract-linked-lists/singly-linked-list';

For Doubly 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.

Importing Individual Functions

For maximum control and minimal footprint, import individual functions or operations.

Singly Linked List Functions:

// 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';

Doubly Linked List Functions:

// 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.

Code documentation

The complete API reference of the library is available at the code documentation site.

Issues and Support

If you encounter any issues or have questions, please open an issue.

License

This project is licensed under the MIT License.

About

A lightweight TypeScript library providing implementations of singly and doubly linked lists, designed for maximum flexibility and seamless support for both object-oriented and functional programming.

Topics

Resources

License

Stars

Watchers

Forks