Indxvec
Description
This crate is lightweight and has no dependencies.
The facilities provided are:
- ranking, sorting, merging, searching, indexing, selecting, partitioning
- general operations on/with indices
- set operations
- printing of generic slices and slices of vectors
- macro for easy error reporting
Usage
Auxiliay functions and constants
use ;
Traits Indices
and/or Printing
use ;
Trait Indices
is implemented on type &[usize]
, i.e. slices of subscripts to slices and vectors.
Trait Printing
provides utility methods to stringify (serialise for printing) generic slices and slices of vecs.
Optionally, it enables printing in bold green and red for adding emphasis (see tests/tests.rs
).
Functions from merge.rs
use ;
These functions are applicable to generic slices &[T]
. Thus they will work on Rust primitive end types, such as f64. They can also work on slices holding any arbitrarily complex end type T
, as long as the required traits, mostly just PartialOrd
and/or Copy
, are implemented for T
.
The following will import everything
use ;
Testing
It is highly recommended to read and run tests/tests.rs
to learn from examples of usage. Use a single thread to run them. It may be a bit slower but it will write the results in the right order:
cargo test --release -- --test-threads=1 --nocapture --color always
Trait Indices
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 as appropriate:
/// Methods to manipulate indices of `Vec<usize>` type.
Trait Printing
This trait is implemented for generic individual items T
, for slices &[T]
and for slices of vecs &[Vec<T>]
. Note that these types are normally unprintable in Rust.
The methods of this trait .gr()
, .red()
, .blue()
, .wvec(&mut f)
and .to_str()
convert all these generic vector objects to printable strings. The last two are uncoloured and can be used to write to files; wvec
also passes on io::Error(s) For example:
println!;
It is also possible to import these constants: use indxvec::{RD,GR,BL,UN};
and then use them in any formatting strings directly, e.g.: "{RD} my important output: {} {UN}"
will print everything so bracketed in red. Switching colours:
println!("{GR}green text, {RD}red warning, {BL}feeling blue{UN}");
Note that all of these methods and interpolations set their own colour regardless of the previous settings.
Interpolating {UN}
resets the terminal to its default foreground rendering.
UN
is automatically appended at the end of strings produced by .gr()
,.red()
and .green()
methods. Be careful to always close with one of these three, or {UN}
, otherwise all the following output will continue with the last selected colour foreground rendering.
/// Trait to serialize slices of generic items &[T] (vectors)
/// and slices of Vecs &[Vec<T>] (matrices).
/// All are converted into printable strings.
Functions
Nota bene: hashsort
really wins on longer Vecs. For about one thousand items upwards it is on average about 25% faster than the best Rust sort.
Signatures of public functions in module src/merge.rs
/// New trivial index for v in the existing order: 0..v.len()
;
/// Maximum value T of slice &[T]
Release Notes (Latest First)
Version 1.1.7 - Added method wvec(self,&mut f)
. It writes vectors to file f and passes up errors. Added colour blue()
. Added printing test. Prettier readme.md.
Version 1.1.6 - Added simple partition
into three sets (lt,eq,gt).
Version 1.1.5 - Updated dev dependency to ran = "^0.3". Changed partition_indexed
to include equal set. Tweaked printing layout.
Version 1.1.4 - Minor change: hashsort
min,max arguments type changed from T to f64. This is more convenient for apriori known data range limits. Also to be the same as for hashsort_indexed
. Added newindex
and minmax_slice
functions. Updated readme file.
Version 1.1.3 - hashsort
renamed to hashsort_indexed
, in keeping with the naming convention here. New plain hashsort
added: it sorts &mut[T] in place, just like does the default Rust sort. Suitable for long explicit sorts.
Version 1.1.2 - Added .red()
method to Printing
. Some tidying up of tests.rs
and the docs. hashsort
improved.
Version 1.1.0 - Added superfast n-recursive hashsort
. Suitable for multithreading (todo).
Version 1.0.9 - Minor changes to testing.rs to better test ran
.
Version 1.0.8 - Dependencies reorganization to minimise the footprint. The random numbers generation has now been moved to its own new crate ran
and added here just as a development dependency where it rightfully belongs.
Version 1.0.7 - Renamed function occurs
to occurs_multiple
and added a simple linear count of item occurences: occurs
.
Version 1.0.6 - Some cosmetic changes to the code, readme and tests, no change of functionality.
Version 1.0.5 - Added partition_indexed
for partitioning into two sets of indices about a pivot. Moved all random number generating functions into new module random.rs
(import changed to: random::*
). Moved the implementations of Printing trait to new module printing.rs
(this has no effect on users).
Version 1.0.4 - here!() now highlights the (first) error in bold red. Added fast random number generation functions ranf64, ranv64, ranvu8, ranvvf64, rannvvu8
.
Version 1.0.3 - Added utilities functions maxt, mint, minmaxt
. Rationalised the functions for printing generic slices and slices of vectors. They are now turned into two chainable methods in trait Printing
: .to_str()
and .gr()
. The latter also serialises slices to strings but additionally makes them bold green.
Version 1.0.2 - Added function occurs
that efficiently counts occurrences of specified items in a set with repetitions.
Version 1.0.1 - Some code style tidying up. Added function binsearchdesc
for completeness and symmetry with binsearch
.
Version 1.0.0 - indxvec
has been stable for some time now, so it gets promoted to v1.0.0. There are some improvements to README.md
to mark the occasion.