From a3fdc9cd82076ece0796d460a3de0dc60717d21e Mon Sep 17 00:00:00 2001
From: Vlad <vlad1997kov@gmail.com>
Date: Tue, 21 Jun 2022 07:14:31 +0200
Subject: [PATCH] Outdated comments, replace COUNTER_INIT_VAL with
 LFU_INIT_VAL, fix typo (#10888)

`COUNTER_INIT_VAL` doesn't exist in the code anymore so we can replace it with `LFU_INIT_VAL` entries
---
 src/evict.c                | 10 +++++-----
 utils/lru/lfu-simulation.c | 10 +++++-----
 2 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/evict.c b/src/evict.c
index 316edf606..6ee85ede5 100644
--- a/src/evict.c
+++ b/src/evict.c
@@ -266,14 +266,14 @@ void evictionPoolPopulate(int dbid, dict *sampledict, dict *keydict, struct evic
  * has a low value.
  *
  * New keys don't start at zero, in order to have the ability to collect
- * some accesses before being trashed away, so they start at COUNTER_INIT_VAL.
- * The logarithmic increment performed on LOG_C takes care of COUNTER_INIT_VAL
- * when incrementing the key, so that keys starting at COUNTER_INIT_VAL
+ * some accesses before being trashed away, so they start at LFU_INIT_VAL.
+ * The logarithmic increment performed on LOG_C takes care of LFU_INIT_VAL
+ * when incrementing the key, so that keys starting at LFU_INIT_VAL
  * (or having a smaller value) have a very high chance of being incremented
  * on access.
  *
  * During decrement, the value of the logarithmic counter is halved if
- * its current value is greater than two times the COUNTER_INIT_VAL, otherwise
+ * its current value is greater than two times the LFU_INIT_VAL, otherwise
  * it is just decremented by one.
  * --------------------------------------------------------------------------*/
 
@@ -295,7 +295,7 @@ unsigned long LFUTimeElapsed(unsigned long ldt) {
 }
 
 /* Logarithmically increment a counter. The greater is the current counter value
- * the less likely is that it gets really implemented. Saturate it at 255. */
+ * the less likely is that it gets really incremented. Saturate it at 255. */
 uint8_t LFULogIncr(uint8_t counter) {
     if (counter == 255) return 255;
     double r = (double)rand()/RAND_MAX;
diff --git a/utils/lru/lfu-simulation.c b/utils/lru/lfu-simulation.c
index 51d639d66..60105e55b 100644
--- a/utils/lru/lfu-simulation.c
+++ b/utils/lru/lfu-simulation.c
@@ -19,7 +19,7 @@ struct entry {
 };
 
 #define to_16bit_minutes(x) ((x/60) & 65535)
-#define COUNTER_INIT_VAL 5
+#define LFU_INIT_VAL 5
 
 /* Compute the difference in minutes between two 16 bit minutes times
  * obtained with to_16bit_minutes(). Since they can wrap around if
@@ -36,7 +36,7 @@ uint16_t minutes_diff(uint16_t now, uint16_t prev) {
 uint8_t log_incr(uint8_t counter) {
     if (counter == 255) return counter;
     double r = (double)rand()/RAND_MAX;
-    double baseval = counter-COUNTER_INIT_VAL;
+    double baseval = counter-LFU_INIT_VAL;
     if (baseval < 0) baseval = 0;
     double limit = 1.0/(baseval*10+1);
     if (r < limit) counter++;
@@ -56,7 +56,7 @@ uint8_t scan_entry(struct entry *e) {
         >= decr_every)
     {
         if (e->counter) {
-            if (e->counter > COUNTER_INIT_VAL*2) {
+            if (e->counter > LFU_INIT_VAL*2) {
                 e->counter /= 2;
             } else {
                 e->counter--;
@@ -89,7 +89,7 @@ int main(void) {
 
     /* Initialize. */
     for (j = 0; j < keyspace_size; j++) {
-        entries[j].counter = COUNTER_INIT_VAL;
+        entries[j].counter = LFU_INIT_VAL;
         entries[j].decrtime = to_16bit_minutes(start);
         entries[j].hits = 0;
         entries[j].ctime = time(NULL);
@@ -131,7 +131,7 @@ int main(void) {
          * 10 and 19, a random one every 10 seconds. */
         if (new_entry_time <= now) {
             idx = 10+(rand()%10);
-            entries[idx].counter = COUNTER_INIT_VAL;
+            entries[idx].counter = LFU_INIT_VAL;
             entries[idx].decrtime = to_16bit_minutes(time(NULL));
             entries[idx].hits = 0;
             entries[idx].ctime = time(NULL);