#sorting #insertion #insert #array #vec

no-std sorted-insert

This crate provides traits to insert elements to a sorted collection and keep the order

5 releases

0.2.3 Mar 19, 2022
0.2.2 Apr 22, 2021
0.2.1 Aug 9, 2020
0.2.0 Aug 9, 2020
0.1.0 Aug 9, 2020

#1330 in Algorithms

Download history 150/week @ 2023-12-05 240/week @ 2023-12-12 235/week @ 2023-12-19 450/week @ 2023-12-26 472/week @ 2024-01-02 229/week @ 2024-01-09 274/week @ 2024-01-16 338/week @ 2024-01-23 130/week @ 2024-01-30 117/week @ 2024-02-06 204/week @ 2024-02-13 187/week @ 2024-02-20 125/week @ 2024-02-27 283/week @ 2024-03-05 379/week @ 2024-03-12 420/week @ 2024-03-19

1,251 downloads per month
Used in 8 crates (2 directly)

MIT license

11KB
156 lines

Sorted Insert

CI

This crate provides traits to insert elements to a sorted collection and keep the order.

Examples

use sorted_insert::SortedInsert;

let mut v = vec![1, 5];

v.sorted_insert_asc(2);

assert_eq!([1, 2, 5], v.as_slice());
use sorted_insert::SortedInsertBinary;

let mut v = vec![5, 1];

v.sorted_insert_desc_binary(2);

assert_eq!([5, 2, 1], v.as_slice());
use sorted_insert::SortedInsertByKey;

#[derive(Debug, Copy, Clone, Eq, PartialEq)]
struct A(i32, i32);

let mut v = vec![A(1, 10), A(2, 20)];

v.sorted_insert_asc_by_key(A(1, 15), |e| &e.1);

assert_eq!([A(1, 10), A(1, 15), A(2, 20)], v.as_slice());

No Std

Disable the default features to compile this crate without std.

[dependencies.sorted-insert]
version = "*"
default-features = false

Crates.io

https://crates.io/crates/sorted-insert

Documentation

https://docs.rs/sorted-insert

License

MIT

No runtime deps

Features