Internally, GIN consists of a B-tree index constructed over keys, where each key is an element of the indexed value (element of array, for example) and where each tuple in a leaf page is either a pointer to a B-tree over heap pointers (PT, posting tree), or a list of heap pointers (PL, posting list) if the tuple is small enough.
There are four methods that an index operator class for GIN must provide (prototypes are in pseudocode):
Compares keys (not indexed values!) and returns an integer less than zero, zero, or greater than zero, indicating whether the first key is less than, equal to, or greater than the second.
Returns an array of keys of value to be indexed, nkeys should contain the number of returned keys.
Returns an array of keys of the query to be executed. n contains the strategy number of the operation (see Section 33.14.2, “Index Method Strategies”). Depending on n, query may be different type.
Returns TRUE if the indexed value satisfies the query qualifier with strategy n (or may satisfy in case of RECHECK mark in operator class). Each element of the check array is TRUE if the indexed value has a corresponding key in the query: if (check[i] == TRUE) the i-th key of the query is present in the indexed value.