#slice #index #array

nightly index_many

A proof of concept for indexing an slice at multiple locations at once

12 releases (5 breaking)

0.6.1 Sep 7, 2021
0.6.0 Sep 7, 2021
0.5.2 Aug 12, 2021
0.4.1 Jun 15, 2021
0.1.2 Mar 18, 2021

#2037 in Data structures

Download history 345/week @ 2023-12-06 211/week @ 2023-12-13 137/week @ 2023-12-20 165/week @ 2023-12-27 296/week @ 2024-01-03 513/week @ 2024-01-10 371/week @ 2024-01-17 580/week @ 2024-01-24 859/week @ 2024-01-31 822/week @ 2024-02-07 329/week @ 2024-02-14 372/week @ 2024-02-21 343/week @ 2024-02-28 513/week @ 2024-03-06 494/week @ 2024-03-13 767/week @ 2024-03-20

2,143 downloads per month

MIT/Apache

105KB
2K SLoC

Proof of concept functions for (mutably) accessing a slice at multiple positions at once via an array of indices.

Provided APIs

This crate implements multiple APIs:

  • "simple": accepts a sorted array [usize; N] of indices.
  • "simple_result": accepts a sorted array [usize; N] of indices, but with an Result based API.
  • "slice_index": accepts a sorted array [I; N] of indices, where I: SliceIndex<[T]>.
  • "generic": uses a generic I: Indices<N> that allows for more flexibility.

Example

use index_many::generic::index_many_mut;

let mut v = vec![1, 2, 3, 4, 5];
let [a, b, c] = index_many_mut(&mut v, [0, 2, 4]);
*a += 10;
*b += 100;
*c += 1000;
assert_eq!(v, vec![11, 2, 103, 4, 1005]);

Generated Assembly

The docs contain example functions with their x86_64 assembly codegen. See the crate::_doc_assembly module.

No runtime deps