From 16153aaaa1fcb0881ff7e3056bd9c991fcf57c29 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 4 Nov 1996 14:08:55 +0000 Subject: [PATCH] Optimized free block usage. --- isamc/isamc-p.h | 8 +++++- isamc/isamc.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++----- isamc/merge.c | 11 +++++--- 3 files changed, 87 insertions(+), 12 deletions(-) diff --git a/isamc/isamc-p.h b/isamc/isamc-p.h index 4abbc72..7f4601c 100644 --- a/isamc/isamc-p.h +++ b/isamc/isamc-p.h @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: isamc-p.h,v $ - * Revision 1.2 1996-11-01 08:59:13 adam + * Revision 1.3 1996-11-04 14:08:55 adam + * Optimized free block usage. + * + * Revision 1.2 1996/11/01 08:59:13 adam * First version of isc_merge that supports update/delete. * * Revision 1.1 1996/10/29 13:40:47 adam @@ -31,6 +34,9 @@ typedef struct ISAMC_file_s { int no_allocated; int no_released; int no_remap; + + int fc_max; + int *fc_list; } *ISAMC_file; struct ISAMC_s { diff --git a/isamc/isamc.c b/isamc/isamc.c index 6401c63..656cae0 100644 --- a/isamc/isamc.c +++ b/isamc/isamc.c @@ -4,10 +4,13 @@ * 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 @@ -34,6 +37,9 @@ #include #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[] = { @@ -64,7 +70,7 @@ ISAMC isc_open (const char *name, int writeflag, ISAMC_M method) { ISAMC is; ISAMC_filecat filecat; - int i; + int i, j; int max_buf_size = 0; is = xmalloc (sizeof(*is)); @@ -124,6 +130,8 @@ ISAMC isc_open (const char *name, int writeflag, ISAMC_M method) is->files[i].no_allocated = 0; is->files[i].no_released = 0; is->files[i].no_remap = 0; + + init_fc (is, i); } return is; } @@ -136,6 +144,7 @@ int isc_close (ISAMC is) logf (LOG_LOG, "isc: writes reads skipped alloc released remap"); for (i = 0; ino_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), @@ -148,6 +157,7 @@ int isc_close (ISAMC is) 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); @@ -184,7 +194,7 @@ int isc_write_dblock (ISAMC is, int cat, int pos, char *src, 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)]; @@ -198,12 +208,31 @@ int isc_alloc_block (ISAMC is, int cat) } 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)]; @@ -212,8 +241,45 @@ void isc_release_block (ISAMC is, int cat, int pos) 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; jfiles[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) diff --git a/isamc/merge.c b/isamc/merge.c index 12334c6..c2b853a 100644 --- a/isamc/merge.c +++ b/isamc/merge.c @@ -4,10 +4,13 @@ * 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 @@ -173,7 +176,7 @@ ISAMC_P isc_merge (ISAMC is, ISAMC_P ipos, ISAMC_I data) 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) @@ -246,7 +249,7 @@ ISAMC_P isc_merge (ISAMC is, ISAMC_P ipos, ISAMC_I data) &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); -- 1.7.10.4