mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-17 06:47:17 +00:00
Estimated hours taken: 3
Branches: main
Provide a mechanism for gathering statistics about which predicates occur most
frequently in the I/O action table.
Instead of adding a new mdb command, consolidate three existing mdb commands
(proc_stats, label_stats and var_name_stats) into a single "stats" command,
and add a new variant for stats on I/O tabling.
doc/mdb_categories:
doc/user_guide.texi:
Document the changes in mdb commands.
runtime/mercury_trace_base.[ch]:
Add a new function for printing stats on the predicate in the I/O
action table.
Add headers to each section of this file.
runtime/mercury_hash_table.[ch]:
Remove the const qualifier from the return type of the lookup function,
since mercury_trace_base.c now needs to modify a looked-up record.
Move the documentation on the functions in this module to the header
file.
trace/mercury_trace_internal.c:
Merge the three previous mdb commands into one, and add the new
alternative.
trace/mercury_trace_tables.c:
Minor change in formatting.
trace/mercury_trace_tables.c:
Minor style fix.
tests/debugger/completion.{inp,exp}:
tests/debugger/mdb_command_test.inp:
Change these test cases to account for the disappearance of the
three old mdb commands and the appearance of the new one.
136 lines
2.6 KiB
C
136 lines
2.6 KiB
C
/*
|
|
** Copyright (C) 1993-2000, 2004-2005 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"
|
|
|
|
void
|
|
MR_ht_init_table(MR_Hash_Table *table)
|
|
{
|
|
int i;
|
|
|
|
table->MR_ht_store = MR_GC_NEW_ARRAY(MR_Dlist *, table->MR_ht_size);
|
|
|
|
for (i = 0; i < table->MR_ht_size; i++) {
|
|
table->MR_ht_store[i] = NULL;
|
|
}
|
|
}
|
|
|
|
void *
|
|
MR_ht_lookup_table(const MR_Hash_Table *table, const void *key)
|
|
{
|
|
MR_Dlist *ptr;
|
|
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
|
|
|
|
MR_for_dlist (ptr, table->MR_ht_store[h]) {
|
|
if (MR_tableequal(table)(key,
|
|
MR_tablekey(table)(MR_dlist_data(ptr))))
|
|
{
|
|
return (void *) MR_dlist_data(ptr);
|
|
}
|
|
}
|
|
|
|
return NULL;
|
|
}
|
|
|
|
const void *
|
|
MR_ht_insert_table(const MR_Hash_Table *table, void *entry)
|
|
{
|
|
MR_Dlist *ptr;
|
|
const void *key;
|
|
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
|
|
|
|
MR_for_dlist (ptr, table->MR_ht_store[h]) {
|
|
if (MR_tableequal(table)(key,
|
|
MR_tablekey(table)(MR_dlist_data(ptr))))
|
|
{
|
|
return MR_dlist_data(ptr);
|
|
}
|
|
}
|
|
|
|
table->MR_ht_store[h] = MR_dlist_addhead(table->MR_ht_store[h], entry);
|
|
return NULL;
|
|
}
|
|
|
|
MR_Dlist *
|
|
MR_ht_get_all_entries(const MR_Hash_Table *table)
|
|
{
|
|
MR_Dlist *list;
|
|
int i;
|
|
|
|
list = MR_dlist_makelist0();
|
|
for (i = 0; i < table->MR_ht_size; i++) {
|
|
MR_dlist_addndlist(list, table->MR_ht_store[i]);
|
|
}
|
|
|
|
return list;
|
|
}
|
|
|
|
void
|
|
MR_ht_process_all_entries(const MR_Hash_Table *table, void f(const void *))
|
|
{
|
|
MR_Dlist *ptr;
|
|
int i;
|
|
|
|
for (i = 0; i < table->MR_ht_size; i++) {
|
|
MR_for_dlist (ptr, table->MR_ht_store[i]) {
|
|
f(MR_dlist_data(ptr));
|
|
}
|
|
}
|
|
}
|
|
|
|
int
|
|
MR_ht_str_to_int(const char *cs)
|
|
{
|
|
int h;
|
|
const char *s;
|
|
|
|
s = cs;
|
|
for (h = 0; *s != '\0'; s++) {
|
|
h = (h << 1) + *s;
|
|
}
|
|
|
|
if (h < 0) {
|
|
h = -h;
|
|
}
|
|
|
|
return h;
|
|
}
|