libabigail
Loading...
Searching...
No Matches
abigail::hashing Namespace Reference

Namespace for hashing. More...

Enumerations

enum  hashing_state {
  HASHING_NOT_DONE_STATE , HASHING_STARTED_STATE , HASHING_CYCLED_TYPE_STATE , HASHING_SUBTYPE_STATE ,
  HASHING_FINISHED_STATE
}
 Enumeration of the different hashing states of an IR node being hashed. More...
 

Functions

hash_t combine_hashes (hash_t val1, hash_t val2)
 Combine two hash values to produce a third hash value.
 
bool deserialize_hash (const string &input, uint64_t &hash)
 Read a string of characters representing a string of hexadecimal digits which itself represents a hash value that was computed using the XH64 algorithm from the xxhash project.
 
uint32_t fnv_hash (const std::string &str)
 Compute a stable string hash.
 
hashing::hashing_state get_hashing_state (const type_or_decl_base &tod)
 Get the hashing state of an IR node.
 
hash_t hash (const std::string &str)
 Hash a string.
 
hash_t hash (std::uint64_t v, std::uint64_t seed=0)
 
hash_t hash (uint64_t v, uint64_t seed)
 Hash an integer value and combine it with a hash previously computed.
 
bool is_recursive_artefact (const type_or_decl_base &t)
 Test if an artifact is recursive.
 
void is_recursive_artefact (const type_or_decl_base &t, bool f)
 Set the property that flags an artifact as recursive.
 
bool serialize_hash (uint64_t hash, string &output)
 Serialiaze a hash value computed using the XH64 algorithm (from the xxhash project) into a string of characters representing the digits of the hash in the canonical form requested by the xxhash project. That canonical form is basically a big endian representation of the hexadecimal hash number.
 
void set_hashing_state (const type_or_decl_base &tod, hashing::hashing_state s)
 Set the hashing state of an IR node.
 

Detailed Description

Namespace for hashing.

Enumeration Type Documentation

◆ hashing_state

Enumeration of the different hashing states of an IR node being hashed.

Enumerator
HASHING_NOT_DONE_STATE 

No hashing has been done/started.

HASHING_STARTED_STATE 

Hashing started but is not yet finished.

Note that when a type_or_decl_base::priv::set_hash_value is invoked on an artifact which has this state, then the hash value is set/saved onto the artifact.

HASHING_CYCLED_TYPE_STATE 

A cycle has been detected in the graph on the current node node.

This means the hashing has started on the current IR node and while hashing its children nodes, this very same IR node is visited again to be hashed. This is a cycle and it needs to be broken otherwise the hashing continues forever.

Note that when a type_or_decl_base::priv::set_hash_value is invoked on an artifact which has this state, then the hash value is set/saved onto the artifact.

HASHING_SUBTYPE_STATE 

Hashing a sub-type while hashing another type.

When a type_or_decl_base::hash_value() is invoked on an artifact which has this state, it means the hash value that is computed must NOT be set/saved onto the artifact. type_or_decl_base::priv::set_hash_value is where this is enforced.

HASHING_FINISHED_STATE 

Hashing of given IR node started and is now done. If an ABI artifact is in this state, then it must have an hash value available and should be get by peek_hash_value or type_or_decl_base::hash_value().

Definition at line 24 of file abg-hash.h.

Function Documentation

◆ combine_hashes()

hash_t combine_hashes ( hash_t val1,
hash_t val2 )

Combine two hash values to produce a third hash value.

If one of the hash values is empty then the other one is returned, intact. If the two hash values are empty then an empty hash value is returned as a result.

Parameters
val1the first hash value.
val2the second hash value.
Returns
a combination of the hash values val1 and val2.

Definition at line 172 of file abg-hash.cc.

◆ deserialize_hash()

bool deserialize_hash ( const string & input,
uint64_t & hash )

Read a string of characters representing a string of hexadecimal digits which itself represents a hash value that was computed using the XH64 algorithm from the xxhash project.

That string of digit (characters) is laid out in the "canonical form" requested by the xxhash project. That form is basically the hash number, represented in big endian.

Parameters
inputthe input string of characters to consider.
hashthe resulting hash value de-serialized from input. This is set by the function iff it returns true.
Returns
true iff the function could de-serialize the characters string input into the hash value hash.

Definition at line 99 of file abg-hash.cc.

◆ fnv_hash()

uint32_t fnv_hash ( const std::string & str)

Compute a stable string hash.

std::hash has no portability or stability guarantees so is unsuitable where reproducibility is a requirement such as in XML output.

This is the 32-bit FNV-1a algorithm. The algorithm, reference code and constants are all unencumbered. It is fast and has reasonable distribution properties.

https://en.wikipedia.org/wiki/Fowler-Noll-Vo_hash_function

Parameters
strthe string to hash.
Returns
an unsigned 32 bit hash value.

Definition at line 241 of file abg-hash.cc.

◆ get_hashing_state()

hashing::hashing_state get_hashing_state ( const type_or_decl_base & tod)

Get the hashing state of an IR node.

Parameters
todthe type or decl IR node to get the hashing state for.
Returns
the hashing state of tod.

Definition at line 261 of file abg-hash.cc.

◆ hash() [1/2]

hash_t hash ( const std::string & str)

Hash a string.

Parameters
strthe string to hash.
Returns
the resulting hash value.

Definition at line 219 of file abg-hash.cc.

◆ hash() [2/2]

hash_t hash ( uint64_t v,
uint64_t seed )

Hash an integer value and combine it with a hash previously computed.

Parameters
vthe value to hash.
seeda previous hash value that is to be combined with the result of hashing v. This is can be zero if no previous hash value is available.
Returns
the resulting hash value.

Definition at line 196 of file abg-hash.cc.

◆ is_recursive_artefact() [1/2]

bool is_recursive_artefact ( const type_or_decl_base & t)

Test if an artifact is recursive.

For now, a recursive artifact is a type that contains a sub-type that refers to itself.

Parameters
tthe artifact to consider.
Returns
truf iff t is recursive.

Definition at line 302 of file abg-hash.cc.

◆ is_recursive_artefact() [2/2]

void is_recursive_artefact ( const type_or_decl_base & t,
bool f )

Set the property that flags an artifact as recursive.

For now, a recursive artifact is a type that contains a sub-type that refers to itself.

Parameters
tthe artifact to consider.
fthe new value of the flag. If true, then the artefact t is considered recursive.

Definition at line 327 of file abg-hash.cc.

◆ serialize_hash()

bool serialize_hash ( uint64_t hash,
string & output )

Serialiaze a hash value computed using the XH64 algorithm (from the xxhash project) into a string of characters representing the digits of the hash in the canonical form requested by the xxhash project. That canonical form is basically a big endian representation of the hexadecimal hash number.

Parameters
hashthe hash number to serialize.
outputthe resulting string of characters representing the hash value hash in its serialized form. This is set iff the function return true.
Returns
true iff the function could serialize the hash value hash into a serialized form that is set into the output parameter output.

Definition at line 138 of file abg-hash.cc.

◆ set_hashing_state()

void set_hashing_state ( const type_or_decl_base & tod,
hashing::hashing_state s )

Set the hashing state of an IR node.

Parameters
todthe type or decl IR node to set the hashing state for.
sthe new hashing state to set.

Definition at line 280 of file abg-hash.cc.