From e86ebff64c89e759e3568511045006b51726b4b0 Mon Sep 17 00:00:00 2001 From: daniellga <43149605+daniellga@users.noreply.github.com> Date: Mon, 29 Jul 2024 17:46:08 -0300 Subject: [PATCH] Add `is_unique` for `ArcArray` (#1399) --- src/impl_arc_array.rs | 25 +++++++++++++++++++++++++ src/lib.rs | 3 +++ 2 files changed, 28 insertions(+) create mode 100644 src/impl_arc_array.rs diff --git a/src/impl_arc_array.rs b/src/impl_arc_array.rs new file mode 100644 index 000000000..0225c71ac --- /dev/null +++ b/src/impl_arc_array.rs @@ -0,0 +1,25 @@ +// Copyright 2019 ndarray developers. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , 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 ArcArray +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 + } +} diff --git a/src/lib.rs b/src/lib.rs index 380256692..838c70497 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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(ptr: *const T) -> bool {