Example #1
0
unsigned int
dns_name_hashbylabel(dns_name_t *name, isc_boolean_t case_sensitive) {
	unsigned char *offsets;
	dns_offsets_t odata;
	dns_name_t tname;
	unsigned int h = 0;
	unsigned int i;

	/*
	 * Provide a hash value for 'name'.
	 */
	REQUIRE(VALID_NAME(name));

	if (name->labels == 0)
		return (0);
	else if (name->labels == 1)
		return (name_hash(name, case_sensitive));

	SETUP_OFFSETS(name, offsets, odata);
	DNS_NAME_INIT(&tname, NULL);
	tname.labels = 1;
	h = 0;
	for (i = 0; i < name->labels; i++) {
		tname.ndata = name->ndata + offsets[i];
		if (i == name->labels - 1)
			tname.length = name->length - offsets[i];
		else
			tname.length = offsets[i + 1] - offsets[i];
		h += name_hash(&tname, case_sensitive);
	}

	return (h);
}
Example #2
0
int newFontBaseEntry(const char *file, void *engine)
{
    if(findFontBaseEntry(file) > -1) {
        printf("Fontbase: font '%s' already exist\n", file);
        return -1;
    }

    FontBase *n = 0;
    int i;
    for(i=0; fbase.empty_entries && i<fbase.cnt; ++i)
    {
        if(!fbase.base[i]) {
            n = fbase.base[i];
            fbase.empty_entries --;
            break;
        }
    }

    if(!n) {
        n = calloc(1, sizeof *n);
        i = fbase_pushback(n);
    }

    n->engine = engine;
    n->file = strdup(file);
    n->hash = name_hash(file);

    return i;
}
Example #3
0
/* called with note_lock held */
uint do_hash(struct dentry * dentry, struct vfsmount * vfsmnt, struct dentry * root, struct vfsmount * rootmnt)
{
	struct qstr * dname;
	uint value = -1;
	uint firsthash;
	uint incr;
	uint parent = 0;
	struct op_hash_index *entry;

	if (!wind_dentries(dentry, vfsmnt, root, rootmnt))
		goto out;

	/* unwind and hash */

	while ((dname = pop_dname())) {
		/* if N is prime, value in [0-N[ and incr = max(1, value) then
		 * iteration: value = (value + incr) % N covers the range [0-N[
		 * in N iterations */
		incr = firsthash = value = name_hash(dname->name, dname->len, parent);
		if (incr == 0)
			incr = 1;

	retry:
		entry = &hash_map[value];
		/* existing entry ? */
		if (streq(get_from_pool(entry->name), dname->name)
			&& entry->parent == parent)
			goto next;

		/* new entry ? */
		if (entry->parent == -1) {
			if (add_hash_entry(entry, parent, dname->name, dname->len))
				goto fullpool;
			goto next;
		}

		/* nope, find another place in the table */
		value = (value + incr) % OP_HASH_MAP_NR;

		if (value == firsthash)
			goto fulltable;

		goto retry;
	next:
		parent = value;
	}

out:
	op_dname_top = 0;
	return value;
fullpool:
	printk(KERN_ERR "oprofile: string pool exhausted.\n");
	value = -1;
	goto out;
fulltable:
	printk(KERN_ERR "oprofile: component hash table full :(\n");
	value = -1;
	goto out;
}
constexpr std::size_t name_hash(const char* str, std::size_t len, std::size_t n,
                                std::size_t state) {
    static_assert(sizeok_k, "Unknown sizeof std::size_t (must be 4 or 8).");

    return n < len ? name_hash(str, len, n + 1,
                               (state xor static_cast<std::size_t>(str[n])) * name_fnv_prime_k)
                   : state;
}
Example #5
0
static struct queue_t* queues_get(const char* name)
{
    int hash = name_hash(name);
    struct queue_t* q = NULL;
    pthread_mutex_lock(&_queues_lock);
    q = bucket_search(hash, name);
    if (q)
        queue_acquire(q);
    pthread_mutex_unlock(&_queues_lock);
    return q;
}
Example #6
0
unsigned int
dns_name_hash(dns_name_t *name, isc_boolean_t case_sensitive) {
	/*
	 * Provide a hash value for 'name'.
	 */
	REQUIRE(VALID_NAME(name));

	if (name->labels == 0)
		return (0);

	return (name_hash(name, case_sensitive));
}
Example #7
0
int findFontBaseEntry(const char *file)
{
    unsigned int hash = name_hash(file);
    int i;

    for(i=0; i<fbase.cnt; ++i) {
        if(fbase.base[i] && fbase.base[i]->hash == hash && !strcmp(fbase.base[i]->file, file)) {
            return i;
        }
    }

    return -1;
}
Example #8
0
        mpi_aggregator(MPI_Comm comm = MPI_COMM_WORLD)
            : world(comm), dtype(amgcl::mpi::datatype<value_type>())
        {
            if (SingleReaderPerNode) {
                typedef std::integral_constant<bool, sizeof(size_t) == sizeof(int)>::type _32bit;

                char node_name[MPI_MAX_PROCESSOR_NAME];
                int node_name_len, node_master;

                MPI_Get_processor_name(node_name, &node_name_len);
                MPI_Comm_split(world, name_hash(node_name, _32bit()), world.rank, &node_comm);
                MPI_Allreduce(&world.rank, &node_master, 1, MPI_INT, MPI_MIN, node_comm);

                reader = (world.rank == node_master);
                MPI_Comm_split(world, reader, world.rank, &reader_comm);
            }
        }
Example #9
0
static int queues_add(struct queue_t* q)
{
    int hash = name_hash(q->name);
    pthread_mutex_lock(&_queues_lock);
    if (bucket_search(hash, q->name))
    {
        pthread_mutex_unlock(&_queues_lock);
        return 0;
    }
    q->next = NULL;
    q->prev = _queues[hash].tail;
    if (_queues[hash].tail)
        _queues[hash].tail->next = q;
    _queues[hash].tail = q;
    if (!_queues[hash].head)
        _queues[hash].head = q;
    q->bucket = hash;
    pthread_mutex_unlock(&_queues_lock);
    TRACE("queues_add: %s bucket=%d\n", q->name, hash);
    return 1;
}
constexpr std::size_t name_hash(const char (&str)[N]) {
    static_assert(sizeok_k, "Unknown sizeof std::size_t (must be 4 or 8).");

    return name_hash(str, N - 1);
}
constexpr std::size_t name_hash(const char* str, std::size_t len) {
    static_assert(sizeok_k, "Unknown sizeof std::size_t (must be 4 or 8).");

    return name_hash(str, len, 0, name_fnv_basis_k);
}