Add cost calculation

This commit is contained in:
Nishi 2026-06-24 11:39:52 +09:00
commit 54d3831094
14 changed files with 136 additions and 16 deletions

View file

@ -121,6 +121,16 @@ setnspr(SJ4_CONTEXT KHREC* kptr, STDYIN* sptr) {
if(sptr->nmflg && (nrank > keepnm)) nrank = keepnm;
}
static int sort_kouhotbl(const void* a, const void* b){
const KHREC* akh = a;
const KHREC* bkh = b;
if(akh->cost < bkh->cost) return -1;
if(akh->cost > bkh->cost) return 1;
return 0;
}
static void
regetrank(SJ4_CONTEXT2) {
KHREC* kptr;
@ -138,6 +148,8 @@ regetrank(SJ4_CONTEXT2) {
nkhcount = tmp = 0;
}
qsort(kouhotbl, khcount, sizeof(*kouhotbl), sort_kouhotbl);
for(count = khcount, kptr = kouhotbl; count--; kptr++) {
if(!(kptr->rank)) {