Skip to content
KennyC3200Public

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

Repository files navigation

kc-cpp

Header-only C++20 data structures and allocators, grown out of my DSA learning project.

Header Description
<kc/memory/stack_arena.hpp> kc::arena, a fixed-size stack buffer, and kc::short_alloc, an STL allocator that draws from it (falls back to the heap when full)
<kc/memory/memory_pool.hpp> kc::MemoryPool: a typed object pool with O(1) Create/Destroy and unique_ptr handles
<kc/memory/memory_pool_stl.hpp> kc::UntypedMemoryPool, a fixed-size slot pool, and kc::MemoryPoolAlloc, an STL allocator for node-based containers (std::list, std::map, std::set, ...)
<kc/graph/node_graph.hpp> kc::NodeGraph, kc::DirectedGraph, kc::UndirectedGraph: allocator-aware adjacency-list graphs
<kc/graph/complete_tree.hpp> kc::CompleteTree: an N-ary complete tree with random-access iterators
<kc/heap/heap.hpp> kc::Heap: a d-ary heap / priority queue on std::vector or CompleteTree
<kc/algorithm/topological_sort.hpp> kc::TopoSort: Kahn's algorithm plus recursive and iterative DFS

Using it in another project

As a git submodule

git submodule add <repo-url> external/kc-cpp
add_subdirectory(external/kc-cpp)
target_link_libraries(my_target PRIVATE kc::cpp)

With FetchContent

include(FetchContent)
FetchContent_Declare(kc_cpp GIT_REPOSITORY <repo-url> GIT_TAG v0.1.0)
FetchContent_MakeAvailable(kc_cpp)
target_link_libraries(my_target PRIVATE kc::cpp)

Linking kc::cpp adds the include path and requires C++20, so no -std=c++20 flag is needed. Tests and examples are only built when kc-cpp is the top-level project.

#include <kc/heap/heap.hpp>

kc::Heap<int> heap;
heap.push(3);
heap.push(9);
heap.top();   // 9

Building and testing

cmake -S . -B build
cmake --build build
ctest --test-dir build --output-on-failure

Catch2 v3 is downloaded automatically the first time you configure.

Option Default Effect
KC_BUILD_TESTS ON when top-level Build the Catch2 tests
KC_BUILD_EXAMPLES ON when top-level Build the programs in examples/
KC_SANITIZE OFF Build tests with AddressSanitizer + UBSan (GCC/Clang on Linux/macOS; not supported by MinGW)

CI (.github/workflows/ci.yml) runs the tests on Linux with GCC and Clang under sanitizers, and on Windows with MSVC.

Layout

include/kc/   public headers, included as <kc/...>
tests/        Catch2 tests
examples/     small demo programs

Memory Pool Benchmarks

See the /examples directory for the files used to benchmark. Below are benchmark numbers recorded on Release, Windows 11, on a Core Ultra 7 165H.

Benchmark new/delete / std::allocator Pool Speedup
kc::MemoryPool ~2450 ms ~140 ms ~17x
std::list + kc::MemoryPoolAlloc ~2430 ms ~410 ms ~6x

Build the examples in Release (-DCMAKE_BUILD_TYPE=Release) when timing them.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages