Skip to content

proposal: two-dimensional array slices #28

Description

@hades

Proposal: support for Array2d slices.

Array2d is a very useful type for two-dimensional data storage. I've used
it extensively while solving Advent of Code and Everybody Codes puzzles[1].

However, one feature that I wish the crate provided was array "views", i.e.
smaller rectangular subarrays that I could borrow into a function without
copying an entire (large) array.

This would function similarly to a (one-dimensional) Rust slice &[T].

I propose an API similar to Array2D itself, so that in many cases this new
type can be used as a drop-in replacement. In particular, the following
functions will be supported:

  • num_rows, num_columns, num_elements, row_len, column_len
  • get
  • row_iter, column_iter
  • rows_iter, columns_iter
  • index
  • eq, ne

For mutable slices also:

  • get_mut
  • set
  • index_mut

Additionally, a copy of an array can be constructed with an as_array method.

In [2] I've cobbled together a very simple implementation of an ArrayView for
reference on how such a type could be useful.

[1] https://github.com/hades/everybodycodes
[2] https://github.com/hades/everybodycodes/blob/master/src/quest10.rs#L35

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions