Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace ritelinked with hashlink #12254

Merged
merged 2 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 21 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/common/cache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ test = false

[features]
heapsize = ["heapsize_"]
amortized = ["ritelinked/ahash-amortized", "ritelinked/inline-more-amortized"]

[dependencies]

# Crates.io dependencies
ritelinked = { version = "0.3.2", default-features = false, features = ["ahash", "inline-more"] }
hashbrown = "0.14"
hashlink = "0.8"

[target.'cfg(not(target_os = "macos"))'.dependencies]
heapsize_ = { package = "heapsize", version = "0.4.2", optional = true }
Expand Down
16 changes: 11 additions & 5 deletions src/common/cache/src/cache/lru.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ use std::fmt;
use std::hash::BuildHasher;
use std::hash::Hash;

use ritelinked::linked_hash_map;
use ritelinked::DefaultHashBuilder;
use ritelinked::LinkedHashMap;
use hashbrown::hash_map::DefaultHashBuilder;
use hashlink::linked_hash_map;
use hashlink::LinkedHashMap;

use crate::cache::Cache;
use crate::meter::count_meter::Count;
Expand Down Expand Up @@ -195,7 +195,7 @@ impl<K: Eq + Hash, V, S: BuildHasher, M: CountableMeter<K, V>> Cache<K, V, S, M>
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
{
self.map.get_refresh(k).map(|v| v as &V)
self.get_mut(k).map(|v| &*v)
}

/// Returns a mutable reference to the value corresponding to the given key in the cache, if
Expand Down Expand Up @@ -224,7 +224,13 @@ impl<K: Eq + Hash, V, S: BuildHasher, M: CountableMeter<K, V>> Cache<K, V, S, M>
K: Borrow<Q>,
Q: Hash + Eq + ?Sized,
{
self.map.get_refresh(k)
match self.map.raw_entry_mut().from_key(k) {
linked_hash_map::RawEntryMut::Occupied(mut occupied) => {
occupied.to_back();
Some(occupied.into_mut())
}
linked_hash_map::RawEntryMut::Vacant(_) => None,
}
}

/// Returns a reference to the value corresponding to the key in the cache or `None` if it is
Expand Down
2 changes: 1 addition & 1 deletion src/common/cache/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ mod meter;

pub use cache::lru::LruCache;
pub use cache::Cache;
pub use hashbrown::hash_map::DefaultHashBuilder;
pub use meter::bytes_meter::BytesMeter;
pub use meter::count_meter::Count;
pub use meter::count_meter::CountableMeter;
Expand All @@ -32,4 +33,3 @@ pub use meter::file_meter::FileSize;
#[cfg(not(target_os = "macos"))]
pub use meter::heap_meter::HeapSize;
pub use meter::Meter;
pub use ritelinked::DefaultHashBuilder;
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl From<&DiskCacheKey> for PathBuf {
impl<C> DiskCache<C>
where C: Cache<String, u64, DefaultHashBuilder, FileSize>
{
/// Create an `DiskCache` with `ritelinked::DefaultHashBuilder` that stores files in `path`,
/// Create an `DiskCache` with `hashbrown::hash_map::DefaultHashBuilder` that stores files in `path`,
/// limited to `size` bytes.
///
/// Existing files in `path` will be stored with their last-modified time from the filesystem
Expand Down
4 changes: 2 additions & 2 deletions src/query/storages/common/cache/src/providers/memory_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl InMemoryCacheBuilder {
where
M: CountableMeter<String, Arc<V>>,
{
let cache = LruCache::with_meter_and_hasher(capacity, meter, DefaultHashBuilder::new());
let cache = LruCache::with_meter_and_hasher(capacity, meter, DefaultHashBuilder::default());
Arc::new(RwLock::new(cache))
}

Expand All @@ -53,7 +53,7 @@ impl InMemoryCacheBuilder {
// new cache that cache `Vec<u8>`, and metered by byte size
pub fn new_bytes_cache(capacity: u64) -> InMemoryBytesCacheHolder {
let cache =
LruCache::with_meter_and_hasher(capacity, BytesMeter, DefaultHashBuilder::new());
LruCache::with_meter_and_hasher(capacity, BytesMeter, DefaultHashBuilder::default());
Arc::new(RwLock::new(cache))
}
}
Expand Down