#ordered-sets #merge-sort #set-operations #ranking-searching #generic-vectors


Sets implemented as generic vectors. Efficiently sorting, merging, ranking, searching, reversing, intersecting, etc.

17 releases

0.2.6 Jul 21, 2021
0.2.5 Jul 8, 2021
0.1.9 Jul 4, 2021
0.1.8 Jun 28, 2021

#91 in Math

Download history 29/week @ 2021-06-16 142/week @ 2021-06-23 50/week @ 2021-06-30 76/week @ 2021-07-07 25/week @ 2021-07-14 28/week @ 2021-07-21

107 downloads per month
Used in 2 crates


437 lines

IndxVec Crates.io GitHub last commit (branch)


Insert into your Cargo.toml file [dependencies] section:
indxvec = "^0.2"

Import into your source file(s) macro here, functions and trait, as needed. There is just one trait Indices implemented on type &[usize]. There is a bunch of functions in module merge which usually take generic slices &[T] as arguments and produce new index vectors and/or other results. The following use statement imports everything from indxvec: use indxvec::{here,wv,wi,merge::*,Indices};

See tests/tests.rs for examples of usage. To run the tests, use a single thread. It may be slower but will produce the results in the right order:
cargo test --release -- --test-threads=1 --nocapture --color always


Indxvec is a spin-off from rstats. It is a self-contained unit, both in terms of the subject matter and also in not having any dependencies.

The tools included are: efficient ranking, sorting, merging, searching, set operations and indices manipulations. They are applicable to generic slices &[T]. Thus they will work on primitive types but also on any arbitrarily complex end type T, as long as you implement their required traits, mostly just PartialOrd and/or Copy for T.


are in the module src/merge.rs. They mostly take some generic slice(s) &[T] and produce the indices into them of type Vec<usize>, onto which the methods of the Indices trait can be conveniently chained. See the documentation.

Trait Index

The methods of this trait are implemented for slices of subscripts, i.e. they take the type &[usize] as input (self) and produce new index Vec<usize>, new data vector Vec<T>, or other results.

Release Notes (Latest First)

Version 0.2.6 - added unindexf64 for convenience. Same as unindex but the output is always converted to Vec<f64>.

Version 0.2.5 - added memsearchdesc_indexed = binary search of a descending indexed set.

Version 0.2.4 - added helper function wt = write tuple. Added memsearchdesc = binary search of a descending set.

Version 0.2.3 - general tidying up and readme update.

Version 0.2.2 - prettification of tests: replaced GV and GI with functions wv and wi respectively. Added revindex to Indices trait, so that it can be functionally chained with its other methods.

Version 0.2.1 - moved GI from rstats to here. Fixed minmax.

Version 0.2.0 - added set operations: sansrepeat, member, memsearch, memsearch_indexed, unite, unite_indexed, intersect, intersect_indexed, diff, diff_indexed. They are also used, with type/struct wrappers, by crate sets.

Version 0.1.9 - added method complindex to trait Indices.

Version 0.1.8 - added function minmax to module merge.

Version 0.1.7 - added convenience conversion method indx_to_f64.

Version 0.1.6 - improved comments. Used Vec::with_capacity for new vectors of known lengths. Maybe a bit faster but no change in functionality.

Version 0.1.5 - fixed an inconsistency in binsearch result.

Version 0.1.4 - swapped arguments of unindex for compatibility. Added more comments.

No runtime deps