Skip to content

Feature std compatibility #13

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

Draft
wants to merge 60 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 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
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
25788c1
FIX: bug in offset() calculation
cehteh Feb 18, 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
96ab22f
improve conditional compilation w/o relying on cfg_if
cehteh Mar 11, 2025
caafac5
ADD: spare_capacity_mut() and set_len()
cehteh Jan 10, 2025
2f648bc
add support for zero length HeaderVec
cehteh Jan 18, 2025
a276769
formatting
cehteh Feb 20, 2025
d392c09
add a `std` feature flag
cehteh Jan 20, 2025
4afb0ba
rename and export start_ptr()/mut to as_ptr()/mut
cehteh Jan 22, 2025
84d6431
FIX: Handle the case when resize_cold() would be a no-op
cehteh Jan 22, 2025
3c04f05
WIP: introduce WeakFixupFn, start removing Option<*const ()>
cehteh Jan 23, 2025
1556faa
CHANGE: modify push() using WeakFixupFn, add push_with_weakfix()
cehteh Jan 23, 2025
fff8d0d
CHANGE: WeakFixupFn for extend_from_slice()
cehteh Jan 23, 2025
5d4dec4
refactor: put HeaderVecWeak into its own module
cehteh Jan 23, 2025
9c5ff01
ADD: a lot `impl From`'s
cehteh Jan 23, 2025
63f10e1
Make `extemd_from_slice()` generic over AsRef<[T]>
cehteh Jan 23, 2025
e14782f
FIX: enable From Cow/Vec/Box only when std is enabled
cehteh Jan 23, 2025
e2f6fe3
ADD: missing From<&str> for HeaderVec<.., u8>
cehteh Jan 23, 2025
31883d2
Add HeaderVec::from_header_slice(), simplify the From impl
cehteh Jan 24, 2025
af365a1
ADD: truncate() and clear()
cehteh Jan 30, 2025
9e8fb9a
CHANGE: make the `std` feature default (breaks no_std)
cehteh Jan 30, 2025
8758758
ADD: `drain()` method and `Drain` iterator
cehteh Jan 30, 2025
2d0cc40
cosmetic fixes/ trivial lints
cehteh Jan 30, 2025
cb9c685
ADD: iter()/iter_mut(), impl IntoIterator
cehteh Jan 30, 2025
507d36e
move slice dependency fom std to core
cehteh Jan 30, 2025
e4e15e8
ADD: impl Extend<T> and Extend<&T>
cehteh Jan 31, 2025
639a0e3
pass the WeakFixupFn by &mut internally
cehteh Jan 31, 2025
04166d4
replace Drain::tail_len with tail_end
cehteh Feb 13, 2025
f4ce0e0
assert that T is not a ZST
cehteh Feb 14, 2025
2bdc609
splice() method and Splice iterator
cehteh Feb 14, 2025
bd6b2f0
move std tests to tests/std.rs
cehteh Feb 14, 2025
a29d0a8
add benchmarks for drain and splice
cehteh Feb 15, 2025
5ad79da
simple/cosmetic changes only
cehteh Feb 20, 2025
2398eca
improve headervec drop() by dropping the elements as slice
cehteh Feb 20, 2025
12d874a
rewrite the splice drop algo to the same std Vec uses
cehteh Feb 20, 2025
afa5423
improve benchmarks, generated by xmacros
cehteh Feb 20, 2025
db35b0a
try to reserve space in the Extend impls
cehteh Feb 21, 2025
8183d52
ADD: from_header_elements() constructor consuming its input
cehteh Feb 21, 2025
d766aba
add tests/mutants.rs
cehteh Feb 21, 2025
d453f62
clippy cosmetics
cehteh Feb 21, 2025
9ae8cbb
Add mutant testing
cehteh Feb 21, 2025
94da760
improve conditional compilation w/o relying on cfg_if
cehteh Mar 10, 2025
243fd4b
DOC: fix some broken links
cehteh Mar 11, 2025
20a6e6b
ADD: header_vec! macro sumilar to the stdlib vec!() macro
cehteh Mar 11, 2025
105675f
fix linter warnings in std tests
cehteh Mar 19, 2025
85c09da
bump xmacro to 0.3 (bugfix)
cehteh Mar 19, 2025
4551f95
ADD: HeaderVec::leak() for leaking data
cehteh Mar 19, 2025
dd95b98
use a repr(C) struct with a [T; 0] as first field for alignment
cehteh Apr 5, 2025
056d3ff
bump xmacro version
cehteh Apr 9, 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.4.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 @@
// acc
// });
// }

xmacro! {

Check failure on line 131 in benches/compare_std_vec.rs

View workflow job for this annotation

GitHub Actions / benches

proc macro panicked
$[
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! {

Check failure on line 149 in benches/compare_std_vec.rs

View workflow job for this annotation

GitHub Actions / benches

proc macro panicked
// 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;

Check warning on line 172 in benches/compare_std_vec.rs

View workflow job for this annotation

GitHub Actions / benches

unused import: `std::ops::RangeBounds`

xmacro! {

Check failure on line 174 in benches/compare_std_vec.rs

View workflow job for this annotation

GitHub Actions / benches

proc macro panicked
$[
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! {

Check failure on line 194 in benches/compare_std_vec.rs

View workflow job for this annotation

GitHub Actions / benches

proc macro panicked
$[
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! {

Check failure on line 213 in benches/compare_std_vec.rs

View workflow job for this annotation

GitHub Actions / benches

proc macro panicked
$[
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! {

Check failure on line 234 in benches/compare_std_vec.rs

View workflow job for this annotation

GitHub Actions / benches

proc macro panicked
$[
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