Ejemplo n.º 1
0
/*
 * Hash the specified filename into a dirhash slot.
 */
int
ufsdirhash_hash(struct dirhash *dh, char *name, int namelen)
{
	u_int32_t hash;

	/*
	 * We hash the name and then some other bit of data that is
	 * invariant over the dirhash's lifetime. Otherwise names
	 * differing only in the last byte are placed close to one
	 * another in the table, which is bad for linear probing.
	 */
	hash = hash32_buf(name, namelen, HASHINIT);
	hash = hash32_buf(&dh, sizeof(dh), hash);
	return (hash % dh->dh_hlen);
}
Ejemplo n.º 2
0
static __inline uint32_t
dircache_hashname(struct pefs_dircache *pd, char const *buf, size_t len)
{
	uint32_t h;

	h = pefs_hash_mixptr(pd);
	h ^= hash32_buf(buf, len, HASHINIT * len);
	return (h);
}
Ejemplo n.º 3
0
static __inline struct perfuse_node_hashlist *
perfuse_nidhash(struct perfuse_state *ps, uint64_t nodeid)
{       
        uint32_t hash;
        
        hash = hash32_buf(&nodeid, sizeof(nodeid), HASH32_BUF_INIT);

	return &ps->ps_nidhash[hash % ps->ps_nnidhash];
}    
Ejemplo n.º 4
0
static struct vmem_hashlist *
bt_hashhead(vmem_t *vm, vmem_addr_t addr)
{
	struct vmem_hashlist *list;
	unsigned int hash;

	hash = hash32_buf(&addr, sizeof(addr), HASH32_BUF_INIT);
	list = &vm->vm_hashlist[hash % vm->vm_hashsize];

	return list;
}
Ejemplo n.º 5
0
void drm_ht_verbose_list(struct drm_open_hash *ht, unsigned long key)
{
	struct drm_hash_item *entry;
	struct drm_hash_item_list *h_list;
	unsigned int hashed_key;
	int count = 0;

	hashed_key = hash32_buf(&key, sizeof(key), ht->order);
	DRM_DEBUG("Key is 0x%08lx, Hashed key is 0x%08x\n", key, hashed_key);
	h_list = &ht->table[hashed_key & ht->mask];
	LIST_FOREACH(entry, h_list, head)
		DRM_DEBUG("count %d, key: 0x%08lx\n", count++, entry->key);
}
Ejemplo n.º 6
0
int
up_generate(struct rde_peer *peer, struct rde_aspath *asp,
    struct bgpd_addr *addr, u_int8_t prefixlen)
{
	struct update_attr		*ua = NULL;
	struct update_prefix		*up;

	if (asp) {
		ua = calloc(1, sizeof(struct update_attr));
		if (ua == NULL)
			fatal("up_generate");

		if (up_generate_attr(peer, ua, asp, addr->aid) == -1) {
			log_warnx("generation of bgp path attributes failed");
			free(ua);
			return (-1);
		}
		/*
		 * use aspath_hash as attr_hash, this may be unoptimal
		 * but currently I don't care.
		 */
		ua->attr_hash = hash32_buf(ua->attr, ua->attr_len, HASHINIT);
		if (ua->mpattr)
			ua->attr_hash = hash32_buf(ua->mpattr, ua->mpattr_len,
			    ua->attr_hash);
	}

	up = calloc(1, sizeof(struct update_prefix));
	if (up == NULL)
		fatal("up_generate");
	up->prefix = *addr;
	up->prefixlen = prefixlen;

	if (up_add(peer, up, ua) == -1)
		return (-1);

	return (0);
}
Ejemplo n.º 7
0
/*
 * Hash sum building routine.  Use string hash if the buildpath routine
 * is the standard one, otherwise use binary hashes.  A bit whimsical
 * way to choose the routine, but the binary works for strings also,
 * so don't sweat it.
 */
void
puffs_path_buildhash(struct puffs_usermount *pu, struct puffs_pathobj *po)
{

	if ((pu->pu_flags & PUFFS_FLAG_HASHPATH) == 0)
		return;

	if (pu->pu_pathbuild == puffs_stdpath_buildpath)
		po->po_hash = hash32_strn(po->po_path, po->po_len,
		    HASH32_STR_INIT);
	else
		po->po_hash = hash32_buf(po->po_path, po->po_len,
		    HASH32_BUF_INIT);
}
Ejemplo n.º 8
0
static struct drm_hash_item *
drm_ht_find_key(struct drm_open_hash *ht, unsigned long key)
{
	struct drm_hash_item *entry;
	struct drm_hash_item_list *h_list;
	unsigned int hashed_key;

	hashed_key = hash32_buf(&key, sizeof(key), ht->order);
	h_list = &ht->table[hashed_key & ht->mask];
	LIST_FOREACH(entry, h_list, head) {
		if (entry->key == key)
			return entry;
		if (entry->key > key)
			break;
	}
	return NULL;
}
Ejemplo n.º 9
0
/*
 * Just insert an item and return any "bits" bit key that hasn't been
 * used before.
 */
