rename hnode fields, functions.

This commit is contained in:
Hojun-Cho 2026-02-08 16:29:29 +09:00
parent f5f88e8451
commit 97f897755f
4 changed files with 17 additions and 17 deletions

4
dat.h
View File

@ -58,8 +58,8 @@ struct Hnode
int next;
char *key;
int klen;
char *kana;
int kanalen;
char *val;
int vlen;
};
typedef struct Hmap Hmap;

14
dict.c
View File

@ -2,7 +2,7 @@
#include "fn.h"
static void
dictlkup(Dictreq *req, Dictres *res)
dictlookup(Dictreq *req, Dictres *res)
{
Lang *l;
Hmap *dict;
@ -18,10 +18,10 @@ dictlkup(Dictreq *req, Dictres *res)
if(dict == nil)
return;
n = hmapget(dict, &req->key);
if(n == nil || n->kanalen == 0)
if(n == nil || n->vlen == 0)
return;
p = n->kana;
e = p + n->kanalen;
p = n->val;
e = p + n->vlen;
while(res->nkouho < Maxkouho && p < e){
sp = p;
while(p < e && *p != ' ')
@ -46,14 +46,14 @@ dictthread(void*)
break;
while(channbrecv(dictreqc, &req) > 0)
;
dictlkup(&req, &res);
dictlookup(&req, &res);
res.key = req.pre;
chansend(dictresc, &res);
}
}
static Hmap*
opendict(char *path)
dictopen(char *path)
{
Hmap *h;
Biobuf *b;
@ -96,7 +96,7 @@ dictinit(char *dir)
if(langs[i].dictname == nil)
continue;
snprint(path, sizeof(path), "%s/%s.dict", dir, langs[i].dictname);
langs[i].dict = opendict(path);
langs[i].dict = dictopen(path);
}
}

12
hash.c
View File

@ -65,7 +65,7 @@ hmapget(Hmap *h, Str *key)
}
static char*
str2dup(Str *s)
sdup(Str *s)
{
char buf[256];
char *p;
@ -79,7 +79,7 @@ str2dup(Str *s)
}
int
hmapset(Hmap **store, Str *key, Str *kana)
hmapset(Hmap **store, Str *key, Str *val)
{
Hnode *n;
uchar *v;
@ -116,14 +116,14 @@ hmapset(Hmap **store, Str *key, Str *kana)
n = (Hnode*)v;
replace:
if(n->filled == 0){
n->key = str2dup(key);
n->key = sdup(key);
n->klen = strlen(n->key);
n->filled = 1;
}
n->next = next;
if(kana->n > 0){
n->kana = str2dup(kana);
n->kanalen = strlen(n->kana);
if(val->n > 0){
n->val = sdup(val);
n->vlen = strlen(n->val);
}
return 0;
}

View File

@ -316,9 +316,9 @@ mapget(Hmap *h, Str *key, Str *out)
if(key->n == 0)
return 0;
n = hmapget(h, key);
if(n == nil || n->kanalen == 0)
if(n == nil || n->vlen == 0)
return 0;
sinit(out, n->kana, n->kanalen);
sinit(out, n->val, n->vlen);
return 1;
}