summaryrefslogtreecommitdiffstats
path: root/mbbsd/record.c
diff options
context:
space:
mode:
authorptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-05-01 00:00:27 +0800
committerptt <ptt@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2004-05-01 00:00:27 +0800
commit770a864a23d078ed050edb116ee27db0ea43a449 (patch)
tree34e3a9225036ab166bfe59903a67b17a006730cb /mbbsd/record.c
parentfe0da2f0c443d67c437276909c42d742c1eda259 (diff)
downloadpttbbs-770a864a23d078ed050edb116ee27db0ea43a449.tar
pttbbs-770a864a23d078ed050edb116ee27db0ea43a449.tar.gz
pttbbs-770a864a23d078ed050edb116ee27db0ea43a449.tar.bz2
pttbbs-770a864a23d078ed050edb116ee27db0ea43a449.tar.lz
pttbbs-770a864a23d078ed050edb116ee27db0ea43a449.tar.xz
pttbbs-770a864a23d078ed050edb116ee27db0ea43a449.tar.zst
pttbbs-770a864a23d078ed050edb116ee27db0ea43a449.zip
update getindex to binary search
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@1903 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd/record.c')
-rw-r--r--mbbsd/record.c49
1 files changed, 31 insertions, 18 deletions
diff --git a/mbbsd/record.c b/mbbsd/record.c
index e551db61..be3b1c07 100644
--- a/mbbsd/record.c
+++ b/mbbsd/record.c
@@ -141,35 +141,48 @@ substitute_ref_record(char *direct, fileheader_t * fhdr, int ent)
get_record(genbuf, &hdr, sizeof(hdr), num);
if (strcmp(hdr.filename, fhdr->filename))
{
- if((num = getindex(genbuf, fhdr->filename, num)))
+ if((num = getindex(genbuf, fhdr, num)))
+ {
substitute_record(genbuf, fhdr, sizeof(*fhdr), num);
- fhdr->money = FHR_REFERENCE | num ; // Ptt: update now!
+ }
}
else
- substitute_record(genbuf, fhdr, sizeof(*fhdr), num);
+ {
+ fhdr->money = hdr.money;
+ substitute_record(genbuf, fhdr, sizeof(*fhdr), num);
+ }
+ fhdr->money = FHR_REFERENCE | num ; // Ptt: update now!
}
substitute_record(direct, fhdr, sizeof(*fhdr), ent);
return num;
}
int
-getindex(char *fpath, char *fname, int start)
+getindex(char *direct, fileheader_t *fh_o, int end)
{ // Ptt: 從前面找很費力 太暴力
-#define READSIZE 64 // 8192 / sizeof(fileheader_t)
- int fd, i, len, n = 1; /* n starts from 1 */
- fileheader_t fhdrs[READSIZE];
-
- if ((fd = open(fpath, O_RDONLY, 0)) != -1) {
- while( (len = read(fd, fhdrs, sizeof(fhdrs))) > 0 ){
- len /= sizeof(fileheader_t);
- for( i = 0 ; i < len ; ++i, ++n )
- if (!strcmp(fhdrs[i].filename, fname)) {
- close(fd);
- return now;
- }
- }
- close(fd);
+ int fd=-1, begin=1, i, stamp, s;
+ fileheader_t fh;
+
+ i = get_num_records(direct, sizeof(fileheader_t));
+ if(end>i) end = i;
+ stamp = atoi(fh_o->filename+2);
+ i=(begin+end)/2;
+ for(; end>begin+1; i=(begin+end)/2)
+ {
+ if(get_record_keep(direct, &fh, sizeof(fileheader_t), i, &fd)==-1)
+ break;
+ if(!fh.filename[0]) break;
+ s = atoi(fh.filename+2);
+ if (s > stamp) end = i+1;
+ else if(s == stamp)
+ {
+ close(fd);
+ fh_o->money = fh.money;
+ return i;
+ }
+ else begin = i;
}
+ if(fd==-1) close(fd);
return 0;
}