1use super::{base_cache::BaseCache, mapref::EntryRef};
2use crate::common::concurrent::ValueEntry;
3
4use std::{
5 hash::{BuildHasher, Hash},
6 sync::Arc,
7};
8use triomphe::Arc as TrioArc;
9
10pub(crate) type DashMapIter<'a, K, V, S> =
11 dashmap::iter::Iter<'a, Arc<K>, TrioArc<ValueEntry<K, V>>, S>;
12
13pub struct Iter<'a, K, V, S> {
14 cache: &'a BaseCache<K, V, S>,
15 map_iter: DashMapIter<'a, K, V, S>,
16}
17
18impl<'a, K, V, S> Iter<'a, K, V, S> {
19 pub(crate) fn new(cache: &'a BaseCache<K, V, S>, map_iter: DashMapIter<'a, K, V, S>) -> Self {
20 Self { cache, map_iter }
21 }
22}
23
24impl<'a, K, V, S> Iterator for Iter<'a, K, V, S>
25where
26 K: Eq + Hash,
27 S: BuildHasher + Clone,
28{
29 type Item = EntryRef<'a, K, V, S>;
30
31 fn next(&mut self) -> Option<Self::Item> {
32 for map_ref in &mut self.map_iter {
33 if !self.cache.is_expired_entry(map_ref.value()) {
34 return Some(EntryRef::new(map_ref));
35 }
36 }
37
38 None
39 }
40}
41
42unsafe impl<'a, 'i, K, V, S> Send for Iter<'i, K, V, S>
43where
44 K: 'a + Eq + Hash + Send,
45 V: 'a + Send,
46 S: 'a + BuildHasher + Clone,
47{
48}
49
50unsafe impl<'a, 'i, K, V, S> Sync for Iter<'i, K, V, S>
51where
52 K: 'a + Eq + Hash + Sync,
53 V: 'a + Sync,
54 S: 'a + BuildHasher + Clone,
55{
56}