Trait indxvec::Vecops

source ·
pub trait Vecops<T> {
Show 34 methods fn tof64(self) -> Vec<f64>
    where
        T: Clone,
        f64: From<T>
; fn maxt(self) -> T
    where
        T: PartialOrd + Clone
; fn mint(self) -> T
    where
        T: PartialOrd + Clone
; fn minmaxt(self) -> (T, T)
    where
        T: PartialOrd + Clone
; fn minmax(self) -> MinMax<T>
    where
        T: PartialOrd + Clone
; fn minmax_slice(self, i: usize, n: usize) -> MinMax<T>
    where
        T: PartialOrd + Clone
; fn minmax_indexed(self, idx: &[usize], i: usize, n: usize) -> MinMax<T>
    where
        T: PartialOrd + Clone
; fn revs(self) -> Vec<T>
    where
        T: Clone
; fn sansrepeat(self) -> Vec<T>
    where
        T: PartialEq + Clone
; fn member(self, m: T, forward: bool) -> Option<usize>
    where
        T: PartialEq + Clone
; fn occurs(self, val: T) -> usize
    where
        T: PartialOrd
; fn unite_unsorted(self, v: &[T]) -> Vec<T>
    where
        T: Clone
; fn unite_indexed(self, ix1: &[usize], v2: &[T], ix2: &[usize]) -> Vec<T>
    where
        T: PartialOrd + Clone
; fn intersect(self, v2: &[T]) -> Vec<T>
    where
        T: PartialOrd + Clone
; fn intersect_indexed(self, ix1: &[usize], v2: &[T], ix2: &[usize]) -> Vec<T>
    where
        T: PartialOrd + Clone
; fn diff(self, v2: &[T]) -> Vec<T>
    where
        T: PartialOrd + Clone
; fn diff_indexed(self, ix1: &[usize], v2: &[T], ix2: &[usize]) -> Vec<T>
    where
        T: PartialOrd + Clone
; fn partition(self, pivot: T) -> (Vec<T>, Vec<T>, Vec<T>)
    where
        T: PartialOrd + Clone
; fn partition_indexed(self, pivot: T) -> (Vec<usize>, Vec<usize>, Vec<usize>)
    where
        T: PartialOrd + Clone
; fn binsearch(self, target: T) -> Range<usize>
    where
        T: PartialOrd + Copy
; fn binsearch_indexed(self, idx: &[usize], target: &T) -> Range<usize>
    where
        T: PartialOrd
; fn merge(self, v2: &[T]) -> Vec<T>
    where
        T: PartialOrd + Clone
; fn merge_indexed(
        self,
        idx1: &[usize],
        v2: &[T],
        idx2: &[usize]
    ) -> (Vec<T>, Vec<usize>)
    where
        T: PartialOrd + Clone
; fn merge_indices(self, idx1: &[usize], idx2: &[usize]) -> Vec<usize>
    where
        T: PartialOrd + Clone
; fn mergesort_indexed(self) -> Vec<usize>
    where
        T: PartialOrd + Clone
; fn mergesortslice(self, i: usize, n: usize) -> Vec<usize>
    where
        T: PartialOrd + Clone
; fn sortm(self, ascending: bool) -> Vec<T>
    where
        T: PartialOrd + Clone
; fn rank(self, ascending: bool) -> Vec<usize>
    where
        T: PartialOrd + Clone
; fn isorttwo(self, idx: &mut [usize], i0: usize, i1: usize) -> bool
    where
        T: PartialOrd
; fn isortthree(self, idx: &mut [usize], i0: usize, i1: usize, i2: usize)
    where
        T: PartialOrd
; fn hashsort_indexed(self) -> Vec<usize>
    where
        T: PartialOrd + Clone,
        f64: From<T>
; fn hashsortslice(self, idx: &mut [usize], i: usize, n: usize, min: T, max: T)
    where
        T: PartialOrd + Clone,
        f64: From<T>
; fn sorth(self, ascending: bool) -> Vec<T>
    where
        T: PartialOrd + Clone,
        f64: From<T>
; fn keyindex(self, keyfn: fn(_: &T) -> f64, ascending: bool) -> Vec<usize>;
}
Expand description

Methods to manipulate generic Vecs and slices of type &[T]

Required Methods

Helper function to copy and cast entire &[T] to Vec<f64>.

Maximum value in self

Minimum value in self

Minimum and maximum values in self

Returns MinMax{min, minindex, max, maxindex}

MinMax of n items starting at subscript i

MinMax of a subset of self, defined by its idx subslice between i,i+n.

Reversed copy of self

Repeated items removed

Some(subscript) of the first occurence of m, or None

Counts partially equal occurrences of val by simple linear search of an unordered set

Unites (concatenates) two unsorted slices. For union of sorted slices, use merge

