Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SparseCostMatrix #348

Merged
merged 19 commits into from
Apr 19, 2021
Merged

SparseCostMatrix #348

merged 19 commits into from
Apr 19, 2021

Conversation

khoover
Copy link
Contributor

@khoover khoover commented Apr 14, 2021

Adds a basic implementation of a sparse cost matrix. Also adds iter and iter_mut to LocalCostMatrix.

Built on top of #347, should probably wait for that to merge and then I can rebase.

…ize array internally

Instead of using Vec<u8>, LocalCostMatrix now holds a [u8; 2500] directly. Also replaced the
Into<Vec<u8>> for LocalCostMatrix with From<LocalCostMatrix> for Vec<u8>, to be idiomatic.
LocalCostMatrix's can now be indexed by (u8, u8) pairs.
Before, we just relied on the bounds checking the index that pos_as_idx spits out, but that allows
invalid coordinates like (0, 201) to be passed in. This fixes that. As a result of the bounds
checking from the asserts, we can skip the checking that goes on in []::index, and just use the
unchecked versions instead.
…ses unchecked internally

With the (u8, u8) indexing impl, we can rewrite get and set in terms of them. And in the indexing
impl, because we check that x and y are in bounds, we're guaranteed that the index from pos_as_idx
will be in bounds as well, so we can just use the unchecked accessors instead.
…trix::{iter, iter_mut}

SparseCostMatrix is the sparse counterpart to the LocalCostMatrix. Also added methods for generating
iterators over both the sparse and dense versions.
Can now merge the two cost matrix types into each other; forms the basis for possible layered cost
matrix behaviour, builder patterns, etc.
…es back instead of u8

Some users might only care about a few values, why deref before it's needed? They can always chain
.copied() after if needed.

BREAKING CHANGE: .iter() returns impl Iterator<Item = ((u8, u8), &u8)> instead of impl Iterator<Item
= ((u8, u8), u8)> for Local and SparseCostMatrix.
@khoover khoover marked this pull request as ready for review April 18, 2021 04:58
…n::y to u8

Now that the position change is merged, these casts are unnecessary.
src/local/cost_matrix.rs Show resolved Hide resolved
src/local/cost_matrix.rs Show resolved Hide resolved
@Azaril Azaril merged commit 85b6443 into rustyscreeps:bindgen Apr 19, 2021
@khoover khoover deleted the sparse_cost_matrix branch November 9, 2024 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants