src/libs/hash_lib.c
void* hash_table_access_create(Hash_Table* table, int64 key, Flag* new_entry) {
  // {{{ access hash table using simple key compare
  uns               index    = HASH_INDEX(table, key);
  Hash_Table_Entry* bucket   = table->entries[index];
  Hash_Table_Entry* new_hash = NULL;
  Hash_Table_Entry* temp;
  Hash_Table_Entry* prev = NULL;

  *new_entry = FALSE;
  ASSERT(0, index < table->buckets);
  for(temp = bucket; temp != NULL; temp = temp->next) {
    if(temp->key == key)
      return temp->data;
    else
      prev = temp;
  }
  table->count++;
  *new_entry = TRUE;
  new_hash   = (Hash_Table_Entry*)smalloc(sizeof(Hash_Table_Entry));
  ASSERT(0, new_hash);
  new_hash->key  = key;
  new_hash->next = NULL;
  new_hash->data = (void*)smalloc(table->data_size);
  ASSERT(0, new_hash->data);

  if(prev)
    prev->next = new_hash;
  else
    table->entries[index] = new_hash;

  _DEBUGA(0, 0, "smalloc'd %ld bytes for %s (%d entries)\n",
          (unsigned long int)sizeof(Hash_Table_Entry) + table->data_size,
          table->name, table->count);

  return new_hash->data;
  // }}}
}
/**************************************************************************************/
/* hash_table_access_create: access the hash table.  Return the data
   pointer if it hits an existing entry.  Otherwise, allocate a new
   entry and return its data pointer. */
access the hash table.  Return the data
pointer if it hits an existing entry.  Otherwise, allocate a new
entry and return its data pointer.
access the hash table . Return the data pointer if it hits an existing entry . Otherwise allocate a new entry and return its data pointer .
void* hash_table_access_create(Hash_Table* table, int64 key, Flag* new_entry) {
  uns               index    = HASH_INDEX(table, key);
  Hash_Table_Entry* bucket   = table->entries[index];
  Hash_Table_Entry* new_hash = NULL;
  Hash_Table_Entry* temp;
  Hash_Table_Entry* prev = NULL;
  *new_entry = FALSE;
  ASSERT(0, index < table->buckets);
  for(temp = bucket; temp != NULL; temp = temp->next) {
    if(temp->key == key)
      return temp->data;
    else
      prev = temp;
  }
  table->count++;
  *new_entry = TRUE;
  new_hash   = (Hash_Table_Entry*)smalloc(sizeof(Hash_Table_Entry));
  ASSERT(0, new_hash);
  new_hash->key  = key;
  new_hash->next = NULL;
  new_hash->data = (void*)smalloc(table->data_size);
  ASSERT(0, new_hash->data);
  if(prev)
    prev->next = new_hash;
  else
    table->entries[index] = new_hash;
  _DEBUGA(0, 0, "smalloc'd %ld bytes for %s (%d entries)\n",
          (unsigned long int)sizeof(Hash_Table_Entry) + table->data_size,
          table->name, table->count);
  return new_hash->data;
}
void * hash_table_access_create ( Hash_Table * table , int64 key , Flag * new_entry ) { uns index = HASH_INDEX ( table , key ) ; Hash_Table_Entry * bucket = table -> entries [ index ] ; Hash_Table_Entry * new_hash = NULL ; Hash_Table_Entry * temp ; Hash_Table_Entry * prev = NULL ; * new_entry = FALSE ; ASSERT ( 0 , index < table -> buckets ) ; for ( temp = bucket ; temp != NULL ; temp = temp -> next ) { if ( temp -> key == key ) return temp -> data ; else prev = temp ; } table -> count ++ ; * new_entry = TRUE ; new_hash = ( Hash_Table_Entry * ) smalloc ( sizeof ( Hash_Table_Entry ) ) ; ASSERT ( 0 , new_hash ) ; new_hash -> key = key ; new_hash -> next = NULL ; new_hash -> data = ( void * ) smalloc ( table -> data_size ) ; ASSERT ( 0 , new_hash -> data ) ; if ( prev ) prev -> next = new_hash ; else table -> entries [ index ] = new_hash ; _DEBUGA ( 0 , 0 , " \n " , ( unsigned long int ) sizeof ( Hash_Table_Entry ) + table -> data_size , table -> name , table -> count ) ; return new_hash -> data ; }
hash_table_access_create: access the hash table.
hash_table_access_create : access the hash table .
// {{{ access hash table using simple key compare // }}}