void ScopeDeleteAll() { Scope *ptr, *this; CfDebug("Deleting all scoped variables\n"); if (!ThreadLock(cft_vscope)) { CfOut(OUTPUT_LEVEL_ERROR, "", "!! Could not lock VSCOPE"); return; } ptr = VSCOPE; while (ptr != NULL) { this = ptr; CfDebug(" -> Deleting scope %s\n", ptr->scope); HashFree(this->hashtable); free(this->scope); ptr = this->next; free((char *) this); } VSCOPE = NULL; SCOPE_CURRENT = NULL; ThreadUnlock(cft_vscope); }
void ScopeDeleteAll() { Scope *ptr, *this; if (!ThreadLock(cft_vscope)) { Log(LOG_LEVEL_ERR, "Could not lock VSCOPE"); return; } ptr = VSCOPE; while (ptr != NULL) { this = ptr; HashFree(this->hashtable); free(this->scope); ptr = this->next; free((char *) this); } VSCOPE = NULL; ThreadUnlock(cft_vscope); }
void ScopeClear(const char *ns, const char *name) { assert(name); assert(!ScopeIsReserved(name)); if (!ns) { ns = "default"; } if (!ThreadLock(cft_vscope)) { Log(LOG_LEVEL_ERR, "Could not lock VSCOPE"); return; } Scope *scope = ScopeGet(ns, name); if (!scope) { Log(LOG_LEVEL_DEBUG, "No scope '%s' to clear", name); ThreadUnlock(cft_vscope); return; } HashFree(scope->hashtable); scope->hashtable = HashInit(); Log(LOG_LEVEL_DEBUG, "Scope '%s' cleared", name); ThreadUnlock(cft_vscope); }
local void ClearFlagTeam(FlagTeam *team) { MYGLOCK; HashFree(team->Breakdown); afree(team); MYGUNLOCK; }
static void ScopeDelete(Scope *scope) { if (!ThreadLock(cft_vscope)) { Log(LOG_LEVEL_ERR, "Could not lock VSCOPE"); return; } Scope *prev = NULL; for (Scope *curr = VSCOPE; curr; prev = curr, curr = curr->next) { if (curr != scope) { continue; } if (!prev) { VSCOPE = scope->next; } else { prev->next = curr->next; } free(scope->scope); HashFree(scope->hashtable); free(scope); break; } ThreadUnlock(cft_vscope); }
local int cmd_players(int argc, char *argv[]) { players_hash = HashAlloc(); walk_db(players_get_names, FALSE); printf(" this database contains information about these players:\n"); printf(" %-18.18s %-17s\n", "player name", "records / bytes"); HashEnum(players_hash, players_print_names, NULL); HashFree(players_hash); return 0; }
local void free_players() { Player *p; Link *link; pd->Lock(); FOR_EACH_PLAYER(p) { PData *pdata = PPDATA(p, pdata_key); if (pdata->vars) { HashEnum(pdata->vars, hash_enum_afree, NULL); HashFree(pdata->vars); } } pd->Unlock(); }
local int cmd_arenas(int argc, char *argv[]) { arenas_hash = HashAlloc(); walk_db(arenas_get_names, FALSE); printf(" this database contains information about these arenas:\n"); printf(" %-14.14s %-17s %-17s %-17s\n", "arena name", "player recs/bytes", " arena recs/bytes", " total recs/bytes"); HashEnum(arenas_hash, arenas_print_names, NULL); HashFree(arenas_hash); return 0; }
local void player_action(Player *p, int action, Arena *arena) { PData *pdata = PPDATA(p, pdata_key); if (action == PA_CONNECT) { FormulaVariable *var = amalloc(sizeof(FormulaVariable)); var->name = astrdup("me"); var->type = VAR_TYPE_PLAYER; var->p = p; pdata->vars = HashAlloc(); HashAdd(pdata->vars, var->name, var); } else if (action == PA_DISCONNECT) { HashEnum(pdata->vars, var_free_enum, NULL); HashFree(pdata->vars); } }
void ScopeClear(const char *name) { if (!ThreadLock(cft_vscope)) { Log(LOG_LEVEL_ERR, "Could not lock VSCOPE"); return; } Scope *scope = ScopeGet(name); if (!scope) { Log(LOG_LEVEL_DEBUG, "No such scope to clear"); ThreadUnlock(cft_vscope); return; } HashFree(scope->hashtable); scope->hashtable = HashInit(); ThreadUnlock(cft_vscope); }
void ScopeClearSpecial(SpecialScope scope) { if (!ThreadLock(cft_vscope)) { Log(LOG_LEVEL_ERR, "Could not lock VSCOPE"); return; } Scope *ptr = ScopeGet(NULL, SpecialScopeToString(scope)); if (!ptr) { Log(LOG_LEVEL_DEBUG, "No special scope '%s' to clear", SpecialScopeToString(scope)); ThreadUnlock(cft_vscope); return; } HashFree(ptr->hashtable); ptr->hashtable = HashInit(); Log(LOG_LEVEL_DEBUG, "Special scope '%s' cleared", SpecialScopeToString(scope)); ThreadUnlock(cft_vscope); }
local int cmd_serials(int argc, char *argv[]) { serials_ag = argv[1]; if (!serials_ag) { puts("you must specify an arena name"); return 1; } serials_hash = HashAlloc(); walk_db(serials_get_names, FALSE); printf(" for arena %s, interval %s, these serials are defined:\n", serials_ag, get_interval_name(args.iv)); HashEnum(serials_hash, serials_print_nums, NULL); HashFree(serials_hash); return 0; }
void ScopeClear(const char *name) { CfDebug("Clearing scope %s\n", name); if (!ThreadLock(cft_vscope)) { CfOut(OUTPUT_LEVEL_ERROR, "", "!! Could not lock VSCOPE"); return; } Scope *scope = ScopeGet(name); if (!scope) { CfDebug("No such scope to clear\n"); ThreadUnlock(cft_vscope); return; } HashFree(scope->hashtable); scope->hashtable = HashInit(); ThreadUnlock(cft_vscope); }
static void StackFramePromiseDestroy(StackFramePromise frame) { HashFree(frame.variables); }
int main(void) { int size = 0, h; char cmd, key[1024], value[1024], buf[1024]; Hash *hash; // ハッシュテーブルの生成 printf("ハッシュテーブルの大きさを入力して下さい: "); scanf("%d", &size); if (size < 1) return -1;// 入力数エラー hash = HashAlloc(size); if (hash == NULL) return -1; // メモリ確保失敗 puts("* ハッシュテーブルを操作するコマンドを入力して下さい."); puts("* データを格納:a"); puts("* キーを削除:x"); puts("* キーに対応するデータの取得:g"); puts("* ハッシュテーブルを表示:d"); puts("* ハッシュ値の表示:h"); puts("* ハッシュテーブルをクリア:c"); puts("* 終了:q"); do { printf(": "); scanf("%s", buf); cmd = buf[0]; switch (cmd) { case 'a': /* データを格納 */ printf("名前を入力して下さい:"); scanf("%s", key); printf("血液型を入力して下さい:"); scanf("%s", value); if (HashAdd(hash, key, value) == TRUE) { // hash, name, blood-type printf("%s=%sを格納しました.\n", key, value); } else { /* 衝突 */ printf("既に同じキーを持つデータが存在します.\n"); } break; case 'd': /* データを表示 */ HashDump(hash); break; case 'c': /* ハッシュテーブルをクリア */ HashClear(hash); break; case 'x': /* キーを削除 */ printf("誰を削除しますか?:"); scanf("%s", key); if(HashDelete(hash, key) == TRUE) { printf("%sを削除しました.\n", key); } else { printf("%sは登録されていません.\n", key); } break; case 'g': /* キーに対応するデータを取得 */ printf("名前を入力して下さい:"); scanf("%s", key); if (HashGet(hash, key, value) == TRUE) { printf("%sの血液型は%sです.\n", key, value); } else { printf("%sは登録されていません.\n", key); } break; case 'h': /* キーに対応するデータを取得 */ printf("名前を入力して下さい:"); scanf("%s", key); h = HashCode(hash, key); printf("%sのハッシュ値は%dです.", key, h); break; case 'q': /* 終了 */ puts("プログラムを終了します."); break; case '\n': /* 改行 */ case '\r': /* 復帰 */ break; default: /* 入力エラー */ puts("コマンドが正しくありません."); break; } } while (cmd != 'q'); HashDump(hash); // 解放前の出力 HashFree(hash); // メモリ解放 return 0; }