+static void cf_write_flat (CFile cf, int no, int vno)
+{
+ int hno = (no*sizeof(int))/HASH_BSIZE;
+ int off = (no*sizeof(int)) - hno*sizeof(HASH_BSIZE);
+
+ hno += cf->head.next_bucket;
+ if (hno >= cf->head.flat_bucket)
+ cf->head.flat_bucket = hno+1;
+ mf_write (cf->hash_mf, hno, off, sizeof(int), &vno);
+}
+
+static void cf_moveto_flat (CFile cf)
+{
+ struct CFile_hash_bucket *p;
+ int i, j;
+
+ logf (LOG_LOG, "Moving to flat shadow.");
+ logf (LOG_LOG, "hits=%d miss=%d bucket_in_memory=%d total=%d",
+ cf->no_hits, cf->no_miss, cf->bucket_in_memory,
+ cf->head.next_bucket - cf->head.first_bucket);
+ assert (cf->head.state == 1);
+ flush_bucket (cf, -1);
+ assert (cf->bucket_in_memory == 0);
+ p = xmalloc (sizeof(*p));
+ for (i = cf->head.first_bucket; i < cf->head.next_bucket; i++)
+ {
+ if (!mf_read (cf->hash_mf, i, 0, 0, &p->ph))
+ {
+ logf (LOG_FATAL|LOG_ERRNO, "read bucket moveto flat");
+ exit (1);
+ }
+ for (j = 0; j < HASH_BUCKET && p->ph.vno[j]; j++)
+ cf_write_flat (cf, p->ph.no[j], p->ph.vno[j]);
+ }
+ xfree (p);
+ xfree (cf->array);
+ cf->array = NULL;
+ xfree (cf->parray);
+ cf->parray = NULL;
+ cf->head.state = 2;
+}
+