Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature std compatibility #13

Draft
wants to merge 56 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
d44385d
WIP: make len atomic, add and use methods using atomics
cehteh Sep 17, 2024
2076db3
Merge branch 'rust-cv:main' into main
cehteh Sep 17, 2024
c9d5388
rename methods in _exact/_strict, add 'atomic_append' feature, add 's…
cehteh Sep 17, 2024
ecc9554
add push_atomic()
cehteh Sep 17, 2024
993cad0
WIP: reserve/shrink API's
cehteh Sep 23, 2024
4bcab1f
FIX: the reseve functions need saturating add as well
cehteh Sep 23, 2024
decaeed
FIX: Miri, unaligned access
cehteh Sep 23, 2024
58d68a1
add: extend_from_slice()
cehteh Sep 23, 2024
00be0d8
add: extend_from_slice_atomic()
cehteh Sep 23, 2024
2b4fbf6
ADD: spare_capacity_mut() and set_len()
cehteh Jan 10, 2025
d3a5a6f
add support for zero length HeaderVec
cehteh Jan 18, 2025
b34e0bd
DOC: fixing doc for reserve_cold()
cehteh Jan 20, 2025
9713321
Make HeaderVec being a NonNull<> instead a raw pointer
cehteh Jan 20, 2025
e2b5f0d
ADD: spare_capacity_mut() and set_len()
cehteh Jan 10, 2025
3fe8098
add support for zero length HeaderVec
cehteh Jan 18, 2025
4cde654
add a `std` feature flag
cehteh Jan 20, 2025
9f18d10
rename and export start_ptr()/mut to as_ptr()/mut
cehteh Jan 22, 2025
47af90f
FIX: Handle the case when resize_cold() would be a no-op
cehteh Jan 22, 2025
c2026c2
WIP: introduce WeakFixupFn, start removing Option<*const ()>
cehteh Jan 23, 2025
ca899af
CHANGE: modify push() using WeakFixupFn, add push_with_weakfix()
cehteh Jan 23, 2025
9775e59
CHANGE: WeakFixupFn for extend_from_slice()
cehteh Jan 23, 2025
71f42a1
refactor: put HeaderVecWeak into its own module
cehteh Jan 23, 2025
0fd6d9a
ADD: a lot `impl From`'s
cehteh Jan 23, 2025
30430e6
Make `extemd_from_slice()` generic over AsRef<[T]>
cehteh Jan 23, 2025
f00e8ad
FIX: enable From Cow/Vec/Box only when std is enabled
cehteh Jan 23, 2025
20a54c7
ADD: missing From<&str> for HeaderVec<.., u8>
cehteh Jan 23, 2025
09d6827
Add HeaderVec::from_header_slice(), simplify the From impl
cehteh Jan 24, 2025
d8c717e
ADD: truncate() and clear()
cehteh Jan 30, 2025
efc96c0
CHANGE: make the `std` feature default (breaks no_std)
cehteh Jan 30, 2025
a421e3f
ADD: `drain()` method and `Drain` iterator
cehteh Jan 30, 2025
546d1af
cosmetic fixes/ trivial lints
cehteh Jan 30, 2025
61435a6
ADD: iter()/iter_mut(), impl IntoIterator
cehteh Jan 30, 2025
e3d1dc7
move slice dependency fom std to core
cehteh Jan 30, 2025
1d9062b
ADD: impl Extend<T> and Extend<&T>
cehteh Jan 31, 2025
76163d6
pass the WeakFixupFn by &mut internally
cehteh Jan 31, 2025
c42d26f
replace Drain::tail_len with tail_end
cehteh Feb 13, 2025
3e9047e
assert that T is not a ZST
cehteh Feb 14, 2025
91fa732
splice() method and Splice iterator
cehteh Feb 14, 2025
c5e3081
move std tests to tests/std.rs
cehteh Feb 14, 2025
723dcdf
add benchmarks for drain and splice
cehteh Feb 15, 2025
25788c1
FIX: bug in offset() calculation
cehteh Feb 18, 2025
9a77260
Merge branch 'feature-atomic-append' into feature-std-compatibility
cehteh Feb 18, 2025
156cb39
simple/cosmetic changes only
cehteh Feb 20, 2025
2e84514
improve headervec drop() by dropping the elements as slice
cehteh Feb 20, 2025
d168f01
rewrite the splice drop algo to the same std Vec uses
cehteh Feb 20, 2025
5dd7b59
improve benchmarks, generated by xmacros
cehteh Feb 20, 2025
9d839ff
Document the atomic_append API / add Safety Section
cehteh Feb 20, 2025
98fae22
remove is_empty_atomic_acquire as_slice_atomic_acquire
cehteh Feb 20, 2025
eb3efca
formatting
cehteh Feb 20, 2025
e68a751
Merge branch 'main' into feature-spare-elements
cehteh Feb 20, 2025
7f8b83a
Merge branch 'feature-spare-elements' into feature-std-compatibility
cehteh Feb 20, 2025
d7a0d1a
try to reserve space in the Extend impls
cehteh Feb 21, 2025
aa3ba67
ADD: from_header_elements() constructor consuming its input
cehteh Feb 21, 2025
779c992
add tests/mutants.rs
cehteh Feb 21, 2025
4420366
clippy cosmetics
cehteh Feb 21, 2025
e6bcf06
Add mutant testing
cehteh Feb 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,18 @@ keywords = ["header", "heap", "vec", "vector", "graph"]
categories = ["no-std"]
license = "MIT"
readme = "README.md"

