MCPcopy Create free account
hub / github.com/cosdata/cosdata / get_or_insert

Method get_or_insert

src/models/atomic_array.rs:95–111  ·  view source on GitHub ↗
(&self, idx: usize, mut f: F)

Source from the content-addressed store, hash-verified

93 }
94
95 pub fn get_or_insert<F>(&self, idx: usize, mut f: F) -> (*mut T, bool)
96 where
97 F: FnMut() -> *mut T,
98 {
99 let mut return_value = ptr::null_mut();
100 let res = self.items[idx].fetch_update(Ordering::SeqCst, Ordering::SeqCst, |existing| {
101 if existing.is_null() {
102 let value = f();
103 return_value = value;
104 Some(value)
105 } else {
106 return_value = existing;
107 None
108 }
109 });
110 (return_value, res.is_ok())
111 }
112
113 pub fn get_or_insert_with<F>(&self, idx: usize, mut f: F) -> (*mut T, bool)
114 where

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected