Module array

Module array 

Source
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§

ThresholdStrategy
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, or None if not found.
bisect
Returns the insertion point for x in a sorted slice to maintain sorted order.
bisect_left
Returns the leftmost insertion point for x in a sorted slice.
bisect_left_f64
Binary search for f64 values (handles NaN correctly).
bisect_right
Returns the rightmost insertion point for x in 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 a but not in b.
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 a and b.
is_disjoint
Returns true if a and b have no elements in common.
is_subset
Returns true if a is a subset of b (all elements of a are in b).
is_superset
Returns true if a is a superset of b (all elements of b are in a).
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 a or b but 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 count ticks.
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 a or b (or both).
unique
Returns a new Vec containing only unique elements (first occurrence).
variance
Returns the sample variance of values in the slice.