* Sebastian Hammer, Adam Dickmeiss
*
* $Log: isamc.c,v $
- * Revision 1.4 1996-11-01 13:36:46 adam
+ * Revision 1.5 1996-11-04 14:08:57 adam
+ * Optimized free block usage.
+ *
+ * Revision 1.4 1996/11/01 13:36:46 adam
* New element, max_blocks_mem, that control how many blocks of max size
* to store in memory during isc_merge.
- * Function isc_merge now ignoreds delete/update of identical keys and
+ * Function isc_merge now ignores delete/update of identical keys and
* the proper blocks are then non-dirty and not written in flush_blocks.
*
* Revision 1.3 1996/11/01 08:59:14 adam
#include <log.h>
#include "isamc-p.h"
+static void release_fc (ISAMC is, int cat);
+static void init_fc (ISAMC is, int cat);
+
ISAMC_M isc_getmethod (void)
{
static struct ISAMC_filecat_s def_cat[] = {
{
ISAMC is;
ISAMC_filecat filecat;
- int i;
+ int i, j;
int max_buf_size = 0;
is = xmalloc (sizeof(*is));
is->files[i].no_allocated = 0;
is->files[i].no_released = 0;
is->files[i].no_remap = 0;
+
+ init_fc (is, i);
}
return is;
}
logf (LOG_LOG, "isc: writes reads skipped alloc released remap");
for (i = 0; i<is->no_files; i++)
{
+ release_fc (is, i);
assert (is->files[i].bf);
if (is->files[i].head_is_dirty)
bf_write (is->files[i].bf, 0, 0, sizeof(ISAMC_head),
is->files[i].no_allocated,
is->files[i].no_released,
is->files[i].no_remap);
+ xfree (is->files[i].fc_list);
bf_close (is->files[i].bf);
}
xfree (is->files);
return isc_write_block (is, cat, pos, src - sizeof(int)*2);
}
-int isc_alloc_block (ISAMC is, int cat)
+static int alloc_block (ISAMC is, int cat)
{
int block;
char buf[sizeof(int)];
}
else
block = (is->files[cat].head.lastblock)++;
- if (is->method->debug > 2)
+ return block;
+}
+
+int isc_alloc_block (ISAMC is, int cat)
+{
+ int block = 0;
+
+ if (is->files[cat].fc_list)
+ {
+ int j, nb;
+ for (j = 0; j < is->files[cat].fc_max; j++)
+ if ((nb = is->files[cat].fc_list[j]) && (!block || nb < block))
+ {
+ is->files[cat].fc_list[j] = 0;
+ break;
+ }
+ }
+ if (!block)
+ block = alloc_block (is, cat);
+ if (is->method->debug > 3)
logf (LOG_LOG, "isc: alloc_block in cat %d: %d", cat, block);
return block;
}
-void isc_release_block (ISAMC is, int cat, int pos)
+static void release_block (ISAMC is, int cat, int pos)
{
char buf[sizeof(int)];
memcpy (buf, &is->files[cat].head.freelist, sizeof(int));
is->files[cat].head.freelist = pos;
bf_write (is->files[cat].bf, pos, 0, sizeof(int), buf);
- if (is->method->debug > 2)
+}
+
+void isc_release_block (ISAMC is, int cat, int pos)
+{
+ if (is->method->debug > 3)
logf (LOG_LOG, "isc: release_block in cat %d: %d", cat, pos);
+ if (is->files[cat].fc_list)
+ {
+ int b, j;
+ for (j = 0; j<is->files[cat].fc_max; j++)
+ if (!is->files[cat].fc_list[j])
+ {
+ is->files[cat].fc_list[j] = pos;
+ return;
+ }
+ }
+ release_block (is, cat, pos);
+}
+
+static void init_fc (ISAMC is, int cat)
+{
+ int j = 100;
+
+ is->files[cat].fc_max = j;
+ is->files[cat].fc_list = xmalloc (sizeof(*is->files[0].fc_list) * j);
+ while (--j >= 0)
+ is->files[cat].fc_list[j] = 0;
+}
+
+static void release_fc (ISAMC is, int cat)
+{
+ int b, j = is->files[cat].fc_max;
+
+ while (--j >= 0)
+ if ((b = is->files[cat].fc_list[j]))
+ {
+ release_block (is, cat, b);
+ is->files[cat].fc_list[j] = 0;
+ }
}
void isc_pp_close (ISAMC_PP pp)
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: merge.c,v $
- * Revision 1.2 1996-11-01 13:36:46 adam
+ * Revision 1.3 1996-11-04 14:08:59 adam
+ * Optimized free block usage.
+ *
+ * Revision 1.2 1996/11/01 13:36:46 adam
* New element, max_blocks_mem, that control how many blocks of max size
* to store in memory during isc_merge.
- * Function isc_merge now ignoreds delete/update of identical keys and
+ * Function isc_merge now ignores delete/update of identical keys and
* the proper blocks are then non-dirty and not written in flush_blocks.
*
* Revision 1.1 1996/11/01 08:59:15 adam
i_item_ptr = i_item;
i_more = (*data->read_item)(data->clientData, &i_item_ptr,
&i_mode);
- /* it next input item the same as current except
+ /* is next input item the same as current except
for the delete flag? */
cmp = (*is->method->compare_item)(i_item, f_item);
if (!cmp && i_mode)
&r_out_ptr, &r_item);
new_offset = r_out_ptr - r_buf;
- if (border >= r_offset && border < new_offset)
+ if (border < new_offset && border >= r_offset)
{
if (is->method->debug > 2)
logf (LOG_LOG, "isc: border %d %d", ptr, border);