示例#1
0
static HashValue *entry_get(GoomHashEntry *entry, const char *key) {

	int cmp;
	if (entry==NULL)
		return NULL;
	cmp = strcmp(key,entry->key);
	if (cmp > 0)
		return entry_get(entry->upper, key);
	else if (cmp < 0)
		return entry_get(entry->lower, key);
	else
		return &(entry->value);
}
示例#2
0
文件: hashmap.c 项目: JDsolution/ipnc
int avahi_hashmap_replace(AvahiHashmap *m, void *key, void *value) {
    unsigned idx;
    Entry *e;

    assert(m);

    if ((e = entry_get(m, key))) {
        if (m->key_free_func)
            m->key_free_func(e->key);
        if (m->value_free_func)
            m->value_free_func(e->value);

        e->key = key;
        e->value = value;
            
        return 1;
    }

    if (!(e = avahi_new(Entry, 1)))
        return -1;

    e->hashmap = m;
    e->key = key;
    e->value = value;

    AVAHI_LLIST_PREPEND(Entry, entries, m->entries_list, e);

    idx = m->hash_func(key) % HASH_MAP_SIZE;
    AVAHI_LLIST_PREPEND(Entry, bucket, m->entries[idx], e);
        
    return 0;
}
示例#3
0
文件: hashmap.c 项目: JDsolution/ipnc
void avahi_hashmap_remove(AvahiHashmap *m, const void *key) {
    Entry *e;
    
    assert(m);

    if (!(e = entry_get(m, key)))
        return;

    entry_free(m, e, 0);
}
示例#4
0
文件: hashmap.c 项目: JDsolution/ipnc
void* avahi_hashmap_lookup(AvahiHashmap *m, const void *key) {
    Entry *e;
    
    assert(m);

    if (!(e = entry_get(m, key)))
        return NULL;

    return e->value;
}
示例#5
0
int integrate(entry_t **list, char *args)
{
	complex_t *z = NULL;
	entry_t *e = NULL;
	polynomial_t *q = NULL;
	size_t size = 0, i = 0;
	char **table = NULL, *c = NULL, count = 0;

	if (list == NULL || args == NULL)
		return EXIT_FAILURE;

	table = split(args, ' ', &size);
	if (table == NULL || size == 1)
	{
		if (table != NULL)
		{
			free(*table);
			free(table);
		}

		return EXIT_FAILURE;
	}

	e = entry_get(*list, table[1]);
	if (e == NULL || e->type != POLYNOMIAL)
	{
		for (i = 0; i < size; i++)
			free(table[i]);

		free(table);

		return EXIT_FAILURE;
	}

	if (size > 2)
	{
		c = args;
		while (count < 2)
		{
			if (*c == ' ')
				count++;

			c++;
		}

		z = complex_fromString(c);
		if (z == NULL)
		{
			for (i = 0; i < size; i++)
				free(table[i]);

			free(table);

			return EXIT_FAILURE;
		}

		q = polynomial_integrate((polynomial_t*) e->polynomial, z);
	}
	else
		q = polynomial_integrate((polynomial_t*) e->polynomial, NULL);

	if (q == NULL)
	{
		if (z != NULL)
			complex_free(z);

		for (i = 0; i < size; i++)
			free(table[i]);

		free(table);

		return EXIT_FAILURE;
	}

	polynomial_display(q);
	fprintf(stdout, "\n");

	entry_add(list, (void*) q, POLYNOMIAL);

	for (i = 0; i < size; i++)
		free(table[i]);

	free(table);

	return EXIT_SUCCESS;
}
示例#6
0
HashValue *goom_hash_get(GoomHash *_this, const char *key) {
  if (_this == NULL) return NULL;
	return entry_get(_this->root,key);
}