Increase shard count and remove redundant impls

next
Sayan Nandan 2 years ago
parent d4c10bee80
commit 669eca3ff7
No known key found for this signature in database
GPG Key ID: 8BC07A0A4D41DD52

1
Cargo.lock generated

@ -1307,7 +1307,6 @@ dependencies = [
"libsky",
"libstress",
"log",
"num_cpus",
"openssl",
"parking_lot 0.12.0",
"rand",

@ -17,7 +17,6 @@ clap = { version = "2", features = ["yaml"] }
env_logger = "0.9.0"
hashbrown = { version = "0.12.1", features = ["raw"] }
log = "0.4.17"
num_cpus = "1.13.1"
openssl = { version = "0.10.40", features = ["vendored"] }
parking_lot = "0.12.0"
regex = "1.5.6"

@ -24,14 +24,13 @@
*
*/
use super::bref::{RefMulti, RefMultiMut};
use super::bref::RefMulti;
use super::LowMap;
use super::Skymap;
use core::mem;
use hashbrown::raw::RawIntoIter;
use hashbrown::raw::RawIter;
use parking_lot::RwLockReadGuard;
use parking_lot::RwLockWriteGuard;
use std::collections::hash_map::RandomState;
use std::sync::Arc;
@ -79,7 +78,6 @@ unsafe impl<K: Send, V: Send, S> Send for OwnedIter<K, V, S> {}
unsafe impl<K: Sync, V: Sync, S> Sync for OwnedIter<K, V, S> {}
type BorrowedIterGroup<'a, K, V> = (RawIter<(K, V)>, Arc<RwLockReadGuard<'a, LowMap<K, V>>>);
type BorrowedIterGroupMut<'a, K, V> = (RawIter<(K, V)>, Arc<RwLockWriteGuard<'a, LowMap<K, V>>>);
/// A borrowed iterator for a [`Skymap`]
pub struct BorrowedIter<'a, K, V, S = ahash::RandomState> {
@ -133,50 +131,6 @@ impl<'a, K, V, S> Iterator for BorrowedIter<'a, K, V, S> {
unsafe impl<'a, K: Send, V: Send, S> Send for BorrowedIter<'a, K, V, S> {}
unsafe impl<'a, K: Sync, V: Sync, S> Sync for BorrowedIter<'a, K, V, S> {}
/// A borrowed iterator with mutable references for a [`Skymap`]
pub struct BorrowedIterMut<'a, K, V, S> {
map: &'a Skymap<K, V, S>,
cs: usize,
citer: Option<BorrowedIterGroupMut<'a, K, V>>,
}
#[allow(unused)] // TODO(@ohsayan): Plonk this
impl<'a, K, V, S> BorrowedIterMut<'a, K, V, S> {
pub const fn new(map: &'a Skymap<K, V, S>) -> Self {
Self {
map,
cs: 0usize,
citer: None,
}
}
}
impl<'a, K, V, S> Iterator for BorrowedIterMut<'a, K, V, S> {
type Item = RefMultiMut<'a, K, V>;
fn next(&mut self) -> Option<Self::Item> {
loop {
if let Some(current) = self.citer.as_mut() {
if let Some(bucket) = current.0.next() {
let (kptr, vptr) = unsafe {
// the lt guarantees that the map will outlive this
// reference
bucket.as_mut()
};
let guard = Arc::clone(&current.1);
return Some(RefMultiMut::new(guard, kptr, vptr));
}
}
if self.cs == self.map.shards().len() {
// reached end of shards
return None;
}
let wshard = unsafe { self.map.get_wshard_unchecked(self.cs) };
let iter = unsafe { wshard.iter() };
self.citer = Some((iter, Arc::new(wshard)));
self.cs += 1;
}
}
}
#[test]
fn test_iter() {
let map = Skymap::default();

@ -39,8 +39,10 @@ use parking_lot::RwLock;
use parking_lot::RwLockReadGuard;
use parking_lot::RwLockWriteGuard;
use std::collections::hash_map::RandomState;
use std::num::NonZeroUsize;
use std::thread::available_parallelism;
pub mod bref;
use iter::{BorrowedIter, BorrowedIterMut, OwnedIter};
use iter::{BorrowedIter, OwnedIter};
pub mod iter;
use bref::{Entry, OccupiedEntry, Ref, RefMut, VacantEntry};
@ -90,7 +92,7 @@ where
}
fn get_shard_count() -> usize {
(num_cpus::get() * 8).next_power_of_two()
(available_parallelism().map_or(1, usize::from) * 16).next_power_of_two()
}
const fn cttz(amount: usize) -> usize {
@ -194,10 +196,6 @@ where
pub fn get_iter(&self) -> BorrowedIter<K, V, S> {
BorrowedIter::new(self)
}
/// Get a borrowed mutable iterator for the Skymap, Bound to the lifetime
pub fn get_iter_mut(&self) -> BorrowedIterMut<K, V, S> {
BorrowedIterMut::new(self)
}
/// Get an owned iterator to the Skymap
pub fn get_owned_iter(self) -> OwnedIter<K, V, S> {
OwnedIter::new(self)

Loading…
Cancel
Save