int hna_global_seq_print_text(struct seq_file *seq, void *offset) { struct net_device *net_dev = (struct net_device *)seq->private; struct bat_priv *bat_priv = netdev_priv(net_dev); struct hna_global_entry *hna_global_entry; HASHIT(hashit); HASHIT(hashit_count); unsigned long flags; size_t buf_size, pos; char *buff; if (!bat_priv->primary_if) { return seq_printf(seq, "BATMAN mesh %s disabled - " "please specify interfaces to enable it\n", net_dev->name); } seq_printf(seq, "Globally announced HNAs received via the mesh %s\n", net_dev->name); spin_lock_irqsave(&bat_priv->hna_ghash_lock, flags); buf_size = 1; /* Estimate length for: " * xx:xx:xx:xx:xx:xx via xx:xx:xx:xx:xx:xx\n"*/ while (hash_iterate(bat_priv->hna_global_hash, &hashit_count)) buf_size += 43; buff = kmalloc(buf_size, GFP_ATOMIC); if (!buff) { spin_unlock_irqrestore(&bat_priv->hna_ghash_lock, flags); return -ENOMEM; } buff[0] = '\0'; pos = 0; while (hash_iterate(bat_priv->hna_global_hash, &hashit)) { hna_global_entry = hashit.bucket->data; pos += snprintf(buff + pos, 44, " * %pM via %pM\n", hna_global_entry->addr, hna_global_entry->orig_node->orig); } spin_unlock_irqrestore(&bat_priv->hna_ghash_lock, flags); seq_printf(seq, "%s", buff); kfree(buff); return 0; }
int hna_global_fill_buffer_text(struct net_device *net_dev, char *buff, size_t count, loff_t off) { struct bat_priv *bat_priv = netdev_priv(net_dev); struct hna_global_entry *hna_global_entry; HASHIT(hashit); int bytes_written = 0; unsigned long flags; size_t hdr_len; if (!bat_priv->primary_if) { if (off == 0) return sprintf(buff, "BATMAN mesh %s disabled - " "please specify interfaces to enable it\n", net_dev->name); return 0; } hdr_len = sprintf(buff, "Globally announced HNAs received via the mesh %s " "(translation table):\n", net_dev->name); if (off < hdr_len) bytes_written = hdr_len; spin_lock_irqsave(&hna_global_hash_lock, flags); while (hash_iterate(hna_global_hash, &hashit)) { hdr_len += 43; if (count < bytes_written + 44) break; if (off >= hdr_len) continue; hna_global_entry = hashit.bucket->data; bytes_written += snprintf(buff + bytes_written, 44, " * " MAC_FMT " via " MAC_FMT "\n", hna_global_entry->addr[0], hna_global_entry->addr[1], hna_global_entry->addr[2], hna_global_entry->addr[3], hna_global_entry->addr[4], hna_global_entry->addr[5], hna_global_entry->orig_node->orig[0], hna_global_entry->orig_node->orig[1], hna_global_entry->orig_node->orig[2], hna_global_entry->orig_node->orig[3], hna_global_entry->orig_node->orig[4], hna_global_entry->orig_node->orig[5]); } spin_unlock_irqrestore(&hna_global_hash_lock, flags); return bytes_written; }
int hna_local_fill_buffer_text(unsigned char *buff, int buff_len) { struct hna_local_entry *hna_local_entry; struct hash_it_t *hashit = NULL; int bytes_written = 0; unsigned long flags; spin_lock_irqsave(&hna_local_hash_lock, flags); while (NULL != (hashit = hash_iterate(hna_local_hash, hashit))) { if (buff_len < bytes_written + ETH_STR_LEN + 4) break; hna_local_entry = hashit->bucket->data; bytes_written += snprintf(buff + bytes_written, ETH_STR_LEN + 4, " * %02x:%02x:%02x:%02x:%02x:%02x\n", hna_local_entry->addr[0], hna_local_entry->addr[1], hna_local_entry->addr[2], hna_local_entry->addr[3], hna_local_entry->addr[4], hna_local_entry->addr[5]); } spin_unlock_irqrestore(&hna_local_hash_lock, flags); return bytes_written; }
static void pim_vxlan_set_peerlink_rif(struct pim_instance *pim, struct interface *ifp) { struct interface *old_iif; if (pim->vxlan.peerlink_rif == ifp) return; old_iif = pim->vxlan.peerlink_rif; if (PIM_DEBUG_VXLAN) zlog_debug("%s: vxlan peerlink_rif changed from %s to %s", __PRETTY_FUNCTION__, old_iif ? old_iif->name : "-", ifp ? ifp->name : "-"); old_iif = pim_vxlan_orig_mr_iif_get(pim); pim->vxlan.peerlink_rif = ifp; ifp = pim_vxlan_orig_mr_iif_get(pim); if (old_iif == ifp) return; if (PIM_DEBUG_VXLAN) zlog_debug("%s: vxlan orig iif changed from %s to %s", __PRETTY_FUNCTION__, old_iif ? old_iif->name : "-", ifp ? ifp->name : "-"); /* add/del upstream entries for the existing vxlan SG when the * interface becomes available */ if (pim->vxlan.sg_hash) hash_iterate(pim->vxlan.sg_hash, pim_vxlan_orig_mr_iif_update, ifp); }
static void hna_local_purge(struct work_struct *work) { struct delayed_work *delayed_work = container_of(work, struct delayed_work, work); struct bat_priv *bat_priv = container_of(delayed_work, struct bat_priv, hna_work); struct hna_local_entry *hna_local_entry; HASHIT(hashit); unsigned long flags; unsigned long timeout; spin_lock_irqsave(&bat_priv->hna_lhash_lock, flags); while (hash_iterate(bat_priv->hna_local_hash, &hashit)) { hna_local_entry = hashit.bucket->data; timeout = hna_local_entry->last_seen + LOCAL_HNA_TIMEOUT * HZ; if ((!hna_local_entry->never_purge) && time_after(jiffies, timeout)) hna_local_del(bat_priv, hna_local_entry, "address timed out"); } spin_unlock_irqrestore(&bat_priv->hna_lhash_lock, flags); hna_local_start_timer(bat_priv); }
int _p11_conf_merge_defaults (hashmap *map, hashmap *defaults) { hashiter iter; void *key; void *value; hash_iterate (defaults, &iter); while (hash_next (&iter, &key, &value)) { /* Only override if not set */ if (hash_get (map, key)) continue; key = strdup (key); if (key == NULL) { errno = ENOMEM; return -1; } value = strdup (value); if (value == NULL) { free (key); errno = ENOMEM; return -1; } if (!hash_set (map, key, value)) { free (key); free (value); errno = ENOMEM; return -1; } key = NULL; value = NULL; } return 0; }
int hna_local_fill_buffer(struct bat_priv *bat_priv, unsigned char *buff, int buff_len) { struct hna_local_entry *hna_local_entry; HASHIT(hashit); int i = 0; unsigned long flags; spin_lock_irqsave(&bat_priv->hna_lhash_lock, flags); while (hash_iterate(bat_priv->hna_local_hash, &hashit)) { if (buff_len < (i + 1) * ETH_ALEN) break; hna_local_entry = hashit.bucket->data; memcpy(buff + (i * ETH_ALEN), hna_local_entry->addr, ETH_ALEN); i++; } /* if we did not get all new local hnas see you next time ;-) */ if (i == bat_priv->num_local_hna) atomic_set(&bat_priv->hna_local_changed, 0); spin_unlock_irqrestore(&bat_priv->hna_lhash_lock, flags); return i; }
void pim_vxlan_add_term_dev(struct pim_instance *pim, struct interface *ifp) { struct pim_interface *pim_ifp; if (pim->vxlan.term_if == ifp) return; if (PIM_DEBUG_VXLAN) zlog_debug("vxlan term oif changed from %s to %s", pim->vxlan.term_if ? pim->vxlan.term_if->name : "-", ifp->name); /* enable pim on the term ifp */ pim_ifp = (struct pim_interface *)ifp->info; if (pim_ifp) { PIM_IF_DO_PIM(pim_ifp->options); } else { pim_ifp = pim_if_new(ifp, false /*igmp*/, true /*pim*/, false /*pimreg*/, true /*vxlan_term*/); /* ensure that pimreg existss before using the newly created * vxlan termination device */ pim_if_create_pimreg(pim); } pim->vxlan.term_if = ifp; if (pim->vxlan.sg_hash) hash_iterate(pim_ifp->pim->vxlan.sg_hash, pim_vxlan_term_mr_oif_update, ifp); }
int hna_local_fill_buffer(unsigned char *buff, int buff_len) { struct hna_local_entry *hna_local_entry; struct hash_it_t *hashit = NULL; int i = 0; unsigned long flags; spin_lock_irqsave(&hna_local_hash_lock, flags); while (NULL != (hashit = hash_iterate(hna_local_hash, hashit))) { if (buff_len < (i + 1) * ETH_ALEN) break; hna_local_entry = hashit->bucket->data; memcpy(buff + (i * ETH_ALEN), hna_local_entry->addr, ETH_ALEN); i++; } /* if we did not get all new local hnas see you next time ;-) */ if (i == num_hna) atomic_set(&hna_local_changed, 0); spin_unlock_irqrestore(&hna_local_hash_lock, flags); return i; }
char *set_iterate(set *s, set_iter *state) { char *str; void *dummy; return (hash_iterate(s->ht, (hash_iter *)state, &str, &dummy) == 1) ? str : NULL; /* true : false */ }
/** * bcache_iterate - apply function to every BC entry * @func: function to apply * @arg: extra data for @func * * Iterates through binding cache, calling @func for each entry. * Extra data may be passed to @func in @arg. @func takes a bcentry * as its first argument and @arg as second argument. **/ int bcache_iterate(int (* func)(void *, void *), void *arg) { int err; pthread_rwlock_rdlock(&bc_lock); err = hash_iterate(&bc_hash, func, arg); pthread_rwlock_unlock(&bc_lock); return err; }
void xalloc_report(void) { XALLOC_REC *rec; HASH_NODE *node = NULL; int index = 0, i; char line[LEN], *l; struct info { int pos; char *fmt; int offset; } pinfo[] = { { 8, "%d", offsetof(XALLOC_REC, id) }, { 24, "%s", offsetof(XALLOC_REC, file) }, { 32, "%d", offsetof(XALLOC_REC, line) }, { 48, "%s", offsetof(XALLOC_REC, name) }, { 64, "0x%x", offsetof(XALLOC_REC, ptr) }, { 0, "%d", offsetof(XALLOC_REC, size) }}; ulog(ULOG_INFO, "xalloc-report: "); if(!xalloc_initialized) { ulog(ULOG_INFO, "nothing to report.\n"); return; } ulog(ULOG_INFO, "\n-------------\n"); ulog(ULOG_INFO, "\ttotal xmalloc() & xcalloc() : %d\n", xalloc_numalloc); ulog(ULOG_INFO, "\ttotal xrealloc() & xrecalloc() : %d\n", xalloc_numrealloc); ulog(ULOG_INFO, "\ttotal xfree() & xcfree() : %d\n\n", xalloc_numfree); if(hash_iterate(xalloc_hash, &index, &node)) { node = NULL, index = 0; ulog(ULOG_INFO, "ID\tFILE\t\tLINE\tSOURCE\t\tADDRESS\t\tSIZE\n"); ulog(ULOG_INFO, "--\t----\t\t----\t------\t\t-------\t\t----\n"); while((rec = hash_iterate(xalloc_hash, &index, &node)) != NULL) { l = line; for(i = 0; i < sizeof(pinfo) / sizeof(struct info); i++) { sprintf(l, pinfo[i].fmt, *(int *)((char *)rec + pinfo[i].offset)); l = l + strlen(l); while(l < line + pinfo[i].pos) *l++ = ' '; } ulog(ULOG_INFO, "%s\n", line); } } ulog(ULOG_INFO, "\n\n"); }
void pim_vxlan_mlag_update(bool enable, bool peer_state, uint32_t role, struct interface *peerlink_rif, struct in_addr *reg_addr) { struct pim_instance *pim; struct interface *old_oif; struct interface *new_oif; char addr_buf[INET_ADDRSTRLEN]; struct pim_interface *pim_ifp = NULL; if (PIM_DEBUG_VXLAN) { inet_ntop(AF_INET, reg_addr, addr_buf, INET_ADDRSTRLEN); zlog_debug("vxlan MLAG update %s state %s role %d rif %s addr %s", enable ? "enable" : "disable", peer_state ? "up" : "down", role, peerlink_rif ? peerlink_rif->name : "-", addr_buf); } /* XXX: for now vxlan termination is only possible in the default VRF * when that changes this will need to change to iterate all VRFs */ pim = pim_get_pim_instance(VRF_DEFAULT); old_oif = pim_vxlan_orig_mr_oif_get(pim); if (enable) vxlan_mlag.flags |= PIM_VXLAN_MLAGF_ENABLED; else vxlan_mlag.flags &= ~PIM_VXLAN_MLAGF_ENABLED; if (vxlan_mlag.peerlink_rif != peerlink_rif) vxlan_mlag.peerlink_rif = peerlink_rif; vxlan_mlag.reg_addr = *reg_addr; vxlan_mlag.peer_state = peer_state; vxlan_mlag.role = role; /* process changes */ if (vxlan_mlag.peerlink_rif) pim_ifp = (struct pim_interface *)vxlan_mlag.peerlink_rif->info; if ((vxlan_mlag.flags & PIM_VXLAN_MLAGF_ENABLED) && pim_ifp && (pim_ifp->mroute_vif_index > 0)) pim_vxlan_set_peerlink_rif(pim, peerlink_rif); else pim_vxlan_set_peerlink_rif(pim, NULL); new_oif = pim_vxlan_orig_mr_oif_get(pim); if (old_oif != new_oif) hash_iterate(pim->vxlan.sg_hash, pim_vxlan_sg_peerlink_update, new_oif); }
int hna_local_fill_buffer_text(struct net_device *net_dev, char *buff, size_t count, loff_t off) { struct bat_priv *bat_priv = netdev_priv(net_dev); struct hna_local_entry *hna_local_entry; HASHIT(hashit); int bytes_written = 0; unsigned long flags; size_t hdr_len; if (!bat_priv->primary_if) { if (off == 0) return sprintf(buff, "BATMAN mesh %s disabled - " "please specify interfaces to enable it\n", net_dev->name); return 0; } hdr_len = sprintf(buff, "Locally retrieved addresses (from %s) " "announced via HNA:\n", net_dev->name); if (off < hdr_len) bytes_written = hdr_len; spin_lock_irqsave(&hna_local_hash_lock, flags); while (hash_iterate(hna_local_hash, &hashit)) { hdr_len += 21; if (count < bytes_written + 22) break; if (off >= hdr_len) continue; hna_local_entry = hashit.bucket->data; bytes_written += snprintf(buff + bytes_written, 22, " * " MAC_FMT "\n", hna_local_entry->addr[0], hna_local_entry->addr[1], hna_local_entry->addr[2], hna_local_entry->addr[3], hna_local_entry->addr[4], hna_local_entry->addr[5]); } spin_unlock_irqrestore(&hna_local_hash_lock, flags); return bytes_written; }
static int unix_sock_req_data_reply(struct globals *globals, int client_sock, uint16_t id, uint8_t requested_type) { int len; struct alfred_push_data_v0 *push; struct hash_it_t *hashit = NULL; uint8_t buf[MAX_PAYLOAD]; uint16_t seqno = 0, ret = 0; /* send some data back through the unix socket */ push = (struct alfred_push_data_v0 *)buf; push->header.type = ALFRED_PUSH_DATA; push->header.version = ALFRED_VERSION; push->tx.id = htons(id); while (NULL != (hashit = hash_iterate(globals->data_hash, hashit))) { struct dataset *dataset = hashit->bucket->data; struct alfred_data *data; if (dataset->data.header.type != requested_type) continue; /* too large? - should never happen */ if (dataset->data.header.length + sizeof(*data) > MAX_PAYLOAD - sizeof(*push)) continue; data = push->data; memcpy(data, &dataset->data, sizeof(*data)); data->header.length = htons(data->header.length); memcpy(data->data, dataset->buf, dataset->data.header.length); len = dataset->data.header.length + sizeof(*data); len += sizeof(*push) - sizeof(push->header); push->header.length = htons(len); push->tx.seqno = htons(seqno++); if (write(client_sock, buf, sizeof(push->header) + len) < 0) { ret = -1; hash_iterate_free(hashit); break; } } close(client_sock); return ret; }
void xalloc_finish(void) { XALLOC_REC *rec; HASH_NODE *node = NULL; int index = 0; if(!xalloc_initialized) return; xalloc_initialized = 0; while((rec = hash_iterate(xalloc_hash, &index, &node)) != NULL) { hash_delete(xalloc_hash, rec); xar_destroy(rec); } hash_destroy(xalloc_hash); xalloc_hash = NULL; }
int cip_net_iterator(char **label) { ipnetobj *obj; static char label_buf[128]; if (0 == next_idx) return -1; if (NULL == label) { hash_iter_init(theHash); return next_idx; } if ((obj = hash_iterate(theHash)) == NULL) return -1; inXaddr_ntop(&obj->addr, label_buf, 128); *label = label_buf; return obj->index; }
int qname_iterator(char **label) { qnameobj *obj; static char label_buf[MAX_QNAME_SZ]; if (0 == next_idx) return -1; if (NULL == label) { hash_iter_init(theHash); return next_idx; } if ((obj = hash_iterate(theHash)) == NULL) return -1; snprintf(label_buf, MAX_QNAME_SZ, "%s", obj->qname); *label = label_buf; return obj->index; }
struct bat_host *bat_hosts_find_by_name(char *name) { struct hash_it_t *hashit = NULL; struct bat_host *bat_host = NULL, *tmp_bat_host; if (!host_hash) return NULL; while (NULL != (hashit = hash_iterate(host_hash, hashit))) { tmp_bat_host = (struct bat_host *)hashit->bucket->data; if (strncmp(tmp_bat_host->name, name, HOST_NAME_MAX_LEN - 1) == 0) bat_host = tmp_bat_host; } return bat_host; }
int hash_set (hashmap *map, void *key, void *val) { hashbucket **bucketp; hashiter iter; hashbucket *bucket; hashbucket **new_buckets; unsigned int num_buckets; bucketp = lookup_or_create_bucket (map, key, 1); if(bucketp && *bucketp) { /* Destroy the previous value */ if ((*bucketp)->value && map->value_destroy_func) map->value_destroy_func ((*bucketp)->value); /* replace entry */ (*bucketp)->value = val; /* check that the collision rate isn't too high */ if (map->num_items > map->num_buckets) { num_buckets = map->num_buckets * 2 + 1; new_buckets = (hashbucket **)calloc (sizeof (hashbucket *), num_buckets + 1); /* Ignore failures, maybe we can expand later */ if(new_buckets) { hash_iterate (map, &iter); while ((bucket = next_entry (&iter)) != NULL) { unsigned int i = bucket->hashed & num_buckets; bucket->next = new_buckets[i]; new_buckets[i] = bucket; } free (map->buckets); map->buckets = new_buckets; map->num_buckets = num_buckets; } } return 1; } return 0; }
int tld_iterator(char **label) { tldobj *obj; static char label_buf[MAX_QNAME_SZ]; if (0 == next_idx) return -1; if (NULL == label) { /* initialize and tell caller how big the array is */ hash_iter_init(theHash); return next_idx; } if ((obj = hash_iterate(theHash)) == NULL) return -1; snprintf(label_buf, MAX_QNAME_SZ, "%s", obj->tld); *label = label_buf; return obj->index; }
static void event_rats_invade_zone(struct char_data *ch, char *arg) { struct event_mob_set mobset[11] = { /* vnum, hp: xdy+z, exp: xdy+z, gold: xdy+z, object %, obj vnum */ {4618, 6, 8, 8, 1, 6, 4, 2, 6, 0, 2, 4602}, /* special large rat */ {4618, 4, 6, 5, 1, 6, 4, 1, 6, 0, 0, -1}, /* large rat */ {4618, 4, 6, 3, 1, 6, 4, 1, 4, 0, 0, -1}, /* large rat */ {3432, 3, 6, 1, 1, 6, 4, 1, 2, -1, 0, -1}, /* disgusting rat */ {3432, 2, 6, 1, 1, 6, 4, 0, 0, 0, 0, -1}, /* disgusting rat */ {3432, 2, 6, 1, 1, 6, 4, 0, 0, 0, 0, -1}, /* disgusting rat */ {3432, 2, 6, 1, 1, 6, 4, 0, 0, 0, 0, -1}, /* disgusting rat */ {3433, 4, 6, 1, 1, 6, 4, 1, 4, -1, 0, -1}, /* giant rat */ {3433, 4, 6, 1, 1, 6, 4, 1, 4, -1, 0, -1}, /* giant rat */ {3433, 4, 6, 5, 1, 6, 4, 1, 4, -1, 0, -1}, /* giant rat */ {5056, 3, 8, 5, 2, 6, 10, 1, 2, -1, 0, -1} /* black cat */ }; struct event_mob_in_zone mobs = { 0, 0, 60, 1, 8, 11, mobset }; int zone = 0; struct room_data *rp = NULL; if (DEBUG > 1) log_info("called %s with %s, %s", __PRETTY_FUNCTION__, SAFE_NAME(ch), VNULL(arg)); if ((rp = real_roomp(ch->in_room))) zone = rp->zone; else return; mobs.bottom = zone ? (zone_table[zone - 1].top + 1) : 0; mobs.top = zone_table[zone].top; if (IS_SET(ch->specials.act, PLR_STEALTH)) zprintf(zone, "\r\nYou feel a great surge of power!\r\nYou hear odd scurrying sounds all around you...\r\n\r\n"); else zprintf(zone, "\r\nIn a puff of acrid smoke, you see %s snap %s fingers!\r\nYou hear odd scurrying sounds all around you...\r\n\r\n", GET_NAME(ch), HSHR(ch)); mob_count = 0; hash_iterate(&room_db, (funcp)event_fill_zone_with_mobs, &mobs); cprintf(ch, "You just added %d rats to %s [#%d].\r\n", mob_count, zone_table[zone].name, zone); log_info("%s added %d rats to %s [#%d].", GET_NAME(ch), mob_count, zone_table[zone].name, zone); }
int main(int argc, char *argv[]) { unsigned int c1, *c2; const char *key; gtk_fetch_filetype_init("./mime.types"); c1 = 0; c2 = 0; while ( (key = hash_iterate(mime_hash, &c1, &c2)) != NULL) { printf("%s ", key); } printf("\n"); if (argc > 1) { printf("%s maps to %s\n", argv[1], fetch_filetype(argv[1])); } gtk_fetch_filetype_fin(); }
void hna_local_purge(struct work_struct *work) { struct hna_local_entry *hna_local_entry; struct hash_it_t *hashit = NULL; unsigned long flags; unsigned long timeout; spin_lock_irqsave(&hna_local_hash_lock, flags); while (NULL != (hashit = hash_iterate(hna_local_hash, hashit))) { hna_local_entry = hashit->bucket->data; timeout = hna_local_entry->last_seen + ((LOCAL_HNA_TIMEOUT / 1000) * HZ); if ((!hna_local_entry->never_purge) && time_after(jiffies, timeout)) hna_local_del(hna_local_entry, "address timed out"); } spin_unlock_irqrestore(&hna_local_hash_lock, flags); hna_local_start_timer(); }
void pim_vxlan_del_term_dev(struct pim_instance *pim) { struct interface *ifp = pim->vxlan.term_if; struct pim_interface *pim_ifp; if (PIM_DEBUG_VXLAN) zlog_debug("vxlan term oif changed from %s to -", ifp->name); pim->vxlan.term_if = NULL; if (pim->vxlan.sg_hash) hash_iterate(pim->vxlan.sg_hash, pim_vxlan_term_mr_oif_update, NULL); pim_ifp = (struct pim_interface *)ifp->info; if (pim_ifp) { PIM_IF_DONT_PIM(pim_ifp->options); if (!PIM_IF_TEST_IGMP(pim_ifp->options)) pim_if_delete(ifp); } }
static void event_scatter_goodies(struct char_data *ch, char *arg) { int the_objects[] = { 5023, 6131, 5932, 15011, 7010, 5937, 1901, 9015 }; int the_mobs[] = { 1200, 9618, 1400, 5441, 5054, 5055, 15047, 9620, 1202, 9601 }; struct event_goodies junk = { 0, 0, 50, 4, 6, -3, 7, 8, the_objects, 11, 10, the_mobs }; int zone = 0; struct room_data *rp = NULL; if (DEBUG > 1) log_info("called %s with %s, %s", __PRETTY_FUNCTION__, SAFE_NAME(ch), VNULL(arg)); if ((rp = real_roomp(ch->in_room))) zone = rp->zone; else return; junk.bottom = zone ? (zone_table[zone - 1].top + 1) : 0; junk.top = zone_table[zone].top; if (IS_SET(ch->specials.act, PLR_STEALTH)) zprintf(zone, "\r\nSuddenly, you fell the winds HOWL into being!\r\nYou can hear the sounds of things FALLING all around you!\r\n\r\n"); else zprintf(zone, "\r\nYou hear %s chanting, and suddenly a wind HOWLS in from %s direction!\r\nYou can hear the sounds of things FALLING all around you!\r\n\r\n", GET_NAME(ch), HSHR(ch)); mob_count = obj_count = gold_count = 0; hash_iterate(&room_db, (funcp)event_scatter_goodies_zone, &junk); cprintf(ch, "You just added %d critters, %d things, and %d gold to %s [#%d].\r\n", mob_count, obj_count, gold_count, zone_table[zone].name, zone); log_info("%s added %d critters, %d things, and %d gold to %s [#%d].\r\n", GET_NAME(ch), mob_count, obj_count, gold_count, zone_table[zone].name, zone); }
void hash_free (hashmap *map) { hashbucket *bucket; hashiter iter; if (!map) return; hash_iterate (map, &iter); while ((bucket = next_entry (&iter)) != NULL) { if (map->key_destroy_func) map->key_destroy_func (bucket->key); if (map->value_destroy_func) map->value_destroy_func (bucket->value); free (bucket); } if (map->buckets) free (map->buckets); free (map); }
int main() { struct hash *my_hash, *my_hash2; int x; /* Testing Hash with Linked List items */ struct list_t *root, *root2, *root3; int a=43,b=63,c=99,d=70,e=25,f=17,g=57,h=69,i=111,j=120,k=70,l=73,m=75; root = list_init(); root2 = list_init(); root3 = list_init(); root = list_remove_rear(root); root = list_remove_any(root,&k); root = list_remove_front(root); list_insert_rear(root, &a); list_insert_rear(root, &b); root = list_insert_after(root,&c,3); list_insert_rear(root, &d); root = list_insert_front(root, &e); root = list_insert_front(root, &f); list_insert_rear(root, &g); root = list_remove_front(root); list_insert_rear(root, &h); root = list_insert_after(root,&i,5); root = list_insert_after(root,&j,120); root = list_remove_any(root,&k); root = list_remove_front(root); list_insert_rear(root, &l); root = list_remove_any(root,&l); list_insert_rear(root, &m); root = list_remove_rear(root); root = list_remove_rear(root); root = list_remove_rear(root); root = list_remove_rear(root); root = list_remove_rear(root); root = list_remove_rear(root); root = list_remove_rear(root); my_hash = hash_init("list"); hash_insert(my_hash, "key1", root); hash_insert(my_hash, "key2", root2); hash_insert(my_hash, "key3", root3); printf("%s\n",my_hash->hash_type); char* s_val = "key2"; char* r_val = hash_get(my_hash, s_val); printf("%s - %s\n", s_val, r_val); hash_iterate(my_hash); hash_destroy(my_hash); /* Testing Hash with Binary Tree items */ struct node *root_node = NULL, *root_node2 = NULL, *root_node3 = NULL; root_node = insert(root_node,5,NULL); root_node = delete_node(root_node,5); root_node = insert(root_node,7,NULL); root_node = insert(root_node,3,NULL); root_node = insert(root_node,6,NULL); root_node = insert(root_node,9,NULL); root_node = insert(root_node,12,NULL); root_node = insert(root_node,1,NULL); print_preorder(root_node); root_node = delete_node(root_node,7); my_hash2 = hash_init("tree"); hash_insert(my_hash2, "key1", root_node); hash_insert(my_hash2, "key2", root_node2); hash_insert(my_hash2, "key3", root_node3); hash_iterate(my_hash2); hash_destroy(my_hash2); return 0; }
/* bul_iterate - iterates through binding update list calling func for * every entry. * @func: function to be called for every entry, @func * takes a void cast bulentry as its first argument and @arg as its * second. * @arg: second argument with which @func is called for every * bul entry */ int bul_iterate(struct hash *h, int (* func)(void *, void *), void *arg) { struct hash *tmp = h ? h : &bul_hash; return hash_iterate(tmp, func, arg); }
void bul_flush(void) { hash_iterate(&bul_hash, bule_cleanup, NULL); }