Skip to content

Commit

Permalink
Merge pull request #30 from orxfun/concurrent-clone-and-fill
Browse files Browse the repository at this point in the history
clone_with_len and fill_with methods are defined for concurrent vectors
  • Loading branch information
orxfun authored Aug 27, 2024
2 parents 968f251 + 6337bc2 commit 1539929
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "orx-pinned-vec"
version = "3.5.0"
version = "3.6.0"
edition = "2021"
authors = ["orxfun <[email protected]>"]
description = "`PinnedVec` trait defines the interface for vectors which guarantee that elements added to the vector are pinned to their memory locations unless explicitly changed."
Expand Down
23 changes: 22 additions & 1 deletion src/concurrent_pinned_vec.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{PinnedVec, PinnedVecGrowthError};
use std::ops::RangeBounds;
use std::ops::{Range, RangeBounds};

/// A wrapper for a pinned vector which provides additional guarantees for concurrent programs.
///
Expand All @@ -24,6 +24,22 @@ pub trait ConcurrentPinnedVec<T> {
/// This method can safely be called if entries in all positions `0..len` are written.
unsafe fn into_inner(self, len: usize) -> Self::P;

/// Clones the concurrent pinned vector with for the first `len` elements.
/// The created concurrent vector will have the same capacity and maximum capacity as this collection;
/// however, only the values within 0..len will be cloned to the target.
///
/// # Safety
///
/// This method is unsafe due to the following.
/// The concurrent pinned vector is the core data structure for different concurrent collections
/// which allow writing to the vector in different ways.
/// The wrapper is responsible to deal with the gaps.
///
/// This method can safely be called if entries in all positions `0..len` are written.
unsafe fn clone_with_len(&self, len: usize) -> Self
where
T: Clone;

// &self get

/// Returns an iterator over positions `0..len` of the vector.
Expand Down Expand Up @@ -113,6 +129,11 @@ pub trait ConcurrentPinnedVec<T> {
where
F: Fn() -> T;

/// Fills the provided `range` with elements created by successively calling the `fill_with` function.
fn fill_with<F>(&self, range: Range<usize>, fill_with: F)
where
F: Fn() -> T;

/// Increases the `maximum_capacity` to the `new_maximum_capacity`.
///
/// # Safety
Expand Down

0 comments on commit 1539929

Please sign in to comment.