|
CPPX 3.2.1
A Modern C++ Utility Library
|
Audience: Contributors, maintainers, and anyone building CPPX from source. This document covers everything you need to develop, test, benchmark, and release CPPX.
Install all required tools before building:
| Tool | Minimum Version | Notes |
|---|---|---|
| GCC / Clang / MSVC | C++23 support | GCC 13+, Clang 17+, MSVC 19.38+ |
| CMake | 3.14 | Fetches Google Test via FetchContent |
| clang-format | any | Applied automatically on build |
| Doxygen | any | Optional — for HTML API docs |
Graphviz (dot) | any | Optional — for class hierarchy diagrams |
| Internet access | — | Required on first build to fetch Google Test |
Key design rule: Template class declarations live in include/cppx.h. Template implementations live in src/*.tpp files, which are #include-d at the bottom of cppx.h. This keeps the header clean while satisfying the C++ requirement that template definitions be visible at instantiation time.
Note: A clean successful build means all unit tests passed. Test failures halt the build and print the failing test names and assertions.
If Doxygen is not installed or you want a faster iteration loop:
Tests are compiled into the unit_tests binary by CMake and auto-discovered by CTest.
Google Test supports --gtest_filter:
| File | Covers |
|---|---|
avl_test_cases.cpp | AVLTree<T> — insert, remove, balance invariants, rotations |
bst_test_cases.cpp | BST<T> — insert, remove, search, min/max, successor/predecessor |
rbt_test_cases.cpp | RBTree<T> — insert, remove, red-black property validation |
binary_tree_test_cases.cpp | BinaryTree<T> — manual construction, traversals, copy/move semantics |
node_test_cases.cpp | Node<T> — accessors, constructors |
visualization_test_cases.cpp | print_tree(), dump_to_dot() output correctness |
Add a file to test_suite/ — CMake picks up all *.cpp files via glob automatically:
Rebuild and run — no CMakeLists changes needed:
The benchmark suite compares stl_ext structures against std::set, std::map, and std::unordered_set at N = 10K, 100K, and 1M elements. It uses its own Benchmark timing class (no external dependency), with 1 warmup run and median of 3 timed runs per operation category (insert / lookup / delete).
This compiles the benchmark binary with -O3 -march=native and runs it, passing the repo root as the output directory.
Always pass the repo root path when running directly so output files land in docs/.
| Output file | Description |
|---|---|
docs/benchmark_results.csv | Raw timing data (structure, N, insert_ms, lookup_ms, delete_ms) |
docs/benchmark_chart.svg | SVG bar chart comparing all structures at all sizes |
The console also prints a formatted table:
std::set at large N due to arena allocation (fewer cache misses).std::unordered_set** wins on pure lookup — it is the correct baseline for O(1) access.Open benchmarks/benchmark_main.cpp and follow the existing pattern:
Then call it inside main() alongside the existing bench_avl(...) calls.
Doxygen docs are built automatically when CPPX_BUILD_DOCS=ON (the default) and Doxygen is found on the system.
The Doxygen theme is doxygen-awesome-css, fetched automatically by CMake. Configuration is in Doxyfile.in (processed into build/Doxyfile at configure time).
The hosted version is at https://cppx.vercel.app/.
CPPX uses clang-format with the rules defined in .clang-format at the repo root (a Google-based style with project-specific overrides).
clang-format runs automatically during every cmake --build invocation via the format_code CMake target, which is a build dependency of both unit_tests and benchmark. You do not need to run it manually.
Or format a single file:
| Category | Rule |
|---|---|
| Namespace | All code inside namespace stl_ext { } |
| Classes | PascalCase — BinaryTree, AVLTree, NodePool |
| Files | snake_case — binary_tree.tpp, avl_test_cases.cpp |
| Functions | snake_case — get_min(), insert_iterative(), rotate_left() |
| Member variables | Prefixed — m_data, m_height (value), p_left, p_head (pointer) |
| Headers | No using namespace std; — always fully qualify in headers |
| Memory | Use NodePool<T> — no raw new/delete — the arena owns all nodes |
| Node links | Raw pointers (not std::unique_ptr) — enables simple rotation pointer surgery |
| Template split | Declarations in .h, implementations in .tpp (included at bottom of .h) |
| Option | Default | Description |
|---|---|---|
CPPX_BUILD_TESTS | ON | Build unit_tests and benchmark executables; fetch Google Test |
CPPX_BUILD_DOCS | ON | Build Doxygen HTML docs; fetch doxygen-awesome-css theme |
Pass options at configure time:
| Target | Command | Description |
|---|---|---|
all (default) | cmake --build . | Build library, tests, benchmark, docs |
unit_tests | cmake --build . --target unit_tests | Build test executable only |
benchmark | cmake --build . --target benchmark | Build benchmark binary only |
run_benchmark | cmake --build . --target run_benchmark | Build and run the full benchmark suite |
doc_doxygen | cmake --build . --target doc_doxygen | Regenerate Doxygen HTML |
format_code | cmake --build . --target format_code | Run clang-format across all sources |
CPPX is designed to grow. Follow these steps to add a new structure correctly:
Forward-declare and then fully declare your class, inheriting from BinaryTree<T> or BST<T> as appropriate:
CMake automatically symlinks src/*.tpp into build/staging_include/cppx/detail/, so no CMakeLists changes are needed.
Cover at minimum: construction, insert, remove, contains, edge cases (empty tree, single node, duplicate values). See existing test files for patterns.
Follow the bench_avl() pattern (see Section 5 — Running Benchmarks above).
CMake's file(GLOB_RECURSE ...) picks up the new .tpp and _test_cases.cpp files automatically — no CMakeLists edits required.
NodePool<T> allocates Node<T> objects from contiguous 4096-node blocks:
used counter inside the current Block. If the block is full, a new Block is heap-allocated.std::vector<void*>). Next allocation checks the free-list first.~NodePool() / destroy_all() deletes all blocks at once — O(num_blocks), not O(N). No per-node destructor calls on the tree nodes.This design provides:
| Property | Benefit |
|---|---|
| Contiguous blocks | CPU cache lines hold multiple adjacent nodes — reduces cache misses on traversal |
No per-node new/delete | Eliminates allocator lock contention and heap fragmentation |
| Free-list recycling | remove() can return nodes without block fragmentation |
Move semantics on NodePool | Entire pools can be transferred (e.g. tree move constructor) in O(1) |
Parent pointers allow AVL and RB rotations to be implemented iteratively, avoiding deep recursion and making the stack trace flat under a profiler.
|balance_factor(node)| ≤ 1 for every node. Balance factor = height(left) - height(right).BinaryTree copy constructor) calls clone_subtree() which allocates new nodes in the destination's own pool.When you have merged new features to main and want to publish to the Ubuntu PPA:
The script:
debian/ packaging filesdebian/changelog via dchdebuild -S -salintian for policy checks (non-fatal warnings are OK)ppa:ifkabir/cppx via dputExample — release to Jammy without bumping the version:
Launchpad typically builds within 5–30 minutes. Check build status at: https://launchpad.net/~ifkabir/+archive/ubuntu/cppx
FetchContent requires internet access on first configure. If you're behind a proxy:
Or pre-download GoogleTest v1.14.0 and point CMake to a local mirror.
Install it:
Then reconfigure:
Install Graphviz:
The benchmark binary accepts the repo root as its first argument:
Without the argument it defaults to ./, which will write ./docs/benchmark_results.csv relative to wherever you ran it from — potentially not the docs/ folder in the repo. Use the CMake target to avoid this:
Make sure you ran cmake .. with CPPX_BUILD_TESTS=ON (the default) and that gtest_discover_tests(unit_tests) had a chance to run. Re-run:
All .tpp files must be #include-d at the bottom of cppx.h. Check that your new .tpp file has a corresponding #include "cppx/detail/your_file.tpp" line there.
For usage questions or bug reports, open an issue at https://github.com/IFKabir/CPPX/issues. For security vulnerabilities, see SECURITY.md.