X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=bfile%2Fcfile.c;h=bacbe8392a0e9d16c5172f8e7fc619a0a1547119;hb=bee234a243b7bfc164f7096f35d1bcb98e7b24a9;hp=cfcd6daae186414f38bf461c5cf5c08bcaab13ab;hpb=25c9afa691b8f62c2a17150cf1febd1f61755b12;p=idzebra-moved-to-github.git diff --git a/bfile/cfile.c b/bfile/cfile.c index cfcd6da..bacbe83 100644 --- a/bfile/cfile.c +++ b/bfile/cfile.c @@ -4,7 +4,24 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: cfile.c,v $ - * Revision 1.4 1995-12-01 16:24:28 adam + * Revision 1.9 1996-02-07 10:08:43 adam + * Work on flat shadow (not finished yet). + * + * Revision 1.8 1995/12/15 12:36:52 adam + * Moved hash file information to union. + * Renamed commit files. + * + * Revision 1.7 1995/12/15 10:35:07 adam + * Changed names of commit files. + * + * Revision 1.6 1995/12/11 09:03:53 adam + * New function: cf_unlink. + * New member of commit file head: state (0) deleted, (1) hash file. + * + * Revision 1.5 1995/12/08 16:21:14 adam + * Work on commit/update. + * + * Revision 1.4 1995/12/01 16:24:28 adam * Commit files use separate meta file area. * * Revision 1.3 1995/12/01 11:37:22 adam @@ -64,27 +81,30 @@ static int read_head (CFile cf) CFile cf_open (MFile mf, MFile_area area, const char *fname, int block_size, int wflag, int *firstp) { - char path[256]; + char path[1024]; int i; CFile cf = xmalloc (sizeof(*cf)); int hash_bytes; cf->rmf = mf; - sprintf (path, "%s.b", fname); + sprintf (path, "%s-b", fname); if (!(cf->block_mf = mf_open (area, path, block_size, wflag))) { logf (LOG_FATAL|LOG_ERRNO, "Failed to open %s", path); exit (1); } - sprintf (path, "%s.h", fname); + sprintf (path, "%s-i", fname); if (!(cf->hash_mf = mf_open (area, path, HASH_BSIZE, wflag))) { logf (LOG_FATAL|LOG_ERRNO, "Failed to open %s", path); exit (1); } - if (!mf_read (cf->hash_mf, 0, 0, sizeof(cf->head), &cf->head)) + assert (firstp); + if (!mf_read (cf->hash_mf, 0, 0, sizeof(cf->head), &cf->head) || + !cf->head.state) { *firstp = 1; + cf->head.state = 1; cf->head.block_size = block_size; cf->head.hash_size = 401; hash_bytes = cf->head.hash_size * sizeof(int); @@ -103,7 +123,7 @@ CFile cf_open (MFile mf, MFile_area area, const char *fname, { *firstp = 0; assert (cf->head.block_size == block_size); - assert (cf->head.hash_size > 2 && cf->head.hash_size < 200000); + assert (cf->head.hash_size > 2); hash_bytes = cf->head.hash_size * sizeof(int); assert (cf->head.next_bucket > 0); cf->array = xmalloc (hash_bytes); @@ -225,7 +245,17 @@ static struct CFile_hash_bucket *new_bucket (CFile cf, int *block_no, int hno) return p; } -int cf_lookup (CFile cf, int no) +static int cf_lookup_flat (CFile cf, int no) +{ + int hno = (no*sizeof(int))/HASH_BSIZE; + int off = (no*sizeof(int)) - hno*sizeof(HASH_BSIZE); + int vno = 0; + + mf_read (cf->hash_mf, hno+cf->head.next_bucket, off, sizeof(int), &vno); + return vno; +} + +static int cf_lookup_hash (CFile cf, int no) { int hno = cf_hash (cf, no); struct CFile_hash_bucket *hb; @@ -254,14 +284,30 @@ int cf_lookup (CFile cf, int no) return 0; } -int cf_new (CFile cf, int no) +static int cf_lookup (CFile cf, int no) +{ + if (cf->head.state > 1) + return cf_lookup_flat (cf, no); + return cf_lookup_hash (cf, no); +} + +int cf_new_flat (CFile cf, int no) +{ + int hno = (no*sizeof(int))/HASH_BSIZE; + int off = (no*sizeof(int)) - hno*sizeof(HASH_BSIZE); + int vno = (cf->head.next_block)++; + + mf_write (cf->hash_mf, hno+cf->head.next_bucket, off, sizeof(int), &vno); + return vno; +} + +static int cf_new_hash (CFile cf, int no) { int hno = cf_hash (cf, no); struct CFile_hash_bucket *hbprev = NULL, *hb = cf->parray[hno]; - int *bucketpp = &cf->array[hno]; - int i; - int vno = (cf->head.next_block)++; - + int *bucketpp = &cf->array[hno]; + int i, vno = (cf->head.next_block)++; + for (hb = cf->parray[hno]; hb; hb = hb->h_next) if (!hb->ph.vno[HASH_BUCKET-1]) for (i = 0; ihead.state > 1) + return cf_new_flat (cf, no); + return cf_new_hash (cf, no); +} + + int cf_read (CFile cf, int no, int offset, int num, void *buf) { int block;