A simple library designed to make it easier to store a hash alongside EEPROM data.
Simple summation of bytes.
Quality: Poor Hash Type: Any Integer Code Size: Small Speed: Fast
hash = 0
foreach byte in object
hash = hash + byte
return hash
Algorithm provided by Donald Knuth in The Art Of Computer Programming Volume 3, Chapter 6.4.
Quality: Decent Hash Type: 32-bit Unsigned Integer Code Size: Smallish Speed: Unknown
hash = size(object)
foreach byte in object
hash = ((hash << 5) ^ (hash >> 27)) + byte
return hash
// Save object to EEPROM
Hashing::EEPROM::putWithHash<Hashing::KnuthHash>(address, object)// Create alias for desired hashing function
using Hash = Hashing::KnuthHash;
// Save object to EEPROM
Hashing::EEPROM::putWithHash<Hash>(address, object);// Create a function object
Hashing::KnuthHash hash;
// Save object to EEPROM
Hashing::EEPROM::putWithHash(address, object, hash)// Load object from EEPROM
if(Hashing::EEPROM::getWithHash<Hashing::KnuthHash>(address, object))
{
// This runs if the hash was valid
}
else
{
// This runs if the hash was invalid
}// Load object from EEPROM
if(!Hashing::EEPROM::getWithHash<Hashing::KnuthHash>(address, object))
{
// This runs if the hash was invalid
}// Create alias for desired hashing function
using Hash = Hashing::KnuthHash;
// Load object from EEPROM
if(Hashing::EEPROM::getWithHash<Hash>(address, object))
{
// This runs if the hash was valid
}
else
{
// This runs if the hash was invalid
}// Create alias for desired hashing function
using Hash = Hashing::KnuthHash;
// Load object from EEPROM
if(!Hashing::EEPROM::getWithHash<Hash>(address, object))
{
// This runs if the hash was invalid
}// Create a function object
Hashing::KnuthHash hash;
// Load object from EEPROM
if(Hashing::EEPROM::getWithHash(address, object, hash))
{
// This runs if the hash was valid
}
else
{
// This runs if the hash was invalid
}// Create a function object
Hashing::KnuthHash hash;
// Load object from EEPROM
if(!Hashing::EEPROM::getWithHash(address, object, hash))
{
// This runs if the hash was invalid
}// Create alias for desired hashing function
using Hash = Hashing::KnuthHash;
// Compute the hash of an object
auto hash_value = Hash::hash(object);// Compute the hash of an object
auto hash_value = Hashing::KnuthHash::hash(object);// Create alias for desired hashing function
using Hash = Hashing::KnuthHash;
// Create a function object
Hash hash;
// Compute the hash of an object
auto hash_value = hash(object);// Create a function object
Hashing::KnuthHash hash;
// Compute the hash of an object
auto hash_value = hash(object);