Annotation of researchv10no/cmd/btree/seek.c, revision 1.1

1.1     ! root        1: #include "cbt.h"
        !             2: #include "pr.h"
        !             3: 
        !             4: extern bfile   *curbf;
        !             5: 
        !             6: xscan(b, key, x) hdr *b; mbuf key; private *x;
        !             7: {      int ncom, i, n, val;
        !             8:        char a, *p;
        !             9:        dkey *d;
        !            10: 
        !            11:        n = i = ncom = 0;
        !            12:        val = NOTFOUND;
        !            13:        p = (char *)(b+1);
        !            14:        d = (dkey *)p;
        !            15:        for(; i < b->kcnt; i++, p += d->dlen) {
        !            16:                d = (dkey *)p;
        !            17:                if(ncom < d->dcom)
        !            18:                        goto onward;
        !            19:                if(ncom > d->dcom) {
        !            20:                        if(x != NULL) {
        !            21:                                x->match = val;
        !            22:                                x->ncom = d->dcom;
        !            23:                                x->ocom = ncom;
        !            24:                                x->d = d;
        !            25:                        }
        !            26:                        return(i);
        !            27:                }
        !            28:                for(n = ncom; ncom < key.mlen && ncom - n < d->dlen - DKEYSZ; ncom++) {
        !            29:                        if((a = d->dkey[ncom - n]) == key.mdata[ncom])
        !            30:                                continue;
        !            31:                        if(a < key.mdata[ncom])
        !            32:                                goto onward;
        !            33:                        goto done;
        !            34:                }
        !            35:                if(ncom == key.mlen) {
        !            36:                        if(ncom == d->dlen - DKEYSZ + d->dcom)
        !            37:                                val = FOUND;
        !            38:                        goto done;
        !            39:                }
        !            40:        onward: ;
        !            41:        }
        !            42: /* infinity: */
        !            43:        if(x != NULL) {
        !            44:                x->match = EOF;
        !            45:                x->ncom = ncom;
        !            46:                x->ocom = n;
        !            47:                x->d = d;
        !            48:        }
        !            49:        return(i);
        !            50: done:
        !            51:        if(x != NULL) {
        !            52:                x->match = val;
        !            53:                x->ncom = ncom;
        !            54:                x->ocom = n;
        !            55:                x->d = d;
        !            56:        }
        !            57:        return(i);
        !            58: }
        !            59: 
        !            60: desce(bf, key, x) bfile *bf; mbuf key; private *x;
        !            61: {      int i, j;
        !            62:        ndaddr u;
        !            63:        for(i = bf->height; i > 0; i--) {
        !            64:                j = xscan(bf->path[i], key, (private *)NULL);
        !            65:                u = *ndadr(bf->path[i], j);
        !            66:                if(bf->loc[i-1] != u)
        !            67:                        if(getincore(i - 1, u) == EOF)
        !            68:                                return(EOF);
        !            69:        }
        !            70:        i = xscan(bf->path[0], key, x);
        !            71:        return(i);
        !            72: }
        !            73: 
        !            74: step(level)
        !            75: /* ran off the end of node at lev-1 */
        !            76: {      hdr *b;
        !            77:        int n, i;
        !            78:        ndaddr u;
        !            79:        if(level > curbf->height)
        !            80:                return(EOF);
        !            81:        n = curbf->loc[level - 1];
        !            82:        b = curbf->path[level];
        !            83:        for(i = 0; i <= b->kcnt; i++)
        !            84:                if(*ndadr(b, i) == n)
        !            85:                        break;
        !            86:        if(i >= b->kcnt)
        !            87:                return(step(level + 1));
        !            88:        n = level;
        !            89:        i++;
        !            90:        do {
        !            91:                u = *ndadr(curbf->path[n], i);
        !            92:                if(curbf->loc[n-1] != u)
        !            93:                        if(getincore(n - 1, u) == EOF)
        !            94:                                return(EOF);
        !            95:                i = 0;
        !            96:        } while(--n > 0);
        !            97:        return(0);
        !            98: }
        !            99: 
        !           100: advance()
        !           101: {      dkey *dold, *dnew;
        !           102:        struct rdptr *y = &curbf->rdptr;
        !           103:        curbf->advnc = 0;
        !           104:        dold = y->rptr;
        !           105:        if(++y->rnum < curbf->path[0]->kcnt) {
        !           106:                dnew = (dkey *)((char *)dold + dold->dlen);
        !           107:                if(dold->dcom < dnew->dcom)
        !           108:                        mvgbt(y->rpref + dold->dcom, dold->dkey, dnew->dcom - dold->dcom);
        !           109:                y->rptr = dnew;
        !           110:                return(0);
        !           111:        }
        !           112:        errno = 0;
        !           113:        if(step(1) == EOF) {
        !           114:                if(errno)
        !           115:                        return(EOF);
        !           116:                y->rnum = curbf->path[0]->kcnt + 1;
        !           117:                y->rptr  = NULL;
        !           118:        }
        !           119:        else {
        !           120:                y->rnum = 0;
        !           121:                y->rptr = (dkey *)(curbf->path[0] + 1);
        !           122:        }
        !           123:        return(0);
        !           124: }
        !           125: static struct D { struct D *a; char *b;} VER = {&VER,"\n82/10/9:seek.c\n"};
        !           126: /*1100011110101111*/
        !           127: /*1101111110111111*/

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.