Next / Previous / Contents / Shipman's homepage

4.2. Data structures

Here is an entity-relationship diagram illustrating the relationships between puzzles, cells, and slots.

We represent the puzzle internally using instances of four corresponding classes.

To describe the geometry of the puzzle, we will use row and column indexes. An instance of helper class Coord represents one location in the puzzle as a row index and a column index, both counting from zero. The upper left corner of the puzzle is row 0, column 0.

For various reasons, we'll define a complete ordering relation on Coord instances. This ordering is the usual scan order for European languages: starting in the upper left corner, across the first row, then left to right in the second row, and so on.

We also define a complete ordering for Slot instances. Slots are ordered according to the row and column coordinates of their first cell, with their orientation as a secondary key: if two slots share the same first cell, the horizontal slot is considered before the vertical slot. We define numbers for the two orientations: 0 for horizontal, 1 for vertical.