Skip to content

Latest commit

 

History

History
334 lines (218 loc) · 4.67 KB

File metadata and controls

334 lines (218 loc) · 4.67 KB

cppstructs

Modern Header-Only Data Structures for C++17

A lightweight collection of reusable data structures missing from the C++ Standard Library.

C++ Header Only License


✨ Features

  • 🚀 Header-only library
  • ⚡ Zero dependencies
  • 📦 Easy integration
  • 🧩 Generic & reusable
  • 🛡️ Modern C++17
  • ✅ Unit tested
  • 📖 Clean API
  • 💻 Cross-platform

Why cppstructs?

The C++ Standard Library is powerful, but several commonly used data structures are still missing.

cppstructs fills those gaps by providing clean, reusable, and well-tested implementations.

Data Structure STL cppstructs
Disjoint Set Union (Union-Find)
Trie (Prefix Tree)
Generic Min Heap Limited (priority_queue)
Segment Tree (Planned) 🚧
Fenwick Tree (Planned) 🚧
LRU Cache (Planned) 🚧

📂 Project Structure

cppstructs/
│
├── include/
│   └── cppstructs/
│       ├── cppstructs.hpp
│       ├── dsu.hpp
│       ├── trie.hpp
│       └── minheap.hpp
│
├── tests/
│
├── CMakeLists.txt
├── LICENSE
└── README.md

🚀 Installation

Option 1 — Copy Headers

Simply copy

include/cppstructs/

into your project.

Then include

#include <cppstructs/cppstructs.hpp>

No build step required.


Option 2 — CMake FetchContent

include(FetchContent)

FetchContent_Declare(
    cppstructs
    GIT_REPOSITORY https://github.com/banothnithin600-hub/cppstructs.git
    GIT_TAG main
)

FetchContent_MakeAvailable(cppstructs)

target_link_libraries(your_target PRIVATE cppstructs)

📖 Quick Start

#include <iostream>
#include <cppstructs/cppstructs.hpp>

int main()
{
    // DSU
    cs::DSU dsu(5);

    dsu.unite(0,1);

    std::cout << dsu.connected(0,1);

    // Trie

    cs::Trie trie;

    trie.insert("apple");

    std::cout << trie.search("apple");

    // Heap

    cs::MinHeap<int> heap;

    heap.push(5);
    heap.push(1);
    heap.push(3);

    std::cout << heap.pop();
}

📚 Data Structures

1. DSU (Disjoint Set Union)

Supports

  • Path Compression
  • Union by Rank
cs::DSU dsu(10);

dsu.unite(1,2);

dsu.connected(1,2);

dsu.count();

Complexity

Operation Complexity
Find O(α(n))
Union O(α(n))
Connected O(α(n))

2. Trie

Supports

  • Insert
  • Search
  • Prefix Search
  • Remove
cs::Trie trie;

trie.insert("apple");

trie.search("apple");

trie.starts_with("app");

trie.remove("apple");

Complexity

Operation Complexity
Insert O(L)
Search O(L)
Remove O(L)
Prefix Search O(L)

where L = length of string


3. MinHeap

A generic binary min heap.

cs::MinHeap<int> heap;

heap.push(5);

heap.push(2);

heap.push(8);

heap.peek();

heap.pop();

heap.empty();

heap.size();

Complexity

Operation Complexity
Push O(log n)
Pop O(log n)
Peek O(1)
Size O(1)

🧪 Running Tests

Clone the repository

git clone https://github.com/banothnithin600-hub/cppstructs.git

Build

cmake -S . -B build
cmake --build build

Run tests

ctest --test-dir build

💡 Design Principles

  • Header-only architecture
  • Modern C++17
  • Template-based implementation
  • Smart pointers where applicable
  • Exception-safe APIs
  • Clean, beginner-friendly interface
  • Zero external dependencies

🛣️ Roadmap

  • DSU
  • Trie
  • Generic MinHeap
  • Segment Tree
  • Fenwick Tree
  • Sparse Table
  • LRU Cache
  • Graph
  • Binary Indexed Tree
  • Benchmark Suite
  • Documentation Website

🤝 Contributing

Contributions are welcome!

If you'd like to improve the library:

  1. Fork the repository
  2. Create a new branch
  3. Commit your changes
  4. Open a Pull Request

Bug reports, feature requests, and discussions are always appreciated.


📄 License

This project is licensed under the MIT License.

See the LICENSE file for details.


⭐ Support

If you found this project useful,

please consider giving it a ⭐ on GitHub.

It helps the project reach more developers and motivates future improvements.


Built with ❤️ by Banoth Nithin

⭐ Star the repository if you like it!