Skip to content

ThomasThorpe/tprt-hash-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tprt-hash-utils

A set of hashing utilities for C++.

Features

  • Compile time friendly.
  • Concise concept contrained API.
  • Builds upon the basis of std::hash.
  • Utilties to make hashing user defined types by composition easier.
  • Support hashing for all cvref types.

Usage

tprt::hash is a free function which wraps the construction of the std::hash object in addition to providing the native ability to combine hash values. The hash implementations for fundamental types have been replaced to be compile time friendly.

static constexpr auto h = tprt::hash(42, 4.2f, 't', 'p', 'r', 't');

Perhaps one of the most useful utilities is hash_members which can be used to create hashers for types made from hashable data members and member functions which return a hashable value.

struct udt { int i{}; double fd(); };

template <>
struct std::hash<udl> : tprt::hash_members<udt, &udt::i, &udt::fd>{};

The library also provides utility hashers for types whose components are also hashable such as hash_chrono, hash_pair, hash_range, and hash_tuple.

Technologies

This is a hobby project made to explore the latest C++ standards and compilers. As a result there is no minimum standard or compiler than this project will support. The project currently makes use of C++ 23 features.

The project uses cmake 3.28 as a build system.

  • FNV compile time hash algorithms.
  • Normalising unique object representations to hashable byte ranges.
  • Compile time testing.
  • Uses function objects to pass overload sets and function templates to higher order functions.

The project has been successfully compiled and tested with the following compilers on Kubuntu 24.04 LTS.

Building & Installation

  1. git clone https://github.com/ThomasThorpe/tprt-hash-utils
  2. cd tprt-hash-utils && mkdir build && cd build
  3. cmake -DCMAKE_BUILD_TYPE=Release -G "Ninja" ..
  4. cmake --build . && ctest
  5. sudo cmake --install .

About

Hashing utilities for C++

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors