home *** CD-ROM | disk | FTP | other *** search
- /*
- * low level fractal search routine
- *
- * This program is the CONFIDENTIAL and PROPRIETARY property
- * of FairCom(R) Corporation. Any unauthorized use, reproduction or
- * transfer of this program is strictly prohibited.
- *
- * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989 FairCom Corporation
- * (Subject to limited distribution and
- * restricted disclosure only.)
- * *** ALL RIGHTS RESERVED ***
- *
- * 4006 West Broadway
- * Columbia, MO 65203
- *
- *
- * c-tree(R) Version 4.3
- * Release C
- * February 7, 1989 17:30
- *
- */
-
- #include "ctstdr.h" /* standard i/o header */
- #include "ctoptn.h" /* c-tree configuration options */
- #include "cterrc.h" /* c-tree error codes */
- #include "ctstrc.h" /* c-tree data structures */
- #include "ctgvar.h" /* c-tree global variables */
-
- #define SCALE 10000
- #define FAC_SCALE 100
-
- /*
- FRCKEY returns the 4-byte record position associated with the key value
- located approximately fractal/100 of the way through the file. idxval
- points to the output key buffer.
- */
-
- POINTER FRCKEY(keyno,idxval,fractal)
- COUNT keyno;
- TEXT *idxval;
- COUNT fractal;
- {
- FAST CTFILE *knum;
- FAST TREEBUFF *buffer;
- COUNT bias,nsize,sfractal,npoint;
- LONG node;
-
- CTFILE *tstfnm();
- LONG gtroot(),nodpnt();
- POINTER drnpnt();
- TREEBUFF *getnod();
- COUNT uerr();
- TEXT *valpnt();
-
- if ((knum = tstfnm(keyno)) == NULL)
- return(uerr_cod);
- else if (fractal < 0 || fractal > (SCALE / FAC_SCALE))
- return(uerr(KFRC_ERR));
-
- if ((node = gtroot(knum)) == DRNZERO)
- return(DRNZERO);
-
- sfractal = fractal;
- bias = 0;
- fractal *= FAC_SCALE;
- while (node) {
- if ((buffer = getnod(node,knum)) == NULL)
- return(DRNZERO);
- nsize = SCALE;
- if (buffer->nkv)
- nsize = SCALE / buffer->nkv;
- npoint = (fractal + nsize - 1) / nsize;
- if (npoint == buffer->nkv + 1)
- npoint--;
- if (npoint == 0) {
- npoint = 1;
- fractal = 0;
- } else {
- if (npoint > buffer->nkv) terr(251);
- bias = fractal - ((npoint - 1) * nsize);
- fractal = bias * buffer->nkv;
- if (fractal > SCALE) fractal = SCALE;
- }
- if (buffer->leaf == LEAF)
- break;
- node = nodpnt(buffer,npoint);
- }
-
- if (!node)
- terr(250);
-
- if (buffer->nkv) {
- nsize = SCALE / buffer->nkv;
- npoint = (fractal + nsize - 1) / nsize;
- if (npoint == 0)
- npoint = 1;
- else if (npoint == buffer->nkv + 1)
- npoint--;
- if (npoint > buffer->nkv) terr(252);
- cpybuf(idxval,valpnt(buffer,npoint),knum->length);
- return(drnpnt(buffer,npoint));
- } else {
- while (node = buffer->sucesr) {
- if ((buffer = getnod(node,knum)) == NULL)
- return(DRNZERO);
- if (buffer->nkv) {
- cpybuf(idxval,valpnt(buffer,1),knum->length);
- return(drnpnt(buffer,1));
- }
- }
- setnul(idxval);
- return(DRNZERO);
- }
- }
-
- /* end of ctfrac.c */
-