index a datatype - Mailing list pgsql-hackers

From Ewald Geschwinde
Subject index a datatype
Date
Msg-id 3CEBA2C3.3060408@geschwinde.net
Whole thread Raw
List pgsql-hackers
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
dimensionswith 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






pgsql-hackers by date:

Previous
From: "D'Arcy J.M. Cain"
Date:
Subject: Edge case problem with pg_dump
Next
From: Lee Kindness
Date:
Subject: Re: Redhat 7.3 time manipulation bug