gbranden pushed a commit to branch master
in repository groff.

commit 2f0defab65f0d0b26b644434176b1d651cec6602
Author: G. Branden Robinson <[email protected]>
AuthorDate: Tue Apr 14 04:52:11 2026 -0500

    [troff]: Trivially refactor.
    
    * src/roff/troff/dictionary.h (class dictionary): Rename member
      variables.
        - size -> capacity
        - used -> occupancy
    
    * src/roff/troff/dictionary.cpp (dictionary::dictionary)
      (dictionary::lookup)
      (dictionary::remove)
      (dictionary_iterator::dictionary_iterator): Update dereference sites.
---
 ChangeLog                     | 14 ++++++++++++++
 src/roff/troff/dictionary.cpp | 38 +++++++++++++++++++-------------------
 src/roff/troff/dictionary.h   |  4 ++--
 3 files changed, 35 insertions(+), 21 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 9dcc21191..07919e3a5 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2026-04-14  G. Branden Robinson <[email protected]>
+
+       [troff]: Trivially refactor.
+
+       * src/roff/troff/dictionary.h (class dictionary): Rename member
+       variables.
+       - size -> capacity
+       - used -> occupancy
+       * src/roff/troff/dictionary.cpp (dictionary::dictionary)
+       (dictionary::lookup)
+       (dictionary::remove)
+       (dictionary_iterator::dictionary_iterator): Update dereference
+       sites.
+
 2026-04-14  G. Branden Robinson <[email protected]>
 
        * src/roff/troff/dictionary.cpp: Fix code style nits.
diff --git a/src/roff/troff/dictionary.cpp b/src/roff/troff/dictionary.cpp
index 839d77e0e..a246a87c1 100644
--- a/src/roff/troff/dictionary.cpp
+++ b/src/roff/troff/dictionary.cpp
@@ -43,7 +43,7 @@ static bool is_good_size(unsigned int p)
 }
 
 dictionary::dictionary(int n)
-  : size(n), used(0), threshold(0.5), factor(1.5)
+  : capacity(n), occupancy(0), threshold(0.5), factor(1.5)
 {
   table = new association[n];
 }
@@ -54,9 +54,9 @@ dictionary::dictionary(int n)
 void *dictionary::lookup(symbol s, void *v)
 {
   int i;
-  for (i = int(s.hash() % size);
+  for (i = size_t(s.hash() % capacity);
        table[i].v != 0 /* nullptr */;
-       i == 0 ? i = (size - 1) : --i)
+       i == 0 ? i = (capacity - 1) : --i)
     if (s == table[i].s) {
       if (v != 0 /* nullptr */) {
        void *temp = table[i].v;
@@ -68,19 +68,19 @@ void *dictionary::lookup(symbol s, void *v)
     }
   if (v == 0 /* nullptr */)
     return 0 /* nullptr */;
-  ++used;
+  ++occupancy;
   table[i].v = v;
   table[i].s = s;
-  if (((static_cast<double>(used) / static_cast<double>(size))
-      >= threshold) || ((used + 1) >= size)) {
-    int old_size = size;
-    size = int(size * factor);
-    while (!is_good_size(size))
-      ++size;
+  if (((static_cast<double>(occupancy) / static_cast<double>(capacity))
+      >= threshold) || ((occupancy + 1) >= capacity)) {
+    int old_capacity = capacity;
+    capacity = int(capacity * factor);
+    while (!is_good_size(capacity))
+      ++capacity;
     association *old_table = table;
-    table = new association[size];
-    used = 0;
-    for (i = 0; i < old_size; i++)
+    table = new association[capacity];
+    occupancy = 0;
+    for (i = 0; i < old_capacity; i++)
       if (old_table[i].v != 0 /* nullptr */)
        (void) lookup(old_table[i].s, old_table[i].v);
     delete[] old_table;
@@ -103,9 +103,9 @@ void *dictionary::remove(symbol s)
 {
   // this relies on the fact that we are using linear probing
   int i;
-  for (i = int(s.hash() % size);
+  for (i = int(s.hash() % capacity);
        table[i].v != 0 /* nullptr */ && s != table[i].s;
-       i == 0 ? i = (size - 1) : --i)
+       i == 0 ? i = (capacity - 1) : --i)
     ;
   void *p = table[i].v;
   while (table[i].v != 0 /* nullptr */) {
@@ -115,15 +115,15 @@ void *dictionary::remove(symbol s)
     do {
       --i;
       if (i < 0)
-       i = size - 1;
+       i = capacity - 1;
       if (table[i].v == 0 /* nullptr */)
        break;
-      r = int(table[i].s.hash() % size);
+      r = int(table[i].s.hash() % capacity);
     } while ((i <= r && r < j) || (r < j && j < i) || (j < i && i <= r));
     table[j] = table[i];
   }
   if (p != 0 /* nullptr */)
-    --used;
+    --occupancy;
   return p;
 }
 
@@ -133,7 +133,7 @@ dictionary_iterator::dictionary_iterator(dictionary &d) : 
dict(&d), i(0)
 
 bool dictionary_iterator::get(symbol *sp, void **vp)
 {
-  for (; i < dict->size; i++)
+  for (; i < dict->capacity; i++)
     if (dict->table[i].v) {
       *sp = dict->table[i].s;
       if (vp != 0 /* nullptr */)
diff --git a/src/roff/troff/dictionary.h b/src/roff/troff/dictionary.h
index 5e3d57aa2..53803fbe4 100644
--- a/src/roff/troff/dictionary.h
+++ b/src/roff/troff/dictionary.h
@@ -37,8 +37,8 @@ public:
 };
 
 class dictionary {
-  int size;
-  int used;
+  int capacity;
+  int occupancy;
   double threshold;
   double factor;
   association *table;

_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to