Content-Length: 321712 | pFad | http://github.com/psqlpy-python/rust-postgres-array/commit/d263375fb678812f06c4368ab9fbd3be0e1db867

5E Document index impl and fix indexing · psqlpy-python/rust-postgres-array@d263375 · GitHub
Skip to content

Commit d263375

Browse files
committed
Document index impl and fix indexing
1 parent 4a6f847 commit d263375

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/array.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,10 @@ impl<T> Array<T> {
8686
self.dims
8787
.iter()
8888
.zip(indices.iter().cloned())
89+
.rev()
8990
.fold((0, 1), |(acc, stride), (dim, idx)| {
9091
let shifted = dim.shift(idx);
91-
(acc * stride + shifted, dim.len)
92+
(acc + shifted * stride, dim.len * stride)
9293
})
9394
.0
9495
}
@@ -160,6 +161,31 @@ tuple_impl!(a: isize, b: isize, c: isize, d: isize, e: isize, f: isize, g: isize
160161
impl<T, I: ArrayIndex> Index<I> for Array<T> {
161162
type Output = T;
162163

164+
//github.com/ Indexes into the `Array`, retrieving a reference to the contained
165+
//github.com/ value.
166+
//github.com/
167+
//github.com/ Since `Array`s can be multi-dimensional, the `Index` trait is
168+
//github.com/ implemented for a variety of index types. In the most generic case, a
169+
//github.com/ `&[isize]` can be used. In addition, a bare `isize` as well as tuples
170+
//github.com/ of up to 10 `isize` values may be used for convenience.
171+
//github.com/
172+
//github.com/ # Panics
173+
//github.com/
174+
//github.com/ Panics if the index does not correspond to an in-bounds element of the
175+
//github.com/ `Array`.
176+
//github.com/
177+
//github.com/ # Examples
178+
//github.com/
179+
//github.com/ ```rust
180+
//github.com/ # use postgres_array::Array;
181+
//github.com/ let mut array = Array::from_vec(vec![0i32, 1, 2, 3], 0);
182+
//github.com/ assert_eq!(2, array[2]);
183+
//github.com/
184+
//github.com/ array.wrap(0);
185+
//github.com/ array.push(Array::from_vec(vec![4, 5, 6, 7], 0));
186+
//github.com/
187+
//github.com/ assert_eq!(6, array[(1, 2)]);
188+
//github.com/ ```
163189
fn index(&self, idx: I) -> &T {
164190
let idx = idx.index(self);
165191
&self.data[idx]

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/psqlpy-python/rust-postgres-array/commit/d263375fb678812f06c4368ab9fbd3be0e1db867

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy