Skip to content

Commit

Permalink
🚧 additive metric
Browse files Browse the repository at this point in the history
  • Loading branch information
yoann-dufresne committed Oct 8, 2024
1 parent 81c43fe commit 2cda9d4
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions app/avalanche.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include <iostream>
#include <cstdint>
#include <memory>

#include "AvalancheTest.hpp"
#include "HashFunction.hpp"
#include "Operator.hpp"
#include "XorLeftShift.hpp"
#include "XorRightShift.hpp"
#include "Multiply.hpp"
#include "AddShift.hpp"
#include "Masking.hpp"
#include "Multiply.hpp"
#include "log.h"


int main()
{
CLUTCHLOG(progress, "Set config");
clutchlog_config(); // common config
auto& log = clutchlog::logger();
log.threshold("XDebug");

// The size of the values to manipulate is 57 bits.
size_t value_size{32};
using myuint = uint32_t;

CLUTCHLOG(progress, "Try HashFunc");
// Create an instance of HashFunction with a value size of 64 bits
HashFunction<myuint> hashFunc(value_size, "hash");

// Add shift operators
hashFunc.add_operator(std::make_unique<XorRightShift<myuint>>(16, value_size));
hashFunc.add_operator(std::make_unique<Multiply<myuint>>(0x7feb352dU, value_size));
hashFunc.add_operator(std::make_unique<XorRightShift<myuint>>(15, value_size));
hashFunc.add_operator(std::make_unique<Multiply<myuint>>(0x846ca68bU, value_size));
hashFunc.add_operator(std::make_unique<XorRightShift<myuint>>(16, value_size));

CLUTCHLOG(note, "Complete with masks");
// Complete with masks if necessary
hashFunc.complete_with_masks();

// Print the string representation of the hash function
std::cout << hashFunc.to_string() << std::endl;

StrictAvalancheTest<myuint> strict_test{hashFunc};
CLUTCHLOG(progress, "Run SoftAvalancheTest");
for (size_t i = 0; i < 20; i++)
{
CLUTCHLOG(note, " 10 000 iterations:\t" << strict_test.run(value_size * 10000UL));
}

return 0;
}

0 comments on commit 2cda9d4

Please sign in to comment.