From: Adam Dickmeiss Date: Tue, 12 Dec 2006 13:46:41 +0000 (+0000) Subject: Added functions isamb_set_int_count, isamb-set_cache_size, X-Git-Tag: ZEBRA.2.0.8~35 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=baeef217d2eeb54b96daabeeca6792c33708aaad;p=idzebra-moved-to-github.git Added functions isamb_set_int_count, isamb-set_cache_size, isamb_get_int_splits, isamb_get_leaf_splits, iasmb_set_int_count. --- diff --git a/include/idzebra/isamb.h b/include/idzebra/isamb.h index 60884b7..183e13b 100644 --- a/include/idzebra/isamb.h +++ b/include/idzebra/isamb.h @@ -1,4 +1,4 @@ -/* $Id: isamb.h,v 1.7 2006-08-14 10:40:14 adam Exp $ +/* $Id: isamb.h,v 1.8 2006-12-12 13:46:42 adam Exp $ Copyright (C) 1995-2006 Index Data ApS @@ -72,6 +72,18 @@ int isamb_block_info(ISAMB isamb, int cat); YAZ_EXPORT void isamb_dump(ISAMB b, ISAM_P pos, void (*pr)(const char *str)); +YAZ_EXPORT +zint isamb_get_int_splits(ISAMB b); + +YAZ_EXPORT +zint isamb_get_leaf_splits(ISAMB b); + +YAZ_EXPORT +void isamb_set_int_count(ISAMB b, int v); + +YAZ_EXPORT +void isamb_set_cache_size(ISAMB b, int sz); + YAZ_END_CDECL #endif diff --git a/isamb/isamb.c b/isamb/isamb.c index 61d7036..3e85ee1 100644 --- a/isamb/isamb.c +++ b/isamb/isamb.c @@ -1,4 +1,4 @@ -/* $Id: isamb.c,v 1.87 2006-12-07 19:23:56 adam Exp $ +/* $Id: isamb.c,v 1.88 2006-12-12 13:46:41 adam Exp $ Copyright (C) 1995-2006 Index Data ApS @@ -100,6 +100,10 @@ struct ISAMB_s { zint returned_numbers; zint skipped_nodes[ISAMB_MAX_LEVEL]; /* [0]=skipped leaves, 1 = higher etc */ zint accessed_nodes[ISAMB_MAX_LEVEL]; /* nodes we did not skip */ + zint number_of_int_splits; + zint number_of_leaf_splits; + int enable_int_count; /* whether we count nodes (or not) */ + int cache_size; /* size of blocks to cache (if cache=1) */ }; struct ISAMB_block { @@ -180,6 +184,17 @@ static void decode_ptr(const char **src, zint *pos) } #endif + +void isamb_set_int_count(ISAMB b, int v) +{ + b->enable_int_count = v; +} + +void isamb_set_cache_size(ISAMB b, int v) +{ + b->cache_size = v; +} + ISAMB isamb_open(BFiles bfs, const char *name, int writeflag, ISAMC_M *method, int cache) { @@ -195,6 +210,11 @@ ISAMB isamb_open(BFiles bfs, const char *name, int writeflag, ISAMC_M *method, isamb->cache = cache; isamb->skipped_numbers = 0; isamb->returned_numbers = 0; + isamb->number_of_int_splits = 0; + isamb->number_of_leaf_splits = 0; + isamb->enable_int_count = 1; + isamb->cache_size = 40; + for (i = 0; iskipped_nodes[i] = isamb->accessed_nodes[i] = 0; @@ -357,9 +377,8 @@ static int cache_block (ISAMB b, ISAM_P pos, unsigned char *userbuf, int wr) return 1; } } - if (no >= 40) + if (no >= b->cache_size) { - assert (no == 40); assert (ce_last && *ce_last); ce_this = *ce_last; *ce_last = 0; /* remove the last entry from list */ @@ -776,6 +795,8 @@ int insert_int (ISAMB b, struct ISAMB_block *p, void *lookahead_item, const char *half; src = dst_buf; endp = dst; + + b->number_of_int_splits++; p->dirty = 1; close_block(b, sub_p2); @@ -783,10 +804,13 @@ int insert_int (ISAMB b, struct ISAMB_block *p, void *lookahead_item, half = src + b->file[p->cat].head.block_size/2; decode_ptr(&src, &pos); - /* read sub block so we can get no_items for it */ - sub_p3 = open_block(b, pos); - no_items_first_half += sub_p3->no_items; - close_block(b, sub_p3); + if (b->enable_int_count) + { + /* read sub block so we can get no_items for it */ + sub_p3 = open_block(b, pos); + no_items_first_half += sub_p3->no_items; + close_block(b, sub_p3); + } while (src <= half) { @@ -801,10 +825,13 @@ int insert_int (ISAMB b, struct ISAMB_block *p, void *lookahead_item, #endif decode_ptr(&src, &pos); - /* read sub block so we can get no_items for it */ - sub_p3 = open_block(b, pos); - no_items_first_half += sub_p3->no_items; - close_block(b, sub_p3); + if (b->enable_int_count) + { + /* read sub block so we can get no_items for it */ + sub_p3 = open_block(b, pos); + no_items_first_half += sub_p3->no_items; + close_block(b, sub_p3); + } } /* p is first half */ p_new_size = src - dst_buf; @@ -1092,6 +1119,8 @@ int insert_leaf (ISAMB b, struct ISAMB_block **sp1, void *lookahead_item, (*b->method->codec.reset)(c2); + b->number_of_leaf_splits++; + first_dst = (*sp2)->bytes; (*b->method->codec.encode)(c2, &first_dst, &cut_item); @@ -1969,6 +1998,17 @@ again: } return 1; } + +zint isamb_get_int_splits(ISAMB b) +{ + return b->number_of_int_splits; +} + +zint isamb_get_leaf_splits(ISAMB b) +{ + return b->number_of_leaf_splits; +} + /* * Local variables: * c-basic-offset: 4