Skip to content

DEIS-Tools/ptrie

 
 

Repository files navigation

ptrie

A memory efficient hashfree hashmap implementation packaged as a header-only library.

Dependencies

Ubuntu (assuming 24.04 LTS):

sudo apt install cmake ninja-build g++
sudo apt install libsparsehash-dev

macOS (install XCode from AppStore, and Homebrew) using native AppleClang:

brew install cmake ninja  
brew install google-sparsehash

macOS (install XCode from AppStore, and Homebrew) using GCC from brew:

brew install cmake ninja gcc
brew install google-sparsehash
export CC=gcc-15
export CXX=g++-15

Windows MSYS2 UCRT64:

PRE=mingw-w64-ucrt-x86_64
pacman -S $PRE-git $PRE-cmake $PRE-ninja $PRE-toolchain $PRE-sparsehash

Installation

Use CMake to install to $PWD/local (headers and CMake configuration):

cmake --workflow --preset quick-release && \
cmake --install build-quick --config Release --prefix=$PWD/local

Example Usage

Directory example contains a sample project using ptrie.

Test against the ptrie installed in local using ptrie.cmake:

cmake -S example -B build-example-local -DCMAKE_PREFIX_PATH=$PWD/local && \
cmake --build build-example-local && \
ctest --test-dir build-example-local --verbose

Test by fetching ptrie from the repository using ptrie.cmake:

cmake -S example -B build-example && \
cmake --build build-example && \
ctest --test-dir build-example --verbose

Clean all:

rm -Rf local build-quick build-example-local build-example

Testing and Benchmarking

Benchmark results are plotted using python when the following packages are installed:

sudo apt install python3-matplotlib python3-pandas python3-scipy python3-pyqt6

Test and benchmark a release build:

cmake --workflow --preset release

Test and debug with sanitizers:

cmake --workflow --preset debug-san

Inspect other workflow presets:

cmake --workflow --list-presets

See also configuration, build and test presets:

cmake --list-presets=configure
cmake --list-presets=build
cmake --list-presets=test

For example multi-config with sanitizers Debug build and test:

cmake --preset multi-san
cmake --build --preset debug-san
ctest --preset debug-san

Code Coverage

Configure with -DPTRIE_COVERAGE=ON and build the coverage target. It runs the instrumented tests and produces an HTML report under <build>/coverage-html plus a textual summary on the console. The tooling is selected by the compiler: gcov/lcov for GCC, llvm-cov for Clang/AppleClang.

cmake --preset multi -DPTRIE_COVERAGE=ON
cmake --build --preset release-deb --target coverage
xdg-open build-multi/coverage-html/index.html  # or open ... on macOS

Coverage instrumentation is incompatible with the sanitizers, so use a non-sanitized preset (e.g. multi / release-deb).

Extra tools are needed for the report (instrumentation alone works without them):

sudo apt install lcov          # GCC: lcov + genhtml
# Clang: llvm-cov and llvm-profdata ship with the LLVM toolchain

With Clang, llvm-cov prints warning: N functions have mismatched data. This is benign: the library is header-only, so a templated function that is present but never called in one test binary keeps a different structural hash than the instantiation exercised in another. It therefore matches by name but not by hash when the merged profile is applied across all test binaries. Coverage counts stay correct, and llvm-cov has no flag to silence just this message (--no-warn does not affect it).

About

A memory efficient hashfree hashmap implementation

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • C++ 82.1%
  • CMake 13.0%
  • Python 3.1%
  • Shell 1.2%
  • C 0.6%