Unites two ascending index-sorted slices.

Intersects two ascending explicitly sorted generic vectors.

Intersects two ascending index sorted vectors.

Removes items of sorted v2 from sorted self.

Removes items of v2 from self using their sort indices.

Divides an unordered set into three: items smaller than pivot, equal, and greater

Divides an unordered set into three by the pivot. The results are subscripts to self

Binary Search. Automatic descending order detection.

Binary Search via index. Automatic descending order detection

Merges (unites) two sorted sets, result is also sorted

Merges (unites) two sets, using their sort indices, giving also the resulting sort index

Used by merge_indexed

Stable Merge sort main method, giving sort index

Utility used by mergesort_indexed

Stable Merge sort, explicitly sorted result obtained via mergesort_indexed

Rank index obtained via mergesort_indexed

Utility, swaps any two items into ascending order

Utility, sorts any three items into ascending order

Stable hash sort giving sort index

Utility used by hashsort_indexed

Stable hash sort. Returns new sorted data vector (ascending or descending)

Makes a sort index for self, using key generating closure keyfn

Implementations on Foreign Types

Helper function to copy and cast entire &[T] to Vec<f64>. Like the standard .to_vec() method but also recasts to f64 end type

Maximum value T of slice &[T]

Minimum value T of slice &[T]

Minimum and maximum (T,T) of a slice &[T]

Minimum, minimum’s first index, maximum, maximum’s first index

Finds min and max of a subset of self, defined by its subslice between i,i+n. Returns min of self, its index, max of self, its index.

Using only a subset of self, defined by its idx subslice between i,i+n. Returns min of self, its index’s index, max of self, its index’s index.

Reverse a generic slice by reverse iteration. Creates a new Vec. Its naive use for descending sort etc. is to be avoided for efficiency reasons.

Removes repetitions from an explicitly ordered set.

Finds the first/last occurence of item m in self by forward/backward iteration. Returns Some(index) of the found item or None. Suitable for small unordered lists. For longer lists, it is better to sort them and use binsearch (see below). For repeated tests, index sort first and then use `binsearch_indexed.

Counts partial equal occurrences of val by simple linear search of any unordered set

Unites (joins) two unsorted sets. For union of sorted sets, use merge

Unites two ascending index-sorted generic vectors. This is the union of two index sorted sets. Returns a single explicitly ordered set.

Intersects two ascending explicitly sorted generic vectors.

Intersects two ascending index-sorted generic vectors. Returns a single explicitly ordered set.

Sets difference: deleting elements of the second from the first. Two ascending explicitly sorted generic vectors.

Sets difference: deleting elements of the second from the first. Two ascending index sorted generic vectors.

Partition with respect to a pivot into three sets

Partition by pivot gives three sets of indices.

Binary Search with automatic descending order detection. Easy encapsulation of function search_all

Binary Search via index. Encapsulation of binary_all from trait Search Manual comparison to avoid Iterator trait bound demanded by cmp Automatic sort order detection

Merges two explicitly ascending sorted generic vectors, by classical selection and copying of their head items into the result. Consider using merge_indexed instead, especially for non-primitive end types T.

Merges two ascending sort indices. Data is not shuffled at all, v2 is just concatenated onto v1 in one go and both remain in their original order. Returns the concatenated vector and a new valid sort index into it.

Merges the sort indices of two concatenated vectors. Data in self is not changed at all, only consulted for the comparisons. This function is used by mergesort and merge_indexed.

Doubly recursive non-destructive merge sort. The data is not moved or mutated. Efficiency is comparable to quicksort but more stable Returns a vector of indices to s from i to i+n, such that the indexed values are in ascending sort order (a sort index). Only the index values are being moved.

The main mergesort Wraps mergesortslice, to obtain the whole sort index

Immutable merge sort. Returns new sorted data vector (ascending or descending). Wraps mergesortslice. Mergesortslice and mergesort_indexed produce only an ascending index. Sortm will produce descending data order with ascending == false.

Fast ranking of many T items, with only n*(log(n)+1) complexity. Ranking is done by inverting the sort index. Sort index is in sorted order, giving data positions. Ranking is in data order, giving sorted order positions. Thus sort index and ranks are in an inverse relationship. They are easily converted by .invindex() (for: invert index).

swap any two index items, if their data items (self) are not in ascending order

sort three index items if their self items are out of ascending order

N recursive non-destructive hash sort. Input data are read only. Output is sort index. Requires min,max, the data range, that must enclose all its values. The range is often known. If not, it can be obtained with minmaxt().

Immutable hash sort. Returns new sorted data vector (ascending or descending). Wraps mergesortslice. Mergesortslice and mergesort_indexed produce only an ascending index. Sortm will produce descending data order with ascending == false.

Makes a sort index for self, using key generating closure keyfn

Implementors