Пример #1
0
unsigned int
tuple_hash_tbl(const void *key, void *data)
{
    Tuple *t = (Tuple *) key;
    Schema *s = (Schema *) data;

    return tuple_hash(t, s);
}
Пример #2
0
/**
 * g_relation_new:
 * @fields: the number of fields.
 *
 * Creates a new #GRelation with the given number of fields. Note that
 * currently the number of fields must be 2.
 *
 * Returns: a new #GRelation.
 *
 * Deprecated: 2.26: Rarely used API
 **/
GRelation*
g_relation_new (gint fields)
{
  GRelation* rel = g_new0 (GRelation, 1);
  
  rel->fields = fields;
  rel->all_tuples = g_hash_table_new (tuple_hash (fields), tuple_equal (fields));
  rel->hashed_tuple_tables = g_new0 (GHashTable*, fields);
  
  return rel;
}
Пример #3
0
Bool hash_has_entry(const Hash* hash, const Tuple* tuple)
{
   unsigned int hcode = tuple_hash(tuple) % hash->size;
   HElem*       he;
   
   assert(hash_is_valid(hash));
   assert(tuple_is_valid(tuple));
   
   for(he = hash->bucket[hcode]; he != NULL; he = he->next)
      if (!entry_cmp(he->value.entry, tuple))
         break;

   return he != NULL;
}
Пример #4
0
GRelation*
g_relation_new (gint fields)
{
  GRelation* rel = g_new0 (GRelation, 1);
  
  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);
  
  return rel;
}
Пример #5
0
void hash_add_tuple(Hash* hash, const Tuple* tuple)
{
   HElem*       he = blk_alloc(sizeof(*he));
   unsigned int hcode;

   assert(hash_is_valid(hash));
   assert(tuple_is_valid(tuple));
   assert(hash->type == HASH_TUPLE);
   assert(he != NULL);
   
   hcode               = tuple_hash(tuple) % hash->size;
   he->value.tuple     = tuple;
   he->next            = hash->bucket[hcode];
   hash->bucket[hcode] = he;
   hash->elems++;
}
Пример #6
0
void hash_add_entry(Hash* hash, const Entry* entry)
{
   HElem*       he = blk_alloc(sizeof(*he));
   const Tuple* tuple;
   unsigned int hcode;

   assert(hash_is_valid(hash));
   assert(entry_is_valid(entry));
   assert(hash->type == HASH_ENTRY);
   assert(he != NULL);
   
   tuple               = entry_get_tuple(entry);
   hcode               = tuple_hash(tuple) % hash->size;
   he->value.entry     = entry;
   he->next            = hash->bucket[hcode];
   hash->bucket[hcode] = he;
   hash->elems++;
}
Пример #7
0
void
g_relation_insert (GRelation   *relation,
		   ...)
{
  GRealRelation *rel = (GRealRelation *) relation;
  gpointer* tuple = g_chunk_new (gpointer, rel->tuple_chunk);
  va_list args;
  gint i;

  va_start(args, relation);

  for (i = 0; i < rel->fields; i += 1)
    tuple[i] = va_arg(args, gpointer);

  va_end(args);

  g_hash_table_insert (rel->all_tuples, tuple, tuple);

  rel->count += 1;

  for (i = 0; i < rel->fields; i += 1)
    {
      GHashTable *table;
      gpointer    key;
      GHashTable *per_key_table;

      table = rel->hashed_tuple_tables[i];

      if (table == NULL)
	continue;

      key = tuple[i];
      per_key_table = g_hash_table_lookup (table, key);

      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);
	}

      g_hash_table_insert (per_key_table, tuple, tuple);
    }
}