1998-06-12 11:38:32 +02:00
|
|
|
/* GLIB - Library of useful routines for C programming
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the Free
|
|
|
|
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
1998-12-15 06:28:02 +01:00
|
|
|
|
1999-02-24 07:14:27 +01:00
|
|
|
/*
|
|
|
|
* Modified by the GLib Team and others 1997-1999. See the AUTHORS
|
|
|
|
* file for a list of people on the GLib Team. See the ChangeLog
|
|
|
|
* files for a list of changes. These files are distributed with
|
|
|
|
* GLib at ftp://ftp.gtk.org/pub/gtk/.
|
|
|
|
*/
|
|
|
|
|
1998-12-15 06:28:02 +01:00
|
|
|
/*
|
|
|
|
* MT safe
|
|
|
|
*/
|
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
#include "glib.h"
|
|
|
|
#include <stdarg.h>
|
1998-06-18 22:37:11 +02:00
|
|
|
#include <string.h>
|
1998-06-12 11:38:32 +02:00
|
|
|
|
|
|
|
typedef struct _GRealRelation GRealRelation;
|
|
|
|
typedef struct _GRealTuples GRealTuples;
|
|
|
|
|
|
|
|
struct _GRealRelation
|
|
|
|
{
|
|
|
|
gint fields;
|
|
|
|
gint current_field;
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
GHashTable *all_tuples;
|
|
|
|
GHashTable **hashed_tuple_tables;
|
|
|
|
GMemChunk *tuple_chunk;
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
gint count;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _GRealTuples
|
|
|
|
{
|
|
|
|
gint len;
|
|
|
|
gint width;
|
|
|
|
gpointer *data;
|
|
|
|
};
|
|
|
|
|
1998-08-17 16:47:49 +02:00
|
|
|
static gboolean
|
|
|
|
tuple_equal_2 (gconstpointer v_a,
|
|
|
|
gconstpointer v_b)
|
1998-06-12 11:38:32 +02:00
|
|
|
{
|
|
|
|
gpointer* a = (gpointer*) v_a;
|
|
|
|
gpointer* b = (gpointer*) v_b;
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
return a[0] == b[0] && a[1] == b[1];
|
|
|
|
}
|
|
|
|
|
1998-08-17 16:47:49 +02:00
|
|
|
static guint
|
1998-06-12 11:38:32 +02:00
|
|
|
tuple_hash_2 (gconstpointer v_a)
|
|
|
|
{
|
|
|
|
gpointer* a = (gpointer*) v_a;
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
return (gulong)a[0] ^ (gulong)a[1];
|
|
|
|
}
|
|
|
|
|
1998-08-17 16:47:49 +02:00
|
|
|
static GHashFunc
|
1998-06-12 11:38:32 +02:00
|
|
|
tuple_hash (gint fields)
|
|
|
|
{
|
|
|
|
switch (fields)
|
|
|
|
{
|
|
|
|
case 2:
|
|
|
|
return tuple_hash_2;
|
|
|
|
default:
|
|
|
|
g_error ("no tuple hash for %d", fields);
|
|
|
|
}
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1998-08-17 16:47:49 +02:00
|
|
|
static GCompareFunc
|
1998-06-12 11:38:32 +02:00
|
|
|
tuple_equal (gint fields)
|
|
|
|
{
|
|
|
|
switch (fields)
|
|
|
|
{
|
|
|
|
case 2:
|
|
|
|
return tuple_equal_2;
|
|
|
|
default:
|
|
|
|
g_error ("no tuple equal for %d", fields);
|
|
|
|
}
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
GRelation*
|
|
|
|
g_relation_new (gint fields)
|
|
|
|
{
|
|
|
|
GRealRelation* rel = g_new0 (GRealRelation, 1);
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
rel->fields = fields;
|
|
|
|
rel->tuple_chunk = g_mem_chunk_new ("Relation Chunk",
|
|
|
|
fields * sizeof (gpointer),
|
|
|
|
fields * sizeof (gpointer) * 128,
|
|
|
|
G_ALLOC_AND_FREE);
|
|
|
|
rel->all_tuples = g_hash_table_new (tuple_hash (fields), tuple_equal (fields));
|
|
|
|
rel->hashed_tuple_tables = g_new0 (GHashTable*, fields);
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
return (GRelation*) rel;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
g_relation_free_array (gpointer key, gpointer value, gpointer user_data)
|
|
|
|
{
|
|
|
|
g_hash_table_destroy ((GHashTable*) value);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
g_relation_destroy (GRelation *relation)
|
|
|
|
{
|
|
|
|
GRealRelation *rel = (GRealRelation *) relation;
|
|
|
|
gint i;
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
if (rel)
|
|
|
|
{
|
|
|
|
g_hash_table_destroy (rel->all_tuples);
|
|
|
|
g_mem_chunk_destroy (rel->tuple_chunk);
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
for (i = 0; i < rel->fields; i += 1)
|
|
|
|
{
|
|
|
|
if (rel->hashed_tuple_tables[i])
|
|
|
|
{
|
|
|
|
g_hash_table_foreach (rel->hashed_tuple_tables[i], g_relation_free_array, NULL);
|
|
|
|
g_hash_table_destroy (rel->hashed_tuple_tables[i]);
|
|
|
|
}
|
|
|
|
}
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
g_free (rel->hashed_tuple_tables);
|
|
|
|
g_free (rel);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
g_relation_index (GRelation *relation,
|
|
|
|
gint field,
|
|
|
|
GHashFunc hash_func,
|
|
|
|
GCompareFunc key_compare_func)
|
|
|
|
{
|
|
|
|
GRealRelation *rel = (GRealRelation *) relation;
|
1999-03-14 21:03:51 +01:00
|
|
|
|
|
|
|
g_return_if_fail (relation != NULL);
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1999-03-14 21:03:51 +01:00
|
|
|
g_return_if_fail (rel->count == 0 && rel->hashed_tuple_tables[field] == NULL);
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
rel->hashed_tuple_tables[field] = g_hash_table_new (hash_func, key_compare_func);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
g_relation_insert (GRelation *relation,
|
|
|
|
...)
|
|
|
|
{
|
|
|
|
GRealRelation *rel = (GRealRelation *) relation;
|
|
|
|
gpointer* tuple = g_chunk_new (gpointer, rel->tuple_chunk);
|
|
|
|
va_list args;
|
|
|
|
gint i;
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
va_start(args, relation);
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
for (i = 0; i < rel->fields; i += 1)
|
|
|
|
tuple[i] = va_arg(args, gpointer);
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
va_end(args);
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
g_hash_table_insert (rel->all_tuples, tuple, tuple);
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
rel->count += 1;
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
for (i = 0; i < rel->fields; i += 1)
|
|
|
|
{
|
|
|
|
GHashTable *table;
|
|
|
|
gpointer key;
|
|
|
|
GHashTable *per_key_table;
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
table = rel->hashed_tuple_tables[i];
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
if (table == NULL)
|
|
|
|
continue;
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
key = tuple[i];
|
|
|
|
per_key_table = g_hash_table_lookup (table, key);
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
if (per_key_table == NULL)
|
|
|
|
{
|
|
|
|
per_key_table = g_hash_table_new (tuple_hash (rel->fields), tuple_equal (rel->fields));
|
|
|
|
g_hash_table_insert (table, key, per_key_table);
|
|
|
|
}
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
g_hash_table_insert (per_key_table, tuple, tuple);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-03-14 21:03:51 +01:00
|
|
|
g_relation_delete_tuple (gpointer tuple_key,
|
|
|
|
gpointer tuple_value,
|
|
|
|
gpointer user_data)
|
1998-06-12 11:38:32 +02:00
|
|
|
{
|
|
|
|
gpointer *tuple = (gpointer*) tuple_value;
|
|
|
|
GRealRelation *rel = (GRealRelation *) user_data;
|
|
|
|
gint j;
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
g_assert (tuple_key == tuple_value);
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
for (j = 0; j < rel->fields; j += 1)
|
|
|
|
{
|
|
|
|
GHashTable *one_table = rel->hashed_tuple_tables[j];
|
|
|
|
gpointer one_key;
|
|
|
|
GHashTable *per_key_table;
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
if (one_table == NULL)
|
|
|
|
continue;
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
if (j == rel->current_field)
|
|
|
|
/* can't delete from the table we're foreaching in */
|
|
|
|
continue;
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
one_key = tuple[j];
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
per_key_table = g_hash_table_lookup (one_table, one_key);
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
g_hash_table_remove (per_key_table, tuple);
|
|
|
|
}
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
g_hash_table_remove (rel->all_tuples, tuple);
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
rel->count -= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
1999-03-14 21:03:51 +01:00
|
|
|
g_relation_delete (GRelation *relation,
|
1998-06-12 11:38:32 +02:00
|
|
|
gconstpointer key,
|
1999-03-14 21:03:51 +01:00
|
|
|
gint field)
|
1998-06-12 11:38:32 +02:00
|
|
|
{
|
|
|
|
GRealRelation *rel = (GRealRelation *) relation;
|
|
|
|
GHashTable *table = rel->hashed_tuple_tables[field];
|
|
|
|
GHashTable *key_table;
|
|
|
|
gint count = rel->count;
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1999-03-14 21:03:51 +01:00
|
|
|
g_return_val_if_fail (relation != NULL, 0);
|
|
|
|
g_return_val_if_fail (table != NULL, 0);
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
key_table = g_hash_table_lookup (table, key);
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
if (!key_table)
|
|
|
|
return 0;
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
rel->current_field = field;
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
g_hash_table_foreach (key_table, g_relation_delete_tuple, rel);
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
g_hash_table_remove (table, key);
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
g_hash_table_destroy (key_table);
|
1998-08-18 05:50:35 +02:00
|
|
|
|
|
|
|
/* @@@ FIXME: Remove empty hash tables. */
|
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
return count - rel->count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1999-03-14 21:03:51 +01:00
|
|
|
g_relation_select_tuple (gpointer tuple_key,
|
|
|
|
gpointer tuple_value,
|
|
|
|
gpointer user_data)
|
1998-06-12 11:38:32 +02:00
|
|
|
{
|
|
|
|
gpointer *tuple = (gpointer*) tuple_value;
|
|
|
|
GRealTuples *tuples = (GRealTuples*) user_data;
|
|
|
|
gint stride = sizeof (gpointer) * tuples->width;
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
g_assert (tuple_key == tuple_value);
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
memcpy (tuples->data + (tuples->len * tuples->width),
|
|
|
|
tuple,
|
|
|
|
stride);
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
tuples->len += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
GTuples*
|
1999-03-14 21:03:51 +01:00
|
|
|
g_relation_select (GRelation *relation,
|
1998-06-12 11:38:32 +02:00
|
|
|
gconstpointer key,
|
1999-03-14 21:03:51 +01:00
|
|
|
gint field)
|
1998-06-12 11:38:32 +02:00
|
|
|
{
|
|
|
|
GRealRelation *rel = (GRealRelation *) relation;
|
|
|
|
GHashTable *table = rel->hashed_tuple_tables[field];
|
|
|
|
GHashTable *key_table;
|
|
|
|
GRealTuples *tuples = g_new0 (GRealTuples, 1);
|
|
|
|
gint count;
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1999-03-14 21:03:51 +01:00
|
|
|
g_return_val_if_fail (relation != NULL, NULL);
|
|
|
|
g_return_val_if_fail (table != NULL, NULL);
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
key_table = g_hash_table_lookup (table, key);
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
if (!key_table)
|
|
|
|
return (GTuples*)tuples;
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
count = g_relation_count (relation, key, field);
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
tuples->data = g_malloc (sizeof (gpointer) * rel->fields * count);
|
|
|
|
tuples->width = rel->fields;
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
g_hash_table_foreach (key_table, g_relation_select_tuple, tuples);
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
g_assert (count == tuples->len);
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
return (GTuples*)tuples;
|
|
|
|
}
|
|
|
|
|
|
|
|
gint
|
1999-03-14 21:03:51 +01:00
|
|
|
g_relation_count (GRelation *relation,
|
1998-06-12 11:38:32 +02:00
|
|
|
gconstpointer key,
|
1999-03-14 21:03:51 +01:00
|
|
|
gint field)
|
1998-06-12 11:38:32 +02:00
|
|
|
{
|
|
|
|
GRealRelation *rel = (GRealRelation *) relation;
|
|
|
|
GHashTable *table = rel->hashed_tuple_tables[field];
|
|
|
|
GHashTable *key_table;
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1999-03-14 21:03:51 +01:00
|
|
|
g_return_val_if_fail (relation != NULL, 0);
|
|
|
|
g_return_val_if_fail (table != NULL, 0);
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
key_table = g_hash_table_lookup (table, key);
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
if (!key_table)
|
|
|
|
return 0;
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
return g_hash_table_size (key_table);
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
g_relation_exists (GRelation *relation, ...)
|
|
|
|
{
|
|
|
|
GRealRelation *rel = (GRealRelation *) relation;
|
|
|
|
gpointer* tuple = g_chunk_new (gpointer, rel->tuple_chunk);
|
|
|
|
va_list args;
|
|
|
|
gint i;
|
|
|
|
gboolean result;
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
va_start(args, relation);
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
for (i = 0; i < rel->fields; i += 1)
|
|
|
|
tuple[i] = va_arg(args, gpointer);
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
va_end(args);
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
result = g_hash_table_lookup (rel->all_tuples, tuple) != NULL;
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
g_mem_chunk_free (rel->tuple_chunk, tuple);
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
g_tuples_destroy (GTuples *tuples0)
|
|
|
|
{
|
|
|
|
GRealTuples *tuples = (GRealTuples*) tuples0;
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
if (tuples)
|
|
|
|
{
|
|
|
|
g_free (tuples->data);
|
|
|
|
g_free (tuples);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gpointer
|
|
|
|
g_tuples_index (GTuples *tuples0,
|
|
|
|
gint index,
|
|
|
|
gint field)
|
|
|
|
{
|
|
|
|
GRealTuples *tuples = (GRealTuples*) tuples0;
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1999-03-14 21:03:51 +01:00
|
|
|
g_return_val_if_fail (tuples0 != NULL, NULL);
|
|
|
|
g_return_val_if_fail (field < tuples->width, NULL);
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
return tuples->data[index * tuples->width + field];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Print
|
|
|
|
*/
|
|
|
|
|
1998-08-17 16:47:49 +02:00
|
|
|
static void
|
|
|
|
g_relation_print_one (gpointer tuple_key,
|
|
|
|
gpointer tuple_value,
|
|
|
|
gpointer user_data)
|
1998-06-12 11:38:32 +02:00
|
|
|
{
|
|
|
|
gint i;
|
1998-08-18 05:50:35 +02:00
|
|
|
GString *gstring;
|
1998-06-12 11:38:32 +02:00
|
|
|
GRealRelation* rel = (GRealRelation*) user_data;
|
|
|
|
gpointer* tuples = (gpointer*) tuple_value;
|
|
|
|
|
1998-08-18 05:50:35 +02:00
|
|
|
gstring = g_string_new ("[");
|
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
for (i = 0; i < rel->fields; i += 1)
|
|
|
|
{
|
1998-08-18 05:50:35 +02:00
|
|
|
g_string_sprintfa (gstring, "%p", tuples[i]);
|
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
if (i < (rel->fields - 1))
|
1998-08-18 05:50:35 +02:00
|
|
|
g_string_append (gstring, ",");
|
1998-06-12 11:38:32 +02:00
|
|
|
}
|
1998-08-18 05:50:35 +02:00
|
|
|
|
|
|
|
g_string_append (gstring, "]");
|
|
|
|
g_log (g_log_domain_glib, G_LOG_LEVEL_INFO, gstring->str);
|
|
|
|
g_string_free (gstring, TRUE);
|
1998-06-12 11:38:32 +02:00
|
|
|
}
|
|
|
|
|
1998-08-17 16:47:49 +02:00
|
|
|
static void
|
|
|
|
g_relation_print_index (gpointer tuple_key,
|
|
|
|
gpointer tuple_value,
|
|
|
|
gpointer user_data)
|
1998-06-12 11:38:32 +02:00
|
|
|
{
|
|
|
|
GRealRelation* rel = (GRealRelation*) user_data;
|
|
|
|
GHashTable* table = (GHashTable*) tuple_value;
|
1998-08-18 05:50:35 +02:00
|
|
|
|
|
|
|
g_log (g_log_domain_glib, G_LOG_LEVEL_INFO, "*** key %p", tuple_key);
|
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
g_hash_table_foreach (table,
|
|
|
|
g_relation_print_one,
|
|
|
|
rel);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
g_relation_print (GRelation *relation)
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
GRealRelation* rel = (GRealRelation*) relation;
|
1998-08-18 05:50:35 +02:00
|
|
|
|
|
|
|
g_log (g_log_domain_glib, G_LOG_LEVEL_INFO, "*** all tuples (%d)", rel->count);
|
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
g_hash_table_foreach (rel->all_tuples,
|
|
|
|
g_relation_print_one,
|
|
|
|
rel);
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
for (i = 0; i < rel->fields; i += 1)
|
|
|
|
{
|
|
|
|
if (rel->hashed_tuple_tables[i] == NULL)
|
|
|
|
continue;
|
1998-08-18 05:50:35 +02:00
|
|
|
|
|
|
|
g_log (g_log_domain_glib, G_LOG_LEVEL_INFO, "*** index %d", i);
|
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
g_hash_table_foreach (rel->hashed_tuple_tables[i],
|
|
|
|
g_relation_print_index,
|
|
|
|
rel);
|
|
|
|
}
|
1998-08-18 05:50:35 +02:00
|
|
|
|
1998-06-12 11:38:32 +02:00
|
|
|
}
|