struct cache_vginfo *vginfo_from_vgid(const char *vgid)
{
struct cache_vginfo *vginfo;
+ char id[ID_LEN + 1];
if (!_vgid_hash || !vgid)
return NULL;
- if (!(vginfo = hash_lookup_fixed(_vgid_hash, vgid, ID_LEN)))
+ /* vgid not necessarily NULL-terminated */
+ strncpy(&id[0], vgid, ID_LEN);
+ id[ID_LEN] = '\0';
+
+ if (!(vginfo = hash_lookup(_vgid_hash, id)))
return NULL;
return vginfo;
struct cache_info *info_from_pvid(const char *pvid)
{
struct cache_info *info;
+ char id[ID_LEN + 1];
if (!_pvid_hash || !pvid)
return NULL;
- if (!(info = hash_lookup_fixed(_pvid_hash, pvid, ID_LEN)))
+ strncpy(&id[0], pvid, ID_LEN);
+ id[ID_LEN] = '\0';
+
+ if (!(info = hash_lookup(_pvid_hash, id)))
return NULL;
return info;
return n;
}
-static unsigned _hash(const char *str, unsigned len)
+static unsigned _hash(const char *str)
{
unsigned long h = 0, g;
- while (*str && len--) {
+ while (*str) {
h <<= 4;
h += _nums[(int) *str++];
g = h & ((unsigned long) 0xf << 16u);
dbg_free(t);
}
-static inline struct hash_node **_find_fixed(struct hash_table *t,
- const char *key, unsigned len)
+static inline struct hash_node **_find(struct hash_table *t, const char *key)
{
- unsigned h = _hash(key, len) & (t->num_slots - 1);
+ unsigned h = _hash(key) & (t->num_slots - 1);
struct hash_node **c;
for (c = &t->slots[h]; *c; c = &((*c)->next))
- if (!strncmp(key, (*c)->key, len))
+ if (!strcmp(key, (*c)->key))
break;
return c;
}
-static inline struct hash_node **_find(struct hash_table *t, const char *key)
-{
- return _find_fixed(t, key, strlen(key));
-}
-
-void *hash_lookup_fixed(struct hash_table *t, const char *key, unsigned len)
-{
- struct hash_node **c = _find_fixed(t, key, len);
- return *c ? (*c)->data : 0;
-}
-
void *hash_lookup(struct hash_table *t, const char *key)
{
struct hash_node **c = _find(t, key);
struct hash_node *hash_get_next(struct hash_table *t, struct hash_node *n)
{
- unsigned h = _hash(n->key, strlen(n->key)) & (t->num_slots - 1);
+ unsigned h = _hash(n->key) & (t->num_slots - 1);
return n->next ? n->next : _next_slot(t, h + 1);
}