[features]
default = ["std", "atomic_append"]
std = []
atomic_append = []

[dev-dependencies]
xmacro = "0.2.0"

# include debug info for flamgraph and other profiling tools
[profile.bench]
debug = true

[dependencies]
mutants = "0.0.3"
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,13 @@
Allows one to store a header struct and a vector all inline in the same memory on the heap and share weak versions for minimizing random lookups in data structures

If you use this without creating a weak ptr, it is safe. It is unsafe to create a weak pointer because you now have aliasing.

## Features

* `std`
Enables API's that requires stdlib features. Provides more compatibility to `Vec`.
This feature is enabled by default.
* `atomic_append`
Enables the `atomic_push` API's that allows extending a `HeaderVec` with interior
mutability from a single thread by a immutable handle.
This feature is enabled by default.
133 changes: 133 additions & 0 deletions benches/compare_std_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

extern crate std;
extern crate test;
use xmacro::xmacro;

use header_vec::*;
use test::Bencher;
Expand Down Expand Up @@ -126,3 +127,135 @@ fn test_regular_vec_create(b: &mut Bencher) {
// acc
// });
// }

xmacro! {
$[
benchfunc: type:
hv_create_bench (HeaderVec::<(), _>)
vec_create_bench (Vec)
]

fn $benchfunc<T>(b: &mut Bencher, init: &[T])
where
T: Clone + Default,
{
b.iter(|| {
let v = $type::from(init);
v
});
}
}

xmacro! {
// benching construction times.
$[
bench: init:
small [123; 1]
middle [123; 1000]
large [[123;32]; 100000]
]

#[bench]
fn $+bench_hv_create_$bench(b: &mut Bencher) {
hv_create_bench(b, &$init);
}

#[bench]
fn $+bench_vec_create_$bench(b: &mut Bencher) {
vec_create_bench(b, &$init);
}
}

#[cfg(feature = "std")]
mod stdbench {
use super::*;
use std::ops::RangeBounds;

xmacro! {
$[
benchfunc: type:
hv_drain_bench (HeaderVec::<(), _>)
vec_drain_bench (Vec)
]

fn $benchfunc<T, R>(b: &mut Bencher, init: &[T], range: R)
where
T: Clone + Default,
R: RangeBounds<usize> + Clone,
{
b.iter(|| {
let mut v = $type::from(init);
v.drain(range.clone());
v
});
}
}

xmacro! {
$[
bench: init: range:
begin [123; 10000] (..5000)
middle [123; 10000] (1000..5000)
end [123; 10000] (1000..)
]

#[bench]
fn $+bench_hv_drain_$bench(b: &mut Bencher) {
hv_drain_bench(b, &$init, $range);
}

#[bench]
fn $+bench_vec_drain_$bench(b: &mut Bencher) {
vec_drain_bench(b, &$init, $range);
}
}

xmacro! {
$[
benchfunc: type:
hv_splice_bench (HeaderVec::<(), _>)
vec_splice_bench (Vec)
]

fn $benchfunc<T, R, I>(b: &mut Bencher, init: &[T], range: R, replace_with: I)
where
T: Clone,
R: RangeBounds<usize> + Clone,
I: IntoIterator<Item = T> + Clone,
{
b.iter(|| {
let mut v = $type::from(init);
v.splice(range.clone(), replace_with.clone());
v
});
}
}

xmacro! {
$[
bench: init: range: replace_with:
nop [123; 10000] (0..0) []
insert [123; 10000] (1000..1000) [123; 5000]
insert_big [[123;64]; 10000] (1000..1000) [[123; 64]; 5000]
remove [123; 10000] (1000..6000) []
middle_shorter [123; 10000] (4000..5000) [234; 500]
middle_longer [123; 10000] (4000..5000) [345; 2000]
middle_same [123; 10000] (4000..5000) [456; 1000]
end_shorter [123; 10000] (9000..) [234; 500]
end_longer [123; 10000] (9000..) [345; 2000]
end_same [123; 10000] (9000..) [456; 1000]
append_big [[123;64]; 10000] (10000..) [[456; 64]; 5000]
append_front_big [[123;64]; 100000] (0..0) [[456; 64]; 1]
]

#[bench]
fn $+bench_hv_splice_$bench(b: &mut Bencher) {
hv_splice_bench(b, &$init, $range, $replace_with)
}

#[bench]
fn $+bench_vec_splice_$bench(b: &mut Bencher) {
vec_splice_bench(b, &$init, $range, $replace_with)
}
}
}
Loading
Loading