Header And Logo

PostgreSQL
| The world's most advanced open source database.

Functions

regc_cvec.c File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

static struct cvecnewcvec (int nchrs, int nranges)
static struct cvecclearcvec (struct cvec *cv)
static void addchr (struct cvec *cv, chr c)
static void addrange (struct cvec *cv, chr from, chr to)
static struct cvecgetcvec (struct vars *v, int nchrs, int nranges)
static void freecvec (struct cvec *cv)

Function Documentation

static void addchr ( struct cvec cv,
chr  c 
) [static]

Definition at line 77 of file regc_cvec.c.

References assert, cvec::chrs, cvec::chrspace, and cvec::nchrs.

Referenced by allcases(), cclass(), eclass(), and range().

{
    assert(cv->nchrs < cv->chrspace);
    cv->chrs[cv->nchrs++] = (chr) c;
}

static void addrange ( struct cvec cv,
chr  from,
chr  to 
) [static]

Definition at line 88 of file regc_cvec.c.

References assert, cvec::nranges, cvec::ranges, and cvec::rangespace.

Referenced by cclass(), and range().

{
    assert(cv->nranges < cv->rangespace);
    cv->ranges[cv->nranges * 2] = (chr) from;
    cv->ranges[cv->nranges * 2 + 1] = (chr) to;
    cv->nranges++;
}

static struct cvec* clearcvec ( struct cvec cv  )  [static, read]

Definition at line 65 of file regc_cvec.c.

References assert, cvec::nchrs, cvec::nranges, and NULL.

Referenced by getcvec(), and newcvec().

{
    assert(cv != NULL);
    cv->nchrs = 0;
    cv->nranges = 0;
    return cv;
}

static void freecvec ( struct cvec cv  )  [static]

Definition at line 133 of file regc_cvec.c.

References FREE.

Referenced by getcvec().

{
    FREE(cv);
}

static struct cvec* getcvec ( struct vars v,
int  nchrs,
int  nranges 
) [static, read]

Definition at line 110 of file regc_cvec.c.

References clearcvec(), vars::cv, ERR, freecvec(), newcvec(), NULL, and REG_ESPACE.

Referenced by allcases(), cclass(), eclass(), and range().

{
    /* recycle existing transient cvec if large enough */
    if (v->cv != NULL && nchrs <= v->cv->chrspace &&
        nranges <= v->cv->rangespace)
        return clearcvec(v->cv);

    /* nope, make a new one */
    if (v->cv != NULL)
        freecvec(v->cv);
    v->cv = newcvec(nchrs, nranges);
    if (v->cv == NULL)
        ERR(REG_ESPACE);

    return v->cv;
}

static struct cvec* newcvec ( int  nchrs,
int  nranges 
) [static, read]

Definition at line 44 of file regc_cvec.c.

References cvec::chrs, cvec::chrspace, clearcvec(), MALLOC, NULL, cvec::ranges, and cvec::rangespace.

Referenced by getcvec().

{
    size_t      nc = (size_t) nchrs + (size_t) nranges * 2;
    size_t      n = sizeof(struct cvec) + nc * sizeof(chr);
    struct cvec *cv = (struct cvec *) MALLOC(n);

    if (cv == NULL)
        return NULL;
    cv->chrspace = nchrs;
    cv->chrs = (chr *) (((char *) cv) + sizeof(struct cvec));
    cv->ranges = cv->chrs + nchrs;
    cv->rangespace = nranges;
    return clearcvec(cv);
}