X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=isam%2Fisam.c;h=c84e42e3db39f65cf3ff85de233b2edadd157a41;hb=0e643dd5ce707178394c0e9d82ec2eeb80f330ec;hp=3ae755c817fbea961e2c795398ea542b771d282d;hpb=a5545de18b5d3762a1f29569a4b10ca5017506db;p=idzebra-moved-to-github.git diff --git a/isam/isam.c b/isam/isam.c index 3ae755c..c84e42e 100644 --- a/isam/isam.c +++ b/isam/isam.c @@ -4,7 +4,13 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: isam.c,v $ - * Revision 1.5 1994-09-27 20:03:50 quinn + * Revision 1.7 1994-09-28 11:56:25 quinn + * Added sort of input to is_merge + * + * Revision 1.6 1994/09/28 11:29:33 quinn + * Added cmp parameter. + * + * Revision 1.5 1994/09/27 20:03:50 quinn * Seems relatively bug-free. * * Revision 1.4 1994/09/26 17:11:29 quinn @@ -30,6 +36,8 @@ #include "rootblk.h" #include "keyops.h" +static int (*extcmp)(const void *p1, const void *p2); + static int splitargs(const char *s, char *bf[], int max) { int ct = 0; @@ -56,7 +64,8 @@ static int splitargs(const char *s, char *bf[], int max) * Open isam file. * Process resources. */ -ISAM is_open(const char *name, int writeflag) +ISAM is_open(const char *name, int (*cmp)(const void *p1, const void *p2), + int writeflag) { ISAM new; char *nm, *r, *pp[IS_MAX_BLOCKTYPES+1], m[2]; @@ -217,7 +226,7 @@ ISAM is_open(const char *name, int writeflag) new->types[i].nice_keys_block = 1; } - new->cmp = is_default_cmp; + new->cmp = cmp ? cmp : is_default_cmp; return new; } @@ -262,7 +271,16 @@ static ISAM_P is_address(int type, int pos) return r; } -ISAM_P is_merge(ISAM is, ISAM_P pos, int num, const char *data) +int sort_input(const void *p1, const void *p2) +{ + int rs; + + if ((rs = (*extcmp)(((char *)p1) + 1, ((char *)p2) + 1))) + return rs; + return *((char *)p1) - *((char*)p2); +} + +ISAM_P is_merge(ISAM is, ISAM_P pos, int num, char *data) { is_mtable tab; int res; @@ -270,6 +288,8 @@ ISAM_P is_merge(ISAM is, ISAM_P pos, int num, const char *data) int oldnum, oldtype, i; char operation, *record; + extcmp = is->cmp; + qsort(data, num, is_keysize(is) + 1, sort_input); is_m_establish_tab(is, &tab, pos); /* TODO: do something to aquire oldnum at this point */ if (pos)