A lightweight collection of reusable data structures missing from the C++ Standard Library.
- 🚀 Header-only library
- ⚡ Zero dependencies
- 📦 Easy integration
- 🧩 Generic & reusable
- 🛡️ Modern C++17
- ✅ Unit tested
- 📖 Clean API
- 💻 Cross-platform
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) | ❌ | 🚧 |
cppstructs/
│
├── include/
│ └── cppstructs/
│ ├── cppstructs.hpp
│ ├── dsu.hpp
│ ├── trie.hpp
│ └── minheap.hpp
│
├── tests/
│
├── CMakeLists.txt
├── LICENSE
└── README.md
Simply copy
include/cppstructs/
into your project.
Then include
#include <cppstructs/cppstructs.hpp>No build step required.
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)#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();
}Supports
- Path Compression
- Union by Rank
cs::DSU dsu(10);
dsu.unite(1,2);
dsu.connected(1,2);
dsu.count();| Operation | Complexity |
|---|---|
| Find | O(α(n)) |
| Union | O(α(n)) |
| Connected | O(α(n)) |
Supports
- Insert
- Search
- Prefix Search
- Remove
cs::Trie trie;
trie.insert("apple");
trie.search("apple");
trie.starts_with("app");
trie.remove("apple");| Operation | Complexity |
|---|---|
| Insert | O(L) |
| Search | O(L) |
| Remove | O(L) |
| Prefix Search | O(L) |
where L = length of string
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();| Operation | Complexity |
|---|---|
| Push | O(log n) |
| Pop | O(log n) |
| Peek | O(1) |
| Size | O(1) |
Clone the repository
git clone https://github.com/banothnithin600-hub/cppstructs.gitBuild
cmake -S . -B buildcmake --build buildRun tests
ctest --test-dir build- Header-only architecture
- Modern C++17
- Template-based implementation
- Smart pointers where applicable
- Exception-safe APIs
- Clean, beginner-friendly interface
- Zero external dependencies
- DSU
- Trie
- Generic MinHeap
- Segment Tree
- Fenwick Tree
- Sparse Table
- LRU Cache
- Graph
- Binary Indexed Tree
- Benchmark Suite
- Documentation Website
Contributions are welcome!
If you'd like to improve the library:
- Fork the repository
- Create a new branch
- Commit your changes
- Open a Pull Request
Bug reports, feature requests, and discussions are always appreciated.
This project is licensed under the MIT License.
See the LICENSE file for details.
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!