Kaynağa Gözat

improved collision rate and extended interface

master
madscientist 4 yıl önce
ebeveyn
işleme
fcce969c41
2 değiştirilmiş dosya ile 13 ekleme ve 8 silme
  1. 12
    8
      mishmash.cpp
  2. 1
    0
      mishmash.hpp

+ 12
- 8
mishmash.cpp Dosyayı Görüntüle

@@ -10,7 +10,7 @@

namespace codedweller {

uint32_t primes[256] {
const uint32_t primes[256] {
1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061,
1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109,
1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181,
@@ -49,18 +49,22 @@ uint32_t primes[256] {
};


inline size_t mod256(size_t n) noexcept { return (n & 0xff); }
inline size_t selectedPrime(size_t n) noexcept { return primes[n &0xff]; }

uint32_t mishmash(const unsigned char* buffer, size_t length) noexcept {
uint64_t accumulator = selectedPrime(length);
uint64_t mishmash(const unsigned char* buffer, size_t length, uint64_t accumulator) noexcept {
for(size_t index = 0; index < length; index++) {
unsigned char byte = buffer[index];
accumulator += selectedPrime(index + accumulator);
accumulator *= selectedPrime(byte + accumulator);
accumulator += selectedPrime(byte + accumulator);
accumulator *= selectedPrime(accumulator);
accumulator += accumulator >> 32;
accumulator &= 0x00000fffffffffff;
accumulator &= 0x000fffffffffffff;
}
return static_cast<uint32_t>(accumulator);
return accumulator;
}

uint32_t mishmash(const unsigned char* buffer, size_t length) noexcept {
uint64_t accumulator = mishmash(buffer, length, 0);
return static_cast<uint32_t>(accumulator & 0x00000000ffffffff);
}

uint32_t mishmash(const std::string& s) noexcept {

+ 1
- 0
mishmash.hpp Dosyayı Görüntüle

@@ -11,6 +11,7 @@

namespace codedweller {

uint64_t mishmash(const unsigned char* buffer, size_t length, uint64_t accumulator) noexcept;
uint32_t mishmash(const unsigned char* buffer, size_t length) noexcept;
uint32_t mishmash(const std::string &s) noexcept;
uint32_t mishmash(const std::vector<unsigned char>& v) noexcept;

Loading…
İptal
Kaydet