for review: cleanup of part of the runtime name space
Zoltan Somogyi
zs at cs.mu.OZ.AU
Wed Aug 26 15:10:00 AEST 1998
Ensure that all modules in the runtime matching the pattern mercury_table*
have to do with tabled evaluation.
runtime/mercury_table.[ch]:
runtime/mercury_hash_table.[ch]:
Rename the mercury_table module as mercury_hash_table. Change the
names of the entities it exports to make them start with MR_.
runtime/mercury_label.c:
Conform to the name changes.
runtime/Mmakefile:
Refer to the new names.
Zoltan.
Index: runtime/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/Mmakefile,v
retrieving revision 1.37
diff -u -u -r1.37 Mmakefile
--- Mmakefile 1998/08/24 08:24:31 1.37
+++ Mmakefile 1998/08/25 05:03:47
@@ -39,6 +39,7 @@
mercury_getopt.h \
mercury_goto.h \
mercury_grade.h \
+ mercury_hash_table.h \
mercury_heap.h \
mercury_heap_profile.h \
mercury_imp.h \
@@ -60,7 +61,6 @@
mercury_stack_layout.h \
mercury_stack_trace.h \
mercury_string.h \
- mercury_table.h \
mercury_table_any.h \
mercury_table_enum.h \
mercury_table_builtins.h \
@@ -108,6 +107,7 @@
mercury_getopt.c \
mercury_getopt1.c \
mercury_grade.c \
+ mercury_hash_table.c \
mercury_heap_profile.c \
mercury_ho_call.c \
mercury_label.c \
@@ -120,7 +120,6 @@
mercury_regs.c \
mercury_signal.c \
mercury_stack_trace.c \
- mercury_table.c \
mercury_table_any.c \
mercury_table_enum.c \
mercury_table_builtins.c \
Index: runtime/mercury_hash_table.c
===================================================================
RCS file: mercury_hash_table.c
diff -N mercury_hash_table.c
--- /dev/null Wed May 28 10:49:58 1997
+++ mercury_hash_table.c Fri Aug 21 19:17:43 1998
@@ -0,0 +1,158 @@
+/*
+** Copyright (C) 1993-1998 The University of Melbourne.
+** This file may only be copied under the terms of the GNU Library General
+** Public License - see the file COPYING.LIB in the Mercury distribution.
+*/
+
+/*
+** Hash table handling module.
+**
+** This file supplies data manipulation routines to other modules;
+** it does not store any data itself. Its routines are generic,
+** applicable to the storage of any kind of data structure with
+** a primary key and a hash function on it.
+*/
+
+#include "mercury_imp.h"
+
+#include <stdio.h>
+#include "mercury_std.h"
+#include "mercury_dlist.h"
+#include "mercury_hash_table.h"
+
+/*
+** Initialize a table.
+*/
+
+void
+MR_ht_init_table(MR_Hash_Table *table)
+{
+ reg int i;
+
+ table->MR_ht_store = make_many(List *, table->MR_ht_size);
+
+ for (i = 0; i < table->MR_ht_size; i++) {
+ table->MR_ht_store[i] = NULL;
+ }
+}
+
+/*
+** Look up and return the entry corresponding to the key
+** in a table.
+*/
+
+void *
+MR_ht_lookup_table(const MR_Hash_Table *table, const void *key)
+{
+ reg List *ptr;
+ reg int h;
+
+ h = MR_tablehash(table)(key);
+
+#ifdef MR_HASHDEBUG
+ if (! (0 <= h && h < table->MR_ht_size)) {
+ fprintf(stderr, "internal error: bad hash index in "
+ "lookup_table: %d, table size %d\n",
+ h, table->MR_ht_size);
+ }
+#endif
+
+ for_list (ptr, table->MR_ht_store[h]) {
+ if (MR_tableequal(table)(key, MR_tablekey(table)(ldata(ptr)))) {
+ return ldata(ptr);
+ }
+ }
+
+ return NULL;
+}
+
+/*
+** Insert a new entry into the table.
+** Return whether it was there before.
+*/
+
+bool
+MR_ht_insert_table(const MR_Hash_Table *table, void *entry)
+{
+ reg List *ptr;
+ reg const void *key;
+ reg int h;
+
+ key = MR_tablekey(table)(entry);
+ h = MR_tablehash(table)(key);
+
+#ifdef MR_HASHDEBUG
+ if (! (0 <= h && h < table->MR_ht_size)) {
+ fprintf(stderr, "internal error: bad hash index in "
+ "lookup_table: %d, table size %d\n",
+ h, table->MR_ht_size);
+ }
+#endif
+
+ for_list (ptr, table->MR_ht_store[h]) {
+ if (MR_tableequal(table)(key, MR_tablekey(table)(ldata(ptr)))) {
+ return TRUE;
+ }
+ }
+
+ table->MR_ht_store[h] = addhead(table->MR_ht_store[h], entry);
+ return FALSE;
+}
+
+/*
+** Return all table entries in a list.
+*/
+
+List *
+MR_ht_get_all_entries(const MR_Hash_Table *table)
+{
+ reg List *list;
+ reg int i;
+
+ list = makelist0();
+ for (i = 0; i < table->MR_ht_size; i++) {
+ addndlist(list, table->MR_ht_store[i]);
+ }
+
+ return list;
+}
+
+/*
+** Process all table entries with the specified function.
+*/
+
+void
+MR_ht_process_all_entries(const MR_Hash_Table *table, void f(const void *))
+{
+ reg List *ptr;
+ reg int i;
+
+ for (i = 0; i < table->MR_ht_size; i++) {
+ for_list (ptr, table->MR_ht_store[i]) {
+ f(ldata(ptr));
+ }
+ }
+}
+
+/*
+** Convert a string to a positive int. The return value
+** mod the table size is a good hash value.
+*/
+
+int
+MR_ht_str_to_int(const char *cs)
+{
+ reg int h;
+ reg const char *s;
+
+ s = cs;
+ for (h = 0; *s != '\0'; s++) {
+ h = (h << 1) + *s;
+ }
+
+ if (h < 0) {
+ h = -h;
+ }
+
+ return h;
+}
Index: runtime/mercury_hash_table.h
===================================================================
RCS file: mercury_hash_table.h
diff -N mercury_hash_table.h
--- /dev/null Wed May 28 10:49:58 1997
+++ mercury_hash_table.h Fri Aug 21 19:16:43 1998
@@ -0,0 +1,50 @@
+/*
+** Copyright (C) 1993-1995, 1997-1998 The University of Melbourne.
+** This file may only be copied under the terms of the GNU Library General
+** Public License - see the file COPYING.LIB in the Mercury distribution.
+*/
+
+/*
+** Defines the interface to the hash table module.
+**
+** Note that this module has nothing to do with the implementation
+** of the "tabling" pragmas such as `pragma memo' -- the implementation
+** of those features uses Tries, not hash tables, and is defined
+** in mercury_tabling.h.
+*/
+
+#ifndef MERCURY_HASH_TABLE_H
+#define MERCURY_HASH_TABLE_H
+
+#include "mercury_std.h" /* for bool */
+#include "mercury_dlist.h" /* for List */
+
+typedef struct {
+ int MR_ht_size;
+ List **MR_ht_store;
+ const void *(*MR_ht_key)(const void *); /* applied to entries */
+ int (*MR_ht_hash)(const void *); /* applied to keys */
+ bool (*MR_ht_equal)(const void *, const void *);
+ /* applied to two keys */
+} MR_Hash_Table;
+
+#define MR_init_hash_table(t) MR_ht_init_table(&t)
+#define MR_lookup_hash_table(t, k) MR_ht_lookup_table(&t, (const void *) k)
+#define MR_insert_hash_table(t, e) MR_ht_insert_table(&t, (void *) e)
+#define MR_get_all_entries(t) MR_ht_get_all_entries(&t)
+#define MR_process_all_entries(t, f) MR_ht_process_all_entries(&t, f)
+#define MR_str_to_int(val) MR_ht_str_to_int(val)
+
+#define MR_tablekey(table) (*(table->MR_ht_key))
+#define MR_tablehash(table) (*(table->MR_ht_hash))
+#define MR_tableequal(table) (*(table->MR_ht_equal))
+
+extern void MR_ht_init_table(MR_Hash_Table *);
+extern void *MR_ht_lookup_table(const MR_Hash_Table *, const void *);
+extern bool MR_ht_insert_table(const MR_Hash_Table *, void *);
+extern List *MR_ht_get_all_entries(const MR_Hash_Table *);
+extern void MR_ht_process_all_entries(const MR_Hash_Table *,
+ void f(const void *));
+extern int MR_ht_str_to_int(const char *);
+
+#endif /* not MERCURY_HASH_TABLE_H */
Index: runtime/mercury_label.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_label.c,v
retrieving revision 1.9
diff -u -u -r1.9 mercury_label.c
--- mercury_label.c 1998/08/24 08:24:43 1.9
+++ mercury_label.c 1998/08/25 05:02:26
@@ -18,7 +18,7 @@
#include "mercury_label.h"
-#include "mercury_table.h" /* for `Table' */
+#include "mercury_hash_table.h" /* for `MR_Hash_Table' and its ops */
#include "mercury_prof.h" /* for prof_output_addr_decl() */
#include "mercury_engine.h" /* for `MR_progdebug' */
#include "mercury_wrapper.h" /* for do_init_modules() */
@@ -62,7 +62,7 @@
static bool equal_addr(const void *addr1, const void *addr2);
static int hash_addr(const void *addr);
-static Table internal_addr_table = {INTERNAL_SIZE, NULL,
+static MR_Hash_Table internal_addr_table = {INTERNAL_SIZE, NULL,
internal_addr, hash_addr, equal_addr};
void
@@ -79,7 +79,7 @@
* sizeof(MR_Entry));
#endif
- init_table(internal_addr_table);
+ MR_init_hash_table(internal_addr_table);
done = TRUE;
}
@@ -209,7 +209,7 @@
/* two labels at same location will happen quite often */
/* when the code generated between them turns out to be empty */
- (void) insert_table(internal_addr_table, internal);
+ (void) MR_insert_hash_table(internal_addr_table, internal);
}
MR_Internal *
@@ -224,7 +224,7 @@
}
#endif
- return (MR_Internal *) lookup_table(internal_addr_table, addr);
+ return (MR_Internal *) MR_lookup_hash_table(internal_addr_table, addr);
}
static const void *
@@ -248,5 +248,5 @@
void
MR_process_all_internal_labels(void f(const void *))
{
- process_all_entries(internal_addr_table, f);
+ MR_process_all_entries(internal_addr_table, f);
}
Index: runtime/mercury_table.c
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_table.c,v
retrieving revision 1.4
diff -u -u -r1.4 mercury_table.c
--- mercury_table.c 1998/07/03 02:35:29 1.4
+++ mercury_table.c 1998/08/13 09:33:14
@@ -1,160 +0,0 @@
-/*
-** Copyright (C) 1993-1998 The University of Melbourne.
-** This file may only be copied under the terms of the GNU Library General
-** Public License - see the file COPYING.LIB in the Mercury distribution.
-*/
-
-/*
-** Table handling module.
-**
-** This file supplies data manipulation routines to other modules;
-** it does not store any data itself. Its routines are generic,
-** applicable to the storage of any kind of data structure with
-** a primary key and a hash function on it.
-*/
-
-#define HASHDEBUG
-
-#include "mercury_imp.h"
-
-#include <stdio.h>
-#include "mercury_std.h"
-#include "mercury_dlist.h"
-#include "mercury_table.h"
-
-/*
-** Initialize a table.
-*/
-
-void
-tab_init_table(Table *table)
-{
- reg int i;
-
- table->ta_store = make_many(List *, table->ta_size);
-
- for (i = 0; i < table->ta_size; i++) {
- table->ta_store[i] = NULL;
- }
-}
-
-/*
-** Look up and return the entry corresponding to the key
-** in a table.
-*/
-
-void *
-tab_lookup_table(const Table *table, const void *key)
-{
- reg List *ptr;
- reg int h;
-
- h = tablehash(table)(key);
-
-#ifdef HASHDEBUG
- if (! (0 <= h && h < table->ta_size)) {
- fprintf(stderr, "internal error: bad hash index in "
- "lookup_table: %d, table size %d\n",
- h, table->ta_size);
- }
-#endif
-
- for_list (ptr, table->ta_store[h]) {
- if (tableequal(table)(key, tablekey(table)(ldata(ptr)))) {
- return ldata(ptr);
- }
- }
-
- return NULL;
-}
-
-/*
-** Insert a new entry into the table.
-** Return whether it was there before.
-*/
-
-bool
-tab_insert_table(const Table *table, void *entry)
-{
- reg List *ptr;
- reg const void *key;
- reg int h;
-
- key = tablekey(table)(entry);
- h = tablehash(table)(key);
-
-#ifdef HASHDEBUG
- if (! (0 <= h && h < table->ta_size)) {
- fprintf(stderr, "internal error: bad hash index in "
- "lookup_table: %d, table size %d\n",
- h, table->ta_size);
- }
-#endif
-
- for_list (ptr, table->ta_store[h]) {
- if (tableequal(table)(key, tablekey(table)(ldata(ptr)))) {
- return TRUE;
- }
- }
-
- table->ta_store[h] = addhead(table->ta_store[h], entry);
- return FALSE;
-}
-
-/*
-** Return all table entries in a list.
-*/
-
-List *
-tab_get_all_entries(const Table *table)
-{
- reg List *list;
- reg int i;
-
- list = makelist0();
- for (i = 0; i < table->ta_size; i++) {
- addndlist(list, table->ta_store[i]);
- }
-
- return list;
-}
-
-/*
-** Process all table entries with the specified function.
-*/
-
-void
-tab_process_all_entries(const Table *table, void f(const void *))
-{
- reg List *ptr;
- reg int i;
-
- for (i = 0; i < table->ta_size; i++) {
- for_list (ptr, table->ta_store[i]) {
- f(ldata(ptr));
- }
- }
-}
-
-/*
-** Convert a string to a positive int. The return value
-** mod the table size is a good hash value.
-*/
-
-int
-tab_str_to_int(const char *cs)
-{
- reg int h;
- reg const char *s;
-
- s = cs;
- for (h = 0; *s != '\0'; s++) {
- h = (h << 1) + *s;
- }
-
- if (h < 0) {
- h = -h;
- }
-
- return h;
-}
Index: runtime/mercury_table.h
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/mercury_table.h,v
retrieving revision 1.5
diff -u -u -r1.5 mercury_table.h
--- mercury_table.h 1998/07/03 02:35:31 1.5
+++ mercury_table.h 1998/08/13 09:33:14
@@ -1,49 +0,0 @@
-/*
-** Copyright (C) 1993-1995, 1997-1998 The University of Melbourne.
-** This file may only be copied under the terms of the GNU Library General
-** Public License - see the file COPYING.LIB in the Mercury distribution.
-*/
-
-/*
-** mercury_table.h - defines the interface to the hash table module.
-**
-** Note that this module has nothing to do with the implementation
-** of the "tabling" pragmas such as `pragma memo' -- the implementation
-** of those features uses Tries, not hash tables, and is defined
-** in mercury_tabling.h.
-*/
-
-#ifndef MERCURY_TABLE_H
-#define MERCURY_TABLE_H
-
-#include "mercury_std.h" /* for bool */
-#include "mercury_dlist.h" /* for List */
-
-typedef struct s_table {
- int ta_size;
- List **ta_store;
- const void * (*ta_key)(const void *); /* applied to entries */
- int (*ta_hash)(const void *); /* applied to keys */
- bool (*ta_equal)(const void *, const void *);
- /* applied to two keys */
-} Table;
-
-#define init_table(t) tab_init_table(&t)
-#define lookup_table(t, k) tab_lookup_table(&t, (const void *) k)
-#define insert_table(t, e) tab_insert_table(&t, (void *) e)
-#define get_all_entries(t) tab_get_all_entries(&t)
-#define process_all_entries(t, f) tab_process_all_entries(&t, f)
-#define str_to_int(val) tab_str_to_int(val)
-
-#define tablekey(table) (*(table->ta_key))
-#define tablehash(table) (*(table->ta_hash))
-#define tableequal(table) (*(table->ta_equal))
-
-extern void tab_init_table(Table *);
-extern void * tab_lookup_table(const Table *, const void *);
-extern bool tab_insert_table(const Table *, void *);
-extern List *tab_get_all_entries(const Table *);
-extern void tab_process_all_entries(const Table *, void f(const void *));
-extern int tab_str_to_int(const char *);
-
-#endif /* not MERCURY_TABLE_H */
More information about the developers
mailing list