Blaming past self

TL;DR

My past self is lucky to not be around here.

In a post from a long, long time ago (A Quiz from my past self) I complained against my then past self about being sloppy and not including the documentation about a specific implementation decision.

So far so good.

So I stumbled again on that post, and read on. Oh, there’s some caching to be done, good. Uh, I tried to optimize the cached parameters in order to minimize the rejection rate, wise. Aha… there are some consideration about how many bits can be considered fine, interesting.

Then, of course, I looked at the code:

if (keys($cache->%*) <= CACHE_SIZE) {
   while (($nbits * $M / $reject_threshold) > ($nbits + 1)) {
      $nbits++;
      $M *= 2;
      $reject_threshold = $M - $M % $N;
   }
}

At this point, I was like 🤦 with both remote-past me and close-past me.

Where is the caching?!?

So, this is what I think it should have been:

if (keys($cache->%*) <= CACHE_SIZE) {
   while (($nbits * $M / $reject_threshold) > ($nbits + 1)) {
      $nbits++;
      $M *= 2;
      $reject_threshold = $M - $M % $N;
   }
   $cache->{$N} = [$nbits, $reject_threshold];
}

So well… hello future me, where did present me mess up this time?!?


Comments? Octodon, , GitHub, Reddit, or drop me a line!