ark::core::Fnv1aHasher

Defined in header “ark/core/hash.hh”.


This is a hasher that can take in arbitrary data and produce a FNV1A hash (64-bit). You can write to it multiple times before you finalize the hash value.

Methods

  • Fnv1aHasher()
    Constructor. Initializes a new hasher.

  • void add_data(const void * data, size_t length)
    Adds the new data to the hash. The hash is updated with ’length’ bytes.

     std::vector<uint8_t> data1 = {0x07, 0x1e, 0x62, 0x37, 0x2c, 0x02, 0x40, 0x42, 0x14, 0x69};
    
     Fnv1aHasher hasher;
     hasher.add_data(data1.data(), data1.size());
     EXPECT_EQ(hasher.finalize(), 0ULL);
    
  • uint64_t finalize()
    Finalizes the hash and returns the current working value.

     Fnv1aHasher hasher;
    
     hasher.add_data("hello", 5);
     hasher.add_data(" ", 1);
     hasher.add_data("world", 5);
    
     EXPECT_EQ(hasher.finalize(), 0x779a65e7023cd2e7ULL);