Skip to content

Commit e86ebff

Browse files
authored
Add is_unique for ArcArray (#1399)
1 parent 5d37dfb commit e86ebff

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/impl_arc_array.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2019 ndarray developers.
2+
//
3+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6+
// option. This file may not be copied, modified, or distributed
7+
// except according to those terms.
8+
9+
use crate::imp_prelude::*;
10+
use alloc::sync::Arc;
11+
12+
/// Methods specific to `ArcArray`.
13+
///
14+
/// ***See also all methods for [`ArrayBase`]***
15+
impl<A, D> ArcArray<A, D>
16+
where D: Dimension
17+
{
18+
/// Returns `true` iff the inner `Arc` is not shared.
19+
/// If you want to ensure the `Arc` is not concurrently cloned, you need to provide a `&mut self` to this function.
20+
pub fn is_unique(&self) -> bool
21+
{
22+
// Only strong pointers are used in this crate.
23+
Arc::strong_count(&self.data.0) == 1
24+
}
25+
}

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,6 +1612,9 @@ mod impl_raw_views;
16121612
// Copy-on-write array methods
16131613
mod impl_cow;
16141614

1615+
// Arc array methods
1616+
mod impl_arc_array;
1617+
16151618
/// Returns `true` if the pointer is aligned.
16161619
pub(crate) fn is_aligned<T>(ptr: *const T) -> bool
16171620
{

0 commit comments

Comments
 (0)