Skip to content

Commit

Permalink
Add is_unique for ArcArray (#1399)
Browse files Browse the repository at this point in the history
  • Loading branch information
daniellga committed Jul 29, 2024
1 parent 5d37dfb commit e86ebff
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/impl_arc_array.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2019 ndarray developers.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use crate::imp_prelude::*;
use alloc::sync::Arc;

/// Methods specific to `ArcArray`.
///
/// ***See also all methods for [`ArrayBase`]***
impl<A, D> ArcArray<A, D>
where D: Dimension
{
/// Returns `true` iff the inner `Arc` is not shared.
/// If you want to ensure the `Arc` is not concurrently cloned, you need to provide a `&mut self` to this function.
pub fn is_unique(&self) -> bool
{
// Only strong pointers are used in this crate.
Arc::strong_count(&self.data.0) == 1
}
}
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1612,6 +1612,9 @@ mod impl_raw_views;
// Copy-on-write array methods
mod impl_cow;

// Arc array methods
mod impl_arc_array;

/// Returns `true` if the pointer is aligned.
pub(crate) fn is_aligned<T>(ptr: *const T) -> bool
{
Expand Down

0 comments on commit e86ebff

Please # to comment.