int drm_ht_just_insert_please(struct drm_open_hash *ht, struct drm_hash_item *item,
			      unsigned long seed, int bits, int shift,
			      unsigned long add)
{
	int ret;
	unsigned long mask = (1 << bits) - 1;
	unsigned long first, unshifted_key = 0;

	unshifted_key = hash32_buf(&seed, sizeof(seed), unshifted_key);
	first = unshifted_key;
	do {
		item->key = (unshifted_key << shift) + add;
		ret = drm_ht_insert_item(ht, item);
		if (ret)
			unshifted_key = (unshifted_key + 1) & mask;
	} while(ret && (unshifted_key != first));

	if (ret) {
		DRM_ERROR("Available key bit space exhausted\n");
		return -EINVAL;
	}
	return 0;
}
Ejemplo n.º 10
0
int drm_ht_insert_item(struct drm_open_hash *ht, struct drm_hash_item *item)
{
	struct drm_hash_item *entry, *parent;
	struct drm_hash_item_list *h_list;
	unsigned int hashed_key;
	unsigned long key = item->key;

	hashed_key = hash32_buf(&key, sizeof(key), ht->order);
	h_list = &ht->table[hashed_key & ht->mask];
	parent = NULL;
	LIST_FOREACH(entry, h_list, head) {
		if (entry->key == key)
			return -EINVAL;
		if (entry->key > key)
			break;
		parent = entry;
	}
	if (parent) {
		LIST_INSERT_AFTER(parent, item, head);
	} else {
		LIST_INSERT_HEAD(h_list, item, head);
	}
	return 0;
}
Ejemplo n.º 11
0
/*
 * Places the key-value pair to the hashtable tbl.
 * Returns:
 *   HASH_OK:		if the key was not present in the hash table yet
 *			but the kay-value pair has been successfully added.
 *   HASH_UPDATED:	if the value for the key has been updated with the
 *			new value.
 *   HASH_FULL:		if the hash table is full and the entry could not
 *			be added.
 *   HASH_FAIL:		if an error has occurred and errno has been set to
 *			indicate the error.
 */
int
hashtable_put(hashtable *tbl, const void *key, const void *value)
{
  uint32_t hash = 0;

  if (tbl->table_size == tbl->usage)
    {
      DPRINT(("hashtable_put: hashtable is full\n"));
      return (HASH_FULL);
    }

  hash = hash32_buf(key, tbl->key_size, hash) % tbl->table_size;
  DPRINT(("hashtable_put: calculated hash %" PRIu32 "\n", hash));

  /*
   * On hash collision entries are inserted at the next free space,
   * so we have to increase the index until we either find an entry
   * with the same key (and update it) or we find a free space.
   */
  for(;;)
    {
      if (tbl->entries[hash] == NULL)
	break;
      else if (memcmp(tbl->entries[hash]->key, key, tbl->key_size) == 0)
	{
	  memcpy(tbl->entries[hash]->value, value, tbl->value_size);
	  DPRINT(("hashtable_put: effective location is %" PRIu32
		  ", entry updated\n", hash));
	  return (HASH_UPDATED);
	}
      if (++hash == tbl->table_size)
	hash = 0;
    }

  DPRINT(("hashtable_put: effective location is %" PRIu32 "\n", hash));

  tbl->entries[hash] = malloc(sizeof(hashtable_entry));
  if (tbl->entries[hash] == NULL)
    {
      errno = ENOMEM;
      goto mem1;
    }

  tbl->entries[hash]->key = malloc(tbl->key_size);
  if (tbl->entries[hash]->key == NULL)
    {
      errno = ENOMEM;
      goto mem2;
    }

  tbl->entries[hash]->value = malloc(tbl->value_size);
  if (tbl->entries[hash]->value == NULL)
    {
      errno = ENOMEM;
      goto mem3;
    }

  memcpy(tbl->entries[hash]->key, key, tbl->key_size);
  memcpy(tbl->entries[hash]->value, value, tbl->value_size);
  tbl->usage++;

  DPRINT(("hashtable_put: entry successfully inserted\n"));

  return (HASH_OK);

mem3:
  free(tbl->entries[hash]->key);
mem2:
  free(tbl->entries[hash]);
mem1:
  DPRINT(("hashtable_put: insertion failed\n"));
  return (HASH_FAIL);
}
Ejemplo n.º 12
0
static uint32_t
hash_table_value(struct namedobj_instance *ni, void *key, uint32_t kopt)
{

	return (hash32_buf(key, 56, 0));
}