Struct advent_of_code_2021::day_25::Grid[−][src]

struct Grid {
    cells: Vec<Cell>,
    width: usize,
    height: usize,
    active_right: HashSet<(usize, usize)>,
    active_down: HashSet<(usize, usize)>,
}
Expand description

Represent a grid as a vector of cells, with a width and height to enable quick lookups from x/y co-ordinates, and to help with wrapping around logic. Also keep HashSets of the RIGHT and DOWN cells that may be able to move, to limit the cells we need to check when iterating the grid

Fields

cells: Vec<Cell>

The cells of the grid as a single list

width: usize

Cache the grid width

height: usize

Cache teh grid height

active_right: HashSet<(usize, usize)>

The cells with a RIGHTwards moving sea cucumber that may be able to move

active_down: HashSet<(usize, usize)>

The cells with a DOWNwards moving sea cucumber that may be able to move

Implementations

Get the current value of a given cell co-ordinate, or None if it is out of bounds for the grid

Convert x, y co-ordinates to an index in the underlying list of cells.

Swap the values of two cells - used when sea cucumbers move

We are overly optimistic when building the active sets. Given the co-ordinates of a sea cucumber and it’s direction of travel, check if it’s next cell is actually available to move into.

Do a full iteration of the grid in-place, moving RIGHTs that can move rightwards, then DOWNs that can move downwards. Calculate the new active set as all the cucumbers that moved, plus any that can move into the vacated space.

Trait Implementations

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Parse the puzzle input as a grid, building the initial active sets to include all the sea cucumbers of the relevant type

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.