resurect addref and unref since tests use 'em for now

This commit is contained in:
Brooks Prumo
2021-09-16 16:00:30 -05:00
committed by Jeff Washington (jwash)
parent 7bccdc5251
commit e4103b5886
2 changed files with 26 additions and 0 deletions

View File

@ -161,6 +161,18 @@ impl<T: Clone + Copy> Bucket<T> {
Err(BucketMapError::IndexNoSpace(index.capacity_pow2))
}
pub fn addref(&mut self, key: &Pubkey) -> Option<RefCount> {
let (elem, _) = self.find_entry_mut(key)?;
elem.ref_count += 1;
Some(elem.ref_count)
}
pub fn unref(&mut self, key: &Pubkey) -> Option<RefCount> {
let (elem, _) = self.find_entry_mut(key)?;
elem.ref_count -= 1;
Some(elem.ref_count)
}
fn create_key(&self, key: &Pubkey, ref_count: u64) -> Result<u64, BucketMapError> {
Self::bucket_create_key(
&self.index,

View File

@ -196,6 +196,20 @@ impl<T: Clone + Copy + Debug> BucketMap<T> {
0
}
}
/// Increment the refcount for Pubkey `key`
pub fn addref(&self, key: &Pubkey) -> Option<RefCount> {
let ix = self.bucket_ix(key);
let mut bucket = self.buckets[ix].write().unwrap();
bucket.as_mut()?.addref(key)
}
/// Decrement the refcount for Pubkey `key`
pub fn unref(&self, key: &Pubkey) -> Option<RefCount> {
let ix = self.bucket_ix(key);
let mut bucket = self.buckets[ix].write().unwrap();
bucket.as_mut()?.unref(key)
}
}
/// Look at the first 8 bytes of the input and reinterpret them as a u64