Ejemplo n.º 1
0
static int
message_list_hash_insert_entry (hash_table *htable, message_ty *mp)
{
  char *alloced_key;
  const char *key;
  size_t keylen;
  int found;

  if (mp->msgctxt != NULL)
    {
      /* Concatenate mp->msgctxt and mp->msgid, to form the hash table key.  */
      size_t msgctxt_len = strlen (mp->msgctxt);
      size_t msgid_len = strlen (mp->msgid);
      keylen = msgctxt_len + 1 + msgid_len + 1;
      alloced_key = (char *) xmalloca (keylen);
      memcpy (alloced_key, mp->msgctxt, msgctxt_len);
      alloced_key[msgctxt_len] = MSGCTXT_SEPARATOR;
      memcpy (alloced_key + msgctxt_len + 1, mp->msgid, msgid_len + 1);
      key = alloced_key;
    }
  else
    {
      alloced_key = NULL;
      key = mp->msgid;
      keylen = strlen (mp->msgid) + 1;
    }

  found = (hash_insert_entry (htable, key, keylen, mp) == NULL);

  if (mp->msgctxt != NULL)
    freea (alloced_key);

  return found;
}
Ejemplo n.º 2
0
/*
 * Move all entries in src into dst; empty src.
 * Entries in src must not exist in dst.
 */
void
erts_hash_merge(Hash* src, Hash* dst)
{
    int limit = src->size;
    HashBucket** bucket = src->bucket;
    int i;

    src->used = 0;
    for (i = 0; i < limit; i++) {
	HashBucket* b = bucket[i];
	HashBucket* next;

	bucket[i] = NULL;
	while (b) {
	    next = b->next;
	    hash_insert_entry(dst, b);
	    b = next;
	}
    }
}