The PostgreSQL source distribution includes
several examples of index operator classes for SP-GiST,
as described in Table 62.1, “Built-in SP-GiST Operator Classes”. Look
into src/backend/access/spgist/
and src/backend/utils/adt/ to see the code.