void* hash_borrar(hash_t* hash, const char* clave) { if (!hash_pertenece(hash,clave)) return NULL; size_t posicion = fhash(clave,hash->tamanio); lista_iter_t* iter = lista_iter_crear(hash->tabla[posicion]); nodo_hash_t* nodo = lista_iter_ver_actual(iter); bool esta = false; while (!lista_iter_al_final(iter)) { if (strcmp(nodo->clave,clave) == 0) { esta = true; break; } lista_iter_avanzar(iter); nodo = lista_iter_ver_actual(iter); } if (esta == false) { lista_iter_destruir(iter); return NULL; } nodo = (nodo_hash_t*)lista_borrar(hash->tabla[posicion],iter); void* dato = nodo->dato; free(nodo->clave); free(nodo); lista_iter_destruir(iter); hash->cantidad --; return dato; }
faction *faction_create(int no) { faction *f = (faction *)calloc(1, sizeof(faction)); if (!f) abort(); f->no = no; fhash(f); return f; }
faction *gm_addfaction(const char *email, plane * p, region * r) { attrib *a; unit *u; faction *f = calloc(1, sizeof(faction)); assert(p != NULL); /* GM faction */ a_add(&f->attribs, make_key(atoi36("quest"))); f->banner = _strdup("quest faction"); f->name = _strdup("quest faction"); f->passw = _strdup(itoa36(rng_int())); if (set_email(&f->email, email) != 0) { log_error("Invalid email address for faction %s: %s\n", itoa36(f->no), email); } f->race = new_race[RC_TEMPLATE]; f->age = 0; f->lastorders = turn; f->alive = true; f->locale = default_locale; f->options = want(O_COMPRESS) | want(O_REPORT) | want(O_COMPUTER) | want(O_ADRESSEN); { faction *xist; int id = atoi36("gm00") - 1; do { xist = findfaction(++id); } while (xist); f->no = id; addlist(&factions, f); fhash(f); } /* generic permissions */ a = a_add(&f->attribs, a_new(&at_permissions)); if (a) { attrib *ap = (attrib *) a->data.v; const char *keys[] = { "gmterf", "gmtele", "gmgive", "gmskil", "gmtake", "gmmsgr", "gmmsgu", "gmgate", 0 }; const char **key_p = keys; while (*key_p) { add_key(&ap, atoi36(*key_p)); ++key_p; } a_add(&ap, make_atgmcreate(resource2item(r_silver))); a->data.v = ap; } /* one initial unit */ u = create_unit(r, f, 1, new_race[RC_TEMPLATE], 1, "quest master", NULL); u->irace = new_race[RC_GNOME]; return f; }
void* hash_obtener(const hash_t* hash, const char* clave) { size_t posicion = fhash(clave,hash->tamanio); nodo_hash_t* nodo_clave = buscar_clave(hash->tabla[posicion],clave); // si no encuentro la clave devuelvo NULL if (nodo_clave == NULL) { return NULL; } // si encuentro la clave devuelvo el dato return nodo_clave->dato; }
bool hash_pertenece(const hash_t* hash, const char* clave) { size_t posicion = fhash(clave,hash->tamanio); nodo_hash_t* nodo_clave = buscar_clave(hash->tabla[posicion],clave); // si no encuentro la clave devuelvo NULL if (nodo_clave == NULL) { return false; } // si encuentro la clave devuelvo true return true; }
faction *addfaction(const char *email, const char *password, const struct race * frace, const struct locale * loc) { faction *f = calloc(1, sizeof(faction)); char buf[128]; if (!f) abort(); if (check_email(email) == 0) { faction_setemail(f, email); } else { log_info("Invalid email address for faction %s: %s\n", itoa36(f->no), email?email:""); faction_setemail(f, NULL); } f->alliance_joindate = turn; f->lastorders = 0; f->_alive = true; f->password_id = 0; f->age = 0; f->race = frace; f->magiegebiet = 0; f->locale = loc; f->uid = 0; f->flags = FFL_ISNEW|FFL_PWMSG; if (password) { faction_setpassword(f, password_hash(password, PASSWORD_DEFAULT)); ADDMSG(&f->msgs, msg_message("changepasswd", "value", password)); } f->options = WANT_OPTION(O_REPORT) | WANT_OPTION(O_ZUGVORLAGE) | WANT_OPTION(O_COMPUTER) | WANT_OPTION(O_COMPRESS) | WANT_OPTION(O_ADRESSEN) | WANT_OPTION(O_STATISTICS); f->no = unused_faction_id(); if (rule_region_owners()) { alliance *al = makealliance(f->no, NULL); setalliance(f, al); } addlist(&factions, f); fhash(f); slprintf(buf, sizeof(buf), "%s %s", LOC(loc, "factiondefault"), itoa36(f->no)); f->name = str_strdup(buf); if (!f->race) { log_warning("creating a faction that has no race", itoa36(f->no)); } return f; }
cons_t defun_eval(cons_t * cell, cons_t result) { cons_t *tmp = cell; cons_t *tmp_o; result.type = DEFUN; cell = cell->cdr; func_name_tmp = cell->symbol; result.symbol = cell->symbol; cell = cell->cdr; argset(cell->car); tmp_o = cell->cdr; fhash(tmp); setarg(tmp_o); return result; }
static void guardian_faction(plane * pl, int id) { region *r; faction *f = findfaction(id); if (!f) { f = calloc(1, sizeof(faction)); f->banner = _strdup("Sie dienen dem großen Wyrm"); f->passw = _strdup(itoa36(rng_int())); set_email(&f->email, "*****@*****.**"); f->name = _strdup("Igjarjuks Kundschafter"); f->race = new_race[RC_ILLUSION]; f->age = turn; f->locale = find_locale("de"); f->options = want(O_COMPRESS) | want(O_REPORT) | want(O_COMPUTER) | want(O_ADRESSEN) | want(O_DEBUG); f->no = id; addlist(&factions, f); fhash(f); } if (f->race != new_race[RC_ILLUSION]) { assert(!"guardian id vergeben"); exit(0); } f->lastorders = turn; f->alive = true; for (r = regions; r; r = r->next) if (getplane(r) == pl && rterrain(r) != T_FIREWALL) { unit *u; freset(r, RF_ENCOUNTER); for (u = r->units; u; u = u->next) { if (u->faction == f) break; } if (u) continue; u = createunit(r, f, 1, new_race[RC_GOBLIN]); set_string(&u->name, "Igjarjuks Auge"); set_item(u, I_RING_OF_INVISIBILITY, 1); set_order(&u->thisorder, NULL); fset(u, UFL_ANON_FACTION); set_money(u, 1000); } }
/** * File's actual metadata */ xa_t getactualxa(FILE *f) { xa_t actual; /* * Must read mtime *before* file hash, * if the file is being modified, hash will be invalid * but timestamp will be outdated anyway */ actual=getmtime(f); /* * Compute hash */ fhash(f,actual.sha256); return actual; }
hash_t* hash_redimensionar(hash_t* hash, size_t tamanio) { lista_t** nueva_tabla = creacion_tabla(hash,tamanio); if (nueva_tabla == NULL) return NULL; for (int i = 0; i < hash->tamanio; i ++) { lista_iter_t* iter = lista_iter_crear(hash->tabla[i]); const char* clave; size_t posicion; nodo_hash_t* nodo; while (!lista_iter_al_final(iter)) { nodo = lista_borrar(hash->tabla[i],iter); clave = nodo->clave; posicion = fhash(clave,tamanio); lista_insertar_primero(nueva_tabla[posicion],nodo); } lista_destruir(hash->tabla[i],NULL); lista_iter_destruir(iter); } free(hash->tabla); hash->tamanio = tamanio; hash->tabla = nueva_tabla; return hash; }
bool hash_guardar(hash_t* hash, const char* clave, void* dato) { size_t posicion = fhash(clave,hash->tamanio); nodo_hash_t* nodo_clave = buscar_clave(hash->tabla[posicion],clave); // si la clave no existe if (nodo_clave == NULL) { nodo_hash_t* nodo = creacion_nodo(clave,dato); lista_insertar_primero(hash->tabla[posicion],nodo); hash->cantidad ++; } // si la clave ya existe, reemplazo el dato if (nodo_clave != NULL) { if (hash->destruir_dato != NULL) { hash->destruir_dato(nodo_clave->dato); } nodo_clave->dato = dato; } //Factor de carga de 70 % float resultado = (hash->cantidad)/(hash->tamanio); if (resultado > FACTORCARGA) hash_redimensionar(hash,(hash->tamanio)*2); return true; }
void renumber_faction(faction * f, int no) { funhash(f); f->no = no; fhash(f); }