0

Based on : https://stackoverflow.com/a/20412573/4058644
I implemented the below:

for (...)
{
    unsigned long long RollingHash = 0;
    int k = LineSize - 1;

    for (size_t j = 0; j < LineSize; ++j)
    {
        if (condition)
        {
            RollingHash += (Line[j] * pow(257, k)) % MOD;
            RollingHash %= MOD;
            k -= 1;
        }
    }
}

However, I have 2 issues:

  1. It does not seem to be much efficient/fast
  2. Adding/Removing values to start or end as per the link does not seem to work

    unsigned long long  h = (Line[0] * pow(257, Line.size()))%MOD;
    old = ((old * 257) + 'h' - h) % MOD;
    

Any ideas?

normaluser
  • 57
  • 2
  • 7
  • *It does not seem to be much efficient/fast* What do you mean by *seem*? Are you just looking at it you think it's slow, or do you have actual numbers that says this is slow and is your bottle neck? – NathanOliver Jan 24 '20 at 13:43
  • @NathanOliver I already tested it, but it takes time on a large set. Time efficiency is important for my project. – normaluser Jan 24 '20 at 14:01
  • If your project is about searching, you can use Adler-32. It should be faster, but it probably lead to more collisions. – zdf Jan 24 '20 at 14:12
  • I am going to store those hashes and use later. Collision is a big issue. – normaluser Jan 24 '20 at 14:17

0 Answers0