Skip to content

msboffl/ds-algo

Repository files navigation

Data Structures and Algorithms Library

A TypeScript monorepo for data structures and algorithms, inspired by Java's Collections Framework. Managed with pnpm workspaces, typed with TypeScript, and tested with Vitest.

πŸ“¦ Packages

This monorepo contains the following packages:

  • @ds-algo/collections β€” Collection framework

    • Core interfaces: Collection, Iterable, Iterator, List (done)
    • Abstract base classes: AbstractCollection, AbstractList (done)
    • Concrete implementations: ArrayList (done), more planned
    • Utilities: Collections aggregator (done)
  • @ds-algo/algorithms β€” Algorithms library

    • Package scaffold, build config, and tests setup present
    • Algorithm modules planned; exports not finalized yet

πŸ—οΈ Project Structure

packages/
β”œβ”€β”€ collections/          # Collection framework
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ interfaces/   # Core interfaces (Collection, Iterable, Iterator, List)
β”‚   β”‚   β”œβ”€β”€ abstracts/    # Abstract base classes (AbstractCollection, AbstractList)
β”‚   β”‚   β”œβ”€β”€ classes/      # Concrete implementations (ArrayList, Collections)
β”‚   β”‚   └── index.ts      # Main exports
β”‚   β”œβ”€β”€ tests/            # Unit tests (e.g., ArrayList.test.ts)
β”‚   └── README.md         # Package documentation
└── algorithms/           # Algorithm implementations (scaffolded)
    β”œβ”€β”€ src/
    β”‚   └── index.ts      # Main exports (TBD)
    β”œβ”€β”€ tests/            # Test files
    └── README.md         # Package documentation

πŸš€ Getting Started

Prerequisites

  • Node.js 18+
  • pnpm 8+

Installation

# Clone the repository
git clone https://github.com/msboffl/ds-algo.git
cd ds-algo

# Install workspace dependencies
pnpm install

# (Optional) Generate a fresh project tree snapshot
pnpm run generate:tree

Build

# Build all workspaces (recursive)
pnpm -r run build

# Build a specific package
pnpm --filter @ds-algo/collections run build
pnpm --filter @ds-algo/algorithms run build

Test

# Run all package tests (recursive)
pnpm -r run test

# Run tests in a specific package
pnpm --filter @ds-algo/collections run test
pnpm --filter @ds-algo/algorithms run test

Usage

Collections Package

import { ArrayList, List } from '@ds-algo/collections';

const list: List<number> = new ArrayList<number>();
list.add(1);
list.add(2);

Algorithms Package

Exports are being stabilized. Examples will be added as implementations land.

πŸ› οΈ Development

Useful Commands

# Format repository
pnpm run prettier:format

# Check formatting
pnpm run prettier:check

# Package dev mode (example)
pnpm --filter @ds-algo/collections run dev

# Clean build artifacts (package level)
pnpm --filter @ds-algo/collections run clean

Development Workflow

  1. Collections

    • Add/extend interfaces in packages/collections/src/interfaces/
    • Implement shared logic in packages/collections/src/abstracts/
    • Implement concrete classes in packages/collections/src/classes/
    • Add tests under packages/collections/src/tests/
    • Export from packages/collections/src/index.ts
  2. Algorithms

    • Implement algorithms under category folders (to be introduced)
    • Export from packages/algorithms/src/index.ts
    • Add tests under packages/algorithms/tests/
    • Document usage in packages/algorithms/README.md

Testing Strategy

Each package includes or plans to include:

  • Unit tests with various input sizes
  • Edge case testing
  • Performance checks where appropriate
  • Type safety verification

πŸ“Š Current Status

Collections Package

  • βœ… Core interfaces implemented (Collection, Iterable, Iterator, List)
  • βœ… Abstract base classes implemented (AbstractCollection, AbstractList)
  • βœ… ArrayList implemented; Collections utilities available
  • πŸ”„ Additional concrete structures (LinkedList, Set, Map) planned
  • πŸ”„ Collection-specific algorithms planned

Algorithms Package

  • βœ… Package structure and build configuration
  • πŸ”„ Algorithm implementations under development
  • πŸ”„ Exports and API surface to be finalized

🎯 Features

Collections Framework

  • Type-safe interfaces with full TypeScript support
  • Generic collections for any data type
  • Iterator pattern for consistent iteration
  • Extensible design for custom implementations
  • Java-inspired architecture for familiarity

Algorithms Library

  • Well-tested implementations with comprehensive test coverage
  • Performance optimized with complexity analysis
  • Multiple algorithm categories (sorting, searching, graph, etc.)
  • TypeScript-first with proper type definitions
  • Educational focus with clear documentation

πŸ“š Documentation

🀝 Contributing

We welcome contributions! Please see our Contributing Guide if available.

Quick Start for Contributors

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes with appropriate tests
  4. Ensure all tests pass (pnpm -r run test)
  5. Submit a pull request

Development Guidelines

  • Follow TypeScript best practices
  • Write comprehensive tests for new features
  • Include JSDoc comments for public APIs
  • Update relevant documentation
  • Ensure code formatting with Prettier

πŸ“ License

This project is licensed under the MIT License β€” see the LICENSE file for details.

πŸ™ Acknowledgments

  • Inspired by Java's Collections Framework
  • Built with modern TypeScript practices
  • Testing with Vitest
  • Monorepo management with pnpm workspaces

πŸ“ˆ Roadmap

Short Term

  • Add LinkedList, Stack, Queue to collections
  • Establish algorithms module layout and initial exports
  • Basic sorting/searching algorithms
  • Expand unit tests

Medium Term

  • Graph and dynamic programming algorithms
  • String and mathematical algorithms
  • Performance benchmarks

Long Term

  • Advanced data structures (trees, heaps, tries)
  • Parallel/optimized variants
  • Documentation site and interactive examples

πŸ”— Related Projects

  • TypeScript Collections β€” https://github.com/basarat/typescript-collections
  • javascript-algorithms β€” https://github.com/trekhleb/javascript-algorithms
  • dsa.js β€” https://github.com/amejiarosario/dsa.js

Note: This is an active development project. Check the Issues page for current development status and planned features.