BuildCache
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
bcache::hasher_t Class Reference

A class for hashing data. More...

#include <hasher.hpp>

Classes

class  hash_t
 A helper class for storing the data hash. More...
 

Public Member Functions

 hasher_t (const hasher_t &other)
 Copy the hash state into a new hasher_t object. More...
 
hasher_toperator= (const hasher_t &other)
 Copy the hash state to an existing hasher_t object. More...
 
void update (const void *data, const size_t size)
 Update the hash with more data. More...
 
void update (const std::string &text)
 Update the hash with more data. More...
 
void update (const string_list_t &data)
 Update the hash with more data. More...
 
void update (const std::map< std::string, std::string > &data)
 Update the hash with more data. More...
 
void update_from_file (const std::string &path)
 Update the hash with more data. More...
 
void update_from_file_deterministic (const std::string &path)
 Update the hash with more data. More...
 
void inject_separator ()
 Update the hash with a separator sequence. More...
 
hash_t final ()
 Finalize the hash calculation. More...
 

Private Member Functions

void update_from_ar_data (const std::string &data)
 Update the hash with data from an AR archive. More...
 

Private Attributes

void * m_state = nullptr
 

Detailed Description

A class for hashing data.

Constructor & Destructor Documentation

◆ hasher_t()

bcache::hasher_t::hasher_t ( const hasher_t other)

Copy the hash state into a new hasher_t object.

Parameters
otherThe source state to be duplicated.

Member Function Documentation

◆ final()

hasher_t::hash_t bcache::hasher_t::final ( )

Finalize the hash calculation.

Returns
the result of the hash.
Note
This method must only be called once.

◆ inject_separator()

void bcache::hasher_t::inject_separator ( )

Update the hash with a separator sequence.

Injecting a separator sequence between other data items is useful for avoiding hash collisions due to similarities of adjacent elements (e.g. "hello","world" v.s. "hell","oworld").

◆ operator=()

hasher_t & bcache::hasher_t::operator= ( const hasher_t other)

Copy the hash state to an existing hasher_t object.

Parameters
otherThe source state to be duplicated.

◆ update() [1/4]

void bcache::hasher_t::update ( const std::map< std::string, std::string > &  data)

Update the hash with more data.

Parameters
dataThe data to hash.

◆ update() [2/4]

void bcache::hasher_t::update ( const std::string &  text)
inline

Update the hash with more data.

Parameters
textThe data to hash.

◆ update() [3/4]

void bcache::hasher_t::update ( const string_list_t data)

Update the hash with more data.

Parameters
dataThe data to hash.

◆ update() [4/4]

void bcache::hasher_t::update ( const void *  data,
const size_t  size 
)

Update the hash with more data.

Parameters
dataPointer to the data to hash.
sizeThe number of bytes to hash.

◆ update_from_ar_data()

void bcache::hasher_t::update_from_ar_data ( const std::string &  data)
private

Update the hash with data from an AR archive.

Parameters
dataThe raw AR data.

◆ update_from_file()

void bcache::hasher_t::update_from_file ( const std::string &  path)

Update the hash with more data.

Parameters
pathPath to a file that contains the data to hash.
Exceptions
runtime_errorif the operation could not be completed.

◆ update_from_file_deterministic()

void bcache::hasher_t::update_from_file_deterministic ( const std::string &  path)

Update the hash with more data.

This method tries to produce a deterministic hash by employing file format specific heuristics to exclude things like time stamps.

Parameters
pathPath to a file that contains the data to hash.
Exceptions
runtime_errorif the operation could not be completed.

The documentation for this class was generated from the following files: