+static void cf_write_flat (CFile cf, zint no, zint vno)
+{
+ zint hno = (no*sizeof(zint))/HASH_BSIZE;
+ int off = (int) ((no*sizeof(zint)) - hno*HASH_BSIZE);
+
+ hno += cf->head.next_bucket;
+ if (hno >= cf->head.flat_bucket)
+ cf->head.flat_bucket = hno+1;
+ cf->dirty = 1;
+ mf_write (cf->hash_mf, hno, off, sizeof(zint), &vno);
+}
+
+static void cf_moveto_flat (CFile cf)
+{
+ struct CFile_hash_bucket *p;
+ int j;
+ zint i;
+
+ yaz_log (YLOG_DEBUG, "cf: Moving to flat shadow: %s", cf->rmf->name);
+ yaz_log (YLOG_DEBUG, "cf: hits=%d miss=%d bucket_in_memory=" ZINT_FORMAT " total="
+ ZINT_FORMAT,
+ 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 = (struct CFile_hash_bucket *) 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))
+ {
+ yaz_log (YLOG_FATAL|YLOG_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;
+ cf->dirty = 1;
+}
+
+static zint cf_lookup (CFile cf, zint no)
+{
+ if (cf->head.state > 1)
+ return cf_lookup_flat (cf, no);
+ return cf_lookup_hash (cf, no);
+}
+
+static zint cf_new_flat (CFile cf, zint no)
+{
+ zint vno = (cf->head.next_block)++;
+
+ cf_write_flat (cf, no, vno);
+ return vno;
+}
+
+static zint cf_new_hash (CFile cf, zint no)