I have looked at the cube datataype in the contrib but I''m not sure 
that I'm on the right way

I have found these functions:

-- support routines for indexing

CREATE FUNCTION cube_union(cube, cube) RETURNS cube
        AS 'MODULE_PATHNAME' LANGUAGE 'c' with (isstrict);

CREATE FUNCTION cube_inter(cube, cube) RETURNS cube
        AS 'MODULE_PATHNAME' LANGUAGE 'c' with (isstrict);

CREATE FUNCTION cube_size(cube) RETURNS float4
        AS 'MODULE_PATHNAME' LANGUAGE 'c' with (isstrict);


and there are the same functions written in c in the file

/* cube_union */
NDBOX *
cube_union(NDBOX * box_a, NDBOX * box_b)
{
        int                        i;
        NDBOX           *result;
        NDBOX           *a = swap_corners(box_a);
        NDBOX           *b = swap_corners(box_b);

        if (a->dim >= b->dim)
        {
                result = palloc(a->size);
                result->size = a->size;
                result->dim = a->dim;
        }
        else
        {
                result = palloc(b->size);
                result->size = b->size;
                result->dim = b->dim;
        }

        /* swap the box pointers if needed */
        if (a->dim < b->dim)
        {
                NDBOX           *tmp = b;

                b = a;
                a = tmp;
        }

        /*
         * use the potentially smaller of the two boxes (b) to fill in the
         * result, padding absent dimensions with zeroes
         */
        for (i = 0; i < b->dim; i++)
        {
                result->x[i] = b->x[i];
                result->x[i + a->dim] = b->x[i + b->dim];
        }
        for (i = b->dim; i < a->dim; i++)
        {
                result->x[i] = 0;
                result->x[i + a->dim] = 0;
        }

        /* compute the union */
        for (i = 0; i < a->dim; i++)
                result->x[i] = min(a->x[i], result->x[i]);
        for (i = a->dim; i < a->dim * 2; i++)
                result->x[i] = max(a->x[i], result->x[i]);

        pfree(a);
        pfree(b);

        return (result);
}


Now my question is:

Is it easy to write an indexed datatype without touching the, let's say 
internal code, of postgresql
Are there some problems when writing indexed datatypes?

Any information and suggestaions welcome

Ewald





Wed, 22 May 2002 15:53:07 +0200
Ewald Geschwinde <webmaster@geschwinde.net>
index a datatype