-{
- hash_index(key);
- for (hlink *hp=table[index]; hp; hp=(hlink *)hp->next) {
-// Dmsg2(100, "hp=0x%x key=%s\n", (long)hp, hp->key);
- if (hash == hp->hash && strcmp(key, hp->key) == 0) {
- Dmsg1(100, "lookup return %x\n", ((char *)hp)-loffset);
- return ((char *)hp)-loffset;
- }
- }
- return NULL;
-}
-
+{
+ hash_index(key);
+ for (hlink *hp=table[index]; hp; hp=(hlink *)hp->next) {
+// Dmsg2(100, "hp=%p key=%s\n", hp, hp->key.key);
+ if (hash == hp->hash && strcmp(key, hp->key.key) == 0) {
+ Dmsg1(dbglvl, "lookup return %p\n", ((char *)hp)-loffset);
+ return ((char *)hp)-loffset;
+ }
+ }
+ return NULL;
+}
+
+bool htable::insert(uint64_t ikey, void *item)
+{
+ hlink *hp;
+ if (lookup(ikey)) {
+ return false; /* already exists */
+ }
+ ASSERT(index < buckets);
+ Dmsg2(dbglvl, "Insert: hash=%p index=%d\n", hash, index);
+ hp = (hlink *)(((char *)item)+loffset);
+ Dmsg4(dbglvl, "Insert hp=%p index=%d item=%p offset=%u\n", hp, index,
+ item, loffset);
+ hp->next = table[index];
+ hp->hash = hash;
+ hp->key.ikey = ikey;
+ hp->is_ikey = true;
+ table[index] = hp;
+ Dmsg3(dbglvl, "Insert hp->next=%p hp->hash=0x%x hp->ikey=%lld\n", hp->next,
+ hp->hash, hp->key.ikey);
+
+ if (++num_items >= max_items) {
+ Dmsg2(dbglvl, "num_items=%d max_items=%d\n", num_items, max_items);
+ grow_table();
+ }
+ Dmsg3(dbglvl, "Leave insert index=%d num_items=%d key=%lld\n",
+ index, num_items, ikey);
+ return true;
+}
+
+void *htable::lookup(uint64_t ikey)
+{
+ hash_index(ikey);
+ for (hlink *hp=table[index]; hp; hp=(hlink *)hp->next) {
+// Dmsg2(100, "hp=%p key=%lld\n", hp, hp->key.ikey);
+ if (hash == hp->hash && ikey == hp->key.ikey) {
+ Dmsg1(dbglvl, "lookup return %p\n", ((char *)hp)-loffset);
+ return ((char *)hp)-loffset;
+ }
+ }
+ return NULL;
+}
+