Expand description
Array manipulation and data utilities
This module provides functions for manipulating and summarizing data arrays, inspired by d3-array. It includes statistics, search, binning, transformations, and set operations.
§Example
use d3rs::array::{mean, min_by, max_by, bisect_right_f64};
let data = vec![3.0, 1.0, 4.0, 1.0, 5.0, 9.0, 2.0, 6.0];
assert_eq!(mean(&data), Some(3.875));
assert_eq!(min_by(&data, |a, b| a.partial_cmp(b).unwrap()), Some(&1.0));
assert_eq!(max_by(&data, |a, b| a.partial_cmp(b).unwrap()), Some(&9.0));
let sorted = vec![1.0, 2.0, 3.0, 5.0, 8.0, 13.0];
assert_eq!(bisect_right_f64(&sorted, 4.0), 3);Structs§
- Bin
- A bin containing values within a range.
- BinGenerator
- Configuration for generating bins/histograms.
- Bisector
- A bisector that uses a custom accessor function.
Enums§
- Threshold
Strategy - Strategy for determining bin thresholds.
Functions§
- bin
- Convenience function to create bins from f64 data with default settings.
- binary_
search - Returns the index of the value in a sorted slice that equals
x, orNoneif not found. - bisect
- Returns the insertion point for
xin a sorted slice to maintain sorted order. - bisect_
left - Returns the leftmost insertion point for
xin a sorted slice. - bisect_
left_ f64 - Binary search for f64 values (handles NaN correctly).
- bisect_
right - Returns the rightmost insertion point for
xin a sorted slice. - bisect_
right_ f64 - Binary search for f64 values (handles NaN correctly).
- count
- Returns the count of values in the slice that satisfy the predicate.
- cross
- Returns cross product of two slices.
- cumsum
- Returns the cumulative sum of values in the slice.
- deviation
- Returns the sample standard deviation of values in the slice.
- difference
- Returns elements that are in
abut not inb. - extent
- Returns the minimum and maximum values in the slice.
- extent_
by - Returns the minimum and maximum values using a custom comparator.
- filter
- Filters elements by a predicate.
- group
- Groups elements by a key function.
- index
- Creates an index from key to element.
- intersection
- Returns elements that are in both
aandb. - is_
disjoint - Returns true if
aandbhave no elements in common. - is_
subset - Returns true if
ais a subset ofb(all elements ofaare inb). - is_
superset - Returns true if
ais a superset ofb(all elements ofbare ina). - least_
index - Finds the value in a sorted slice that is closest to
x. - log_
ticks - Generate nice logarithmic ticks for a given domain.
- map
- Maps elements using a function.
- max
- Returns the maximum value in the slice.
- max_by
- Returns the maximum value in the slice using a custom comparator.
- max_
index - Returns the index of the maximum value in the slice.
- mean
- Returns the arithmetic mean of values in the slice.
- mean_by
- Returns the arithmetic mean using an accessor function.
- median
- Returns the median of values in a mutable slice.
- merge_
sorted - Merges multiple sorted slices into a single sorted Vec.
- min
- Returns the minimum value in the slice.
- min_by
- Returns the minimum value in the slice using a custom comparator.
- min_
index - Returns the index of the minimum value in the slice.
- nice
- Extend the domain to nice round values.
- nice_
bin_ edges - Computes nice bin edges that span the given extent.
- nice_
number - Find a “nice” number approximately equal to the range.
- pairs
- Returns pairs of consecutive elements.
- quantile
- Returns the p-quantile of values in a mutable slice.
- quantile_
sorted - Returns the p-quantile of values in a sorted slice.
- reduce
- Reduces elements to a single value.
- reverse
- Reverses the order of elements in a slice.
- rollup
- Groups elements and applies a reducer to each group.
- shuffle
- Randomly shuffles a slice using the Fisher-Yates algorithm.
- shuffle_
seeded - Randomly shuffles a slice using a seeded random number generator.
- sort_by
- Sorts a slice in place using a key accessor.
- sort_
by_ desc - Sorts a slice in place in descending order using a key accessor.
- sum
- Returns the sum of values in the slice.
- symmetric_
difference - Returns the symmetric difference: elements in
aorbbut not both. - threshold_
sturges - Computes the recommended number of bins using Sturges’ formula.
- tick_
increment - Increment a nice step size to the next larger nice value.
- tick_
step - Compute the step size for generating approximately
countticks. - ticks
- Generate nice linear ticks for a given domain.
- ticks_
interval - Generate ticks at specific intervals (e.g., every 5, 10, etc.).
- time_
ticks - Generate date/time ticks (placeholder for future implementation).
- union
- Returns elements that are in either
aorb(or both). - unique
- Returns a new Vec containing only unique elements (first occurrence).
- variance
- Returns the sample variance of values in the slice.