summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorschmidt <douglascraigschmidt@users.noreply.github.com>1998-10-06 01:07:33 +0000
committerschmidt <douglascraigschmidt@users.noreply.github.com>1998-10-06 01:07:33 +0000
commitb98e64990a1ff45cdccc502e53acbb1aca1fcb6a (patch)
tree8e12eca3ae51d3f1fe20dcbf99828243e104c375 /apps
parent6257a412bbf4e299e83958af9a6d3ff1a4b5d1aa (diff)
downloadATCD-b98e64990a1ff45cdccc502e53acbb1aca1fcb6a.tar.gz
.
Diffstat (limited to 'apps')
-rw-r--r--apps/gperf/ChangeLog4
-rw-r--r--apps/gperf/src/Gen_Perf.cpp53
-rw-r--r--apps/gperf/src/Gen_Perf.h2
3 files changed, 44 insertions, 15 deletions
diff --git a/apps/gperf/ChangeLog b/apps/gperf/ChangeLog
index 6959633dbd7..0245e8384ec 100644
--- a/apps/gperf/ChangeLog
+++ b/apps/gperf/ChangeLog
@@ -1,5 +1,9 @@
Mon Oct 5 18:24:15 1998 Douglas C. Schmidt <schmidt@tango.cs.wustl.edu>
+ * src/Gen_Perf: Created a new function that allows us to split the
+ binary search and perfect hash logic apart. Thanks to Vishal
+ and Alex for reporting this.
+
* src/Key_List.cpp (dump): Fixed the unsigned problems with line
1502 YET again... Thanks to David/Darrell for reporting this.
diff --git a/apps/gperf/src/Gen_Perf.cpp b/apps/gperf/src/Gen_Perf.cpp
index 7a2b8900fd3..0cf7f440683 100644
--- a/apps/gperf/src/Gen_Perf.cpp
+++ b/apps/gperf/src/Gen_Perf.cpp
@@ -296,22 +296,15 @@ Gen_Perf::open (void)
return 0;
}
-// Does the hard stuff.... Initializes the Bool Array, and attempts
-// to find a perfect function that will hash all the key words without
-// getting any duplications. This is made much easier since we aren't
-// attempting to generate *minimum* functions, only perfect ones. If
-// we can't generate a perfect function in one pass *and* the user
-// hasn't enabled the DUP option, we'll inform the user to try the
-// randomization option, use -D, or choose alternative key positions.
-// The alternatives (e.g., back-tracking) are too time-consuming, i.e,
-// exponential in the number of keys.
-
int
-Gen_Perf::run (void)
+Gen_Perf::compute_binary_search (void)
{
- if (this->open () == -1)
- return 1;
+ return 0;
+}
+int
+Gen_Perf::compute_perfect_hash (void)
+{
List_Node *curr;
for (curr = this->key_list.head;
@@ -326,7 +319,7 @@ Gen_Perf::run (void)
if (ptr->hash_value == curr->hash_value)
{
if (this->change (ptr, curr) == -1)
- return 1;
+ return -1;
break;
}
num_done++;
@@ -352,9 +345,39 @@ Gen_Perf::run (void)
"\nInternal error, duplicate value %d:\n"
"try options -D or -r, or use new key positions.\n\n",
this->hash (curr)));
- return 1;
+ return -1;
}
+ return 0;
+}
+
+// Does the hard stuff.... Initializes the Bool Array, and attempts
+// to find a perfect function that will hash all the key words without
+// getting any duplications. This is made much easier since we aren't
+// attempting to generate *minimum* functions, only perfect ones. If
+// we can't generate a perfect function in one pass *and* the user
+// hasn't enabled the DUP option, we'll inform the user to try the
+// randomization option, use -D, or choose alternative key positions.
+// The alternatives (e.g., back-tracking) are too time-consuming, i.e,
+// exponential in the number of keys.
+
+int
+Gen_Perf::run (void)
+{
+ if (this->open () == -1)
+ return 1;
+
+ if (option[BINARYSEARCH])
+ {
+ if (this->compute_binary_search () != 0)
+ return 1;
+ }
+ else
+ {
+ if (this->compute_perfect_hash () != 0)
+ return 1;
+ }
+
// Sorts the key word list by hash value, and then outputs the list.
// The generated hash table code is only output if the early stage
// of processing turned out O.K.
diff --git a/apps/gperf/src/Gen_Perf.h b/apps/gperf/src/Gen_Perf.h
index 46fc6cce181..a5a800b0441 100644
--- a/apps/gperf/src/Gen_Perf.h
+++ b/apps/gperf/src/Gen_Perf.h
@@ -49,6 +49,8 @@ private:
int open (void);
int change (List_Node *prior, List_Node *curr);
int affects_prev (char c, List_Node *curr);
+ int compute_perfect_hash (void);
+ int compute_binary_search (void);
static int hash (List_Node *key_node);
static int compute_disjoint_union (char *s1, char *s2, char *s3);
static void sort_set (char *union_set, int len);