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; int next;
char *key; char *key;
int klen; int klen;
char *kana; char *val;
int kanalen; int vlen;
}; };
typedef struct Hmap Hmap; typedef struct Hmap Hmap;

14
dict.c
View File

@ -2,7 +2,7 @@
#include "fn.h" #include "fn.h"
static void static void
dictlkup(Dictreq *req, Dictres *res) dictlookup(Dictreq *req, Dictres *res)
{ {
Lang *l; Lang *l;
Hmap *dict; Hmap *dict;
@ -18,10 +18,10 @@ dictlkup(Dictreq *req, Dictres *res)
if(dict == nil) if(dict == nil)
return; return;
n = hmapget(dict, &req->key); n = hmapget(dict, &req->key);
if(n == nil || n->kanalen == 0) if(n == nil || n->vlen == 0)
return; return;
p = n->kana; p = n->val;
e = p + n->kanalen; e = p + n->vlen;
while(res->nkouho < Maxkouho && p < e){ while(res->nkouho < Maxkouho && p < e){
sp = p; sp = p;
while(p < e && *p != ' ') while(p < e && *p != ' ')
@ -46,14 +46,14 @@ dictthread(void*)
break; break;
while(channbrecv(dictreqc, &req) > 0) while(channbrecv(dictreqc, &req) > 0)
; ;
dictlkup(&req, &res); dictlookup(&req, &res);
res.key = req.pre; res.key = req.pre;
chansend(dictresc, &res); chansend(dictresc, &res);
} }
} }
static Hmap* static Hmap*
opendict(char *path) dictopen(char *path)
{ {
Hmap *h; Hmap *h;
Biobuf *b; Biobuf *b;
@ -96,7 +96,7 @@ dictinit(char *dir)
if(langs[i].dictname == nil) if(langs[i].dictname == nil)
continue; continue;
snprint(path, sizeof(path), "%s/%s.dict", dir, langs[i].dictname); 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* static char*
str2dup(Str *s) sdup(Str *s)
{ {
char buf[256]; char buf[256];
char *p; char *p;
@ -79,7 +79,7 @@ str2dup(Str *s)
} }
int int
hmapset(Hmap **store, Str *key, Str *kana) hmapset(Hmap **store, Str *key, Str *val)
{ {
Hnode *n; Hnode *n;
uchar *v; uchar *v;
@ -116,14 +116,14 @@ hmapset(Hmap **store, Str *key, Str *kana)
n = (Hnode*)v; n = (Hnode*)v;
replace: replace:
if(n->filled == 0){ if(n->filled == 0){
n->key = str2dup(key); n->key = sdup(key);
n->klen = strlen(n->key); n->klen = strlen(n->key);
n->filled = 1; n->filled = 1;
} }
n->next = next; n->next = next;
if(kana->n > 0){ if(val->n > 0){
n->kana = str2dup(kana); n->val = sdup(val);
n->kanalen = strlen(n->kana); n->vlen = strlen(n->val);
} }
return 0; return 0;
} }

View File

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