+static void cf_commit_flat (CFile cf)
+{
+ zint *fp;
+ zint hno;
+ int i;
+ zint vno = 0;
+
+#if CF_OPTIMIZE_COMMIT
+ struct map_cache *m_p;
+#endif
+
+
+#if CF_OPTIMIZE_COMMIT
+ m_p = map_cache_init (cf);
+#endif
+ fp = (zint *) xmalloc (HASH_BSIZE);
+ for (hno = cf->head.next_bucket; hno < cf->head.flat_bucket; hno++)
+ {
+ for (i = 0; i < (int) (HASH_BSIZE/sizeof(zint)); i++)
+ fp[i] = 0;
+ if (!mf_read (cf->hash_mf, hno, 0, 0, fp) &&
+ hno != cf->head.flat_bucket-1)
+ {
+ yaz_log (YLOG_FATAL, "read index block hno=" ZINT_FORMAT
+ " (" ZINT_FORMAT "-" ZINT_FORMAT ") commit",
+ hno, cf->head.next_bucket, cf->head.flat_bucket-1);
+ }
+ for (i = 0; i < (int) (HASH_BSIZE/sizeof(zint)); i++)
+ {
+ if (fp[i])
+ {
+#if CF_OPTIMIZE_COMMIT
+ map_cache_add (m_p, fp[i], vno);
+#else
+ if (!mf_read (cf->block_mf, fp[i], 0, 0, cf->iobuf))
+ {
+ yaz_log (YLOG_FATAL, "read data block hno=" ZINT_FORMAT " (" ZINT_FORMAT "-" ZINT_FORMAT ") "
+ "i=%d commit block at " ZINT_FORMAT " (->" ZINT_FORMAT")",
+ hno, cf->head.next_bucket, cf->head.flat_bucket-1,
+ i, fp[i], vno);
+ exit (1);
+ }
+ mf_write (cf->rmf, vno, 0, 0, cf->iobuf);
+
+#endif
+ }
+ vno++;
+ }
+ }
+#if CF_OPTIMIZE_COMMIT
+ map_cache_del (m_p);
+#endif
+ xfree (fp);
+}
+
+void cf_commit (CFile cf)
+{
+
+ if (cf->bucket_in_memory)
+ {
+ yaz_log (YLOG_FATAL, "Cannot commit potential dirty cache");
+ exit (1);
+ }
+ if (cf->head.state == 1)
+ cf_commit_hash (cf);
+ else if (cf->head.state == 2)
+ cf_commit_flat (cf);
+}
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+