From 555e213c3a100db431fec78cbba6dfed8e541e2a Mon Sep 17 00:00:00 2001 From: j8takagi Date: Sun, 31 Jan 2010 13:03:02 +0900 Subject: [PATCH] =?utf8?q?=E3=82=B3=E3=83=9E=E3=83=B3=E3=83=89=E8=A1=A8?= =?utf8?q?=E3=81=A8=E3=83=A9=E3=83=99=E3=83=AB=E8=A1=A8=E3=81=AE=E4=BD=9C?= =?utf8?q?=E6=88=90=E6=99=82=E3=81=AB=E3=80=81=E5=85=B1=E7=94=A8=E4=BD=93?= =?utf8?q?=E7=89=88hash=E9=96=A2=E6=95=B0=E3=82=92=E4=BD=BF=E3=81=86?= =?utf8?q?=E3=82=88=E3=81=86=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/cmd.c | 30 ++++++++++++++++++++---------- src/label.c | 3 +-- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/cmd.c b/src/cmd.c index 1ba5152..c399ac4 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -69,13 +69,18 @@ bool create_cmdtype_code() /* 命令と命令タイプからハッシュ値を生成する */ unsigned hash_cmdtype(const char *cmd, CMDTYPE type) { - int i; - unsigned hashval = 0; - for(i = 0; *cmd != '\0'; cmd++) { - hashval = *cmd + 31 * hashval; - } - hashval = (int)(type & 070) + 31 * hashval; - return hashval % cmdcodesize; + HKEY *keys[2]; + + /* 命令をセット */ + keys[0] = malloc(sizeof(HKEY)); + keys[0]->type = CHARS; + keys[0]->val.s = strdup(cmd); + /* 命令タイプをセット */ + keys[1] = malloc(sizeof(HKEY)); + keys[1]->type = INT; + keys[1]->val.i = (int)(type & 070); + /* ハッシュ値を返す */ + return hash(2, keys, cmdcodesize); } /* 命令と命令タイプから、命令コードを取得する。 @@ -147,9 +152,14 @@ bool create_code_type() /* 命令コードからハッシュ値を生成する */ unsigned hash_code(WORD code) { - unsigned hashval = 0; - hashval = (code >> 8); - return hashval % cmdcodesize; + HKEY *keys[1]; + + /* 命令コードをセット */ + keys[0] = malloc(sizeof(HKEY)); + keys[0]->type = INT; + keys[0]->val.i = (int)(code >> 8); + /* ハッシュ値を返す */ + return hash(1, keys, cmdcodesize); } /* 命令コードから命令タイプを取得する。 diff --git a/src/label.c b/src/label.c index b58def5..d740b2e 100644 --- a/src/label.c +++ b/src/label.c @@ -25,8 +25,7 @@ WORD getlabel(const char *prog, const char *label) { LABELTAB *np; for(np = labels[labelhash(prog, label)]; np != NULL; np = np->next) { - if(((prog == NULL && np->prog == NULL) || - (prog != NULL && np->prog != NULL && strcmp(prog, np->prog) == 0)) && + if((prog == NULL || (np->prog != NULL && strcmp(prog, np->prog) == 0)) && strcmp(label, np->label) == 0) { return np->adr; -- 2.18.0