chess_index
chess_index · Data types for indexing chess positions.
Overview
| ID | Extension | Package | Version | Category | License | Language |
|---|---|---|---|---|---|---|
| 100526 | chess_index | chess_index | 0.0.1 | TYPE | MIT | C |
Usage
Sources:
chess_index defines compact PostgreSQL types for chess positions, pieces, and squares, with comparison and hash/B-tree operator classes intended to make positions indexable. The project is an unfinished pre-release implementation; use it only for research with expendable data, not for correctness-sensitive chess storage or indexes.
Core Workflow
The board input is a shortened four-field FEN value: piece placement, active side, castling rights, and en-passant target. Halfmove and fullmove counters are not part of the stored representation.
The SQL declares hash and B-tree operator classes for board, square, and pindex, so indexes can be created syntactically:
Do not rely on such an index until the implementation defects below are fixed and verified.
Important Objects
board: compact position value withpcount(board),side(board), andpieces(board, side)accessors.side,piece,pindex,square, andpiecesquare: compact chess component types.cfile,rank, anddiagonal: square-derived coordinate types.pretty(board, boolean, boolean): format a position as text or Unicode pieces.invert(board): swap piece case and active side in the textual representation.- Hash and B-tree operators/operator classes support equality and ordering for selected types.
Correctness and Packaging Caveats
At the reviewed commit, the Makefile names sql/chess_index--0.0.1.sql, but the repository contains only sql/chess_index.sql; an unpatched source install can therefore fail before CREATE EXTENSION is usable.
More importantly, the C comparator uses the size of a pointer rather than the size of the stored board structure when comparing values. Equality and ordering can ignore relevant position bytes, while hashing uses a different representation. This can produce wrong comparisons and unsafe index semantics. The code also keeps the original FEN in a fixed 100-byte array and has a boundary check that permits an input at the array’s nominal limit. Treat both parsing and indexing as untrusted experimental code, keep backups, and validate any locally patched build with adversarial FEN values before use.