simplify iterator state constructor arguments

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2025-01-06 05:12:01 +00:00
parent cc1889d135
commit 685b127f99
10 changed files with 23 additions and 19 deletions

View file

@ -77,7 +77,11 @@ impl Map {
#[inline] #[inline]
pub fn name(&self) -> &str { &self.name } pub fn name(&self) -> &str { &self.name }
fn cf(&self) -> impl AsColumnFamilyRef + '_ { &*self.cf } #[inline]
pub(crate) fn db(&self) -> &Arc<Engine> { &self.db }
#[inline]
pub(crate) fn cf(&self) -> impl AsColumnFamilyRef + '_ { &*self.cf }
} }
impl Debug for Map { impl Debug for Map {

View file

@ -23,7 +23,7 @@ pub fn raw_keys(self: &Arc<Self>) -> impl Stream<Item = Result<Key<'_>>> + Send
use crate::pool::Seek; use crate::pool::Seek;
let opts = super::iter_options_default(); let opts = super::iter_options_default();
let state = stream::State::new(&self.db, &self.cf, opts); let state = stream::State::new(self, opts);
if is_cached(self) { if is_cached(self) {
let state = state.init_fwd(None); let state = state.init_fwd(None);
return task::consume_budget() return task::consume_budget()

View file

@ -54,7 +54,7 @@ where
use crate::pool::Seek; use crate::pool::Seek;
let opts = super::iter_options_default(); let opts = super::iter_options_default();
let state = stream::State::new(&self.db, &self.cf, opts); let state = stream::State::new(self, opts);
if is_cached(self, from) { if is_cached(self, from) {
return stream::Keys::<'_>::from(state.init_fwd(from.as_ref().into())).boxed(); return stream::Keys::<'_>::from(state.init_fwd(from.as_ref().into())).boxed();
} }

View file

@ -23,7 +23,7 @@ pub fn rev_raw_keys(self: &Arc<Self>) -> impl Stream<Item = Result<Key<'_>>> + S
use crate::pool::Seek; use crate::pool::Seek;
let opts = super::iter_options_default(); let opts = super::iter_options_default();
let state = stream::State::new(&self.db, &self.cf, opts); let state = stream::State::new(self, opts);
if is_cached(self) { if is_cached(self) {
let state = state.init_rev(None); let state = state.init_rev(None);
return task::consume_budget() return task::consume_budget()

View file

@ -62,7 +62,7 @@ where
use crate::pool::Seek; use crate::pool::Seek;
let opts = super::iter_options_default(); let opts = super::iter_options_default();
let state = stream::State::new(&self.db, &self.cf, opts); let state = stream::State::new(self, opts);
if is_cached(self, from) { if is_cached(self, from) {
return stream::KeysRev::<'_>::from(state.init_rev(from.as_ref().into())).boxed(); return stream::KeysRev::<'_>::from(state.init_rev(from.as_ref().into())).boxed();
} }

View file

@ -32,7 +32,7 @@ pub fn rev_raw_stream(self: &Arc<Self>) -> impl Stream<Item = Result<KeyVal<'_>>
use crate::pool::Seek; use crate::pool::Seek;
let opts = super::read_options_default(); let opts = super::read_options_default();
let state = stream::State::new(&self.db, &self.cf, opts); let state = stream::State::new(self, opts);
if is_cached(self) { if is_cached(self) {
let state = state.init_rev(None); let state = state.init_rev(None);
return task::consume_budget() return task::consume_budget()
@ -65,9 +65,9 @@ pub fn rev_raw_stream(self: &Arc<Self>) -> impl Stream<Item = Result<KeyVal<'_>>
skip_all, skip_all,
fields(%map), fields(%map),
)] )]
pub(super) fn is_cached(map: &super::Map) -> bool { pub(super) fn is_cached(map: &Arc<super::Map>) -> bool {
let opts = super::cache_read_options_default(); let opts = super::cache_read_options_default();
let state = stream::State::new(&map.db, &map.cf, opts).init_rev(None); let state = stream::State::new(map, opts).init_rev(None);
!state.is_incomplete() !state.is_incomplete()
} }

View file

@ -81,7 +81,7 @@ where
use crate::pool::Seek; use crate::pool::Seek;
let opts = super::iter_options_default(); let opts = super::iter_options_default();
let state = stream::State::new(&self.db, &self.cf, opts); let state = stream::State::new(self, opts);
if is_cached(self, from) { if is_cached(self, from) {
let state = state.init_rev(from.as_ref().into()); let state = state.init_rev(from.as_ref().into());
return task::consume_budget() return task::consume_budget()
@ -119,7 +119,7 @@ where
P: AsRef<[u8]> + ?Sized, P: AsRef<[u8]> + ?Sized,
{ {
let cache_opts = super::cache_read_options_default(); let cache_opts = super::cache_read_options_default();
let cache_status = stream::State::new(&map.db, &map.cf, cache_opts) let cache_status = stream::State::new(map, cache_opts)
.init_rev(from.as_ref().into()) .init_rev(from.as_ref().into())
.status(); .status();

View file

@ -31,7 +31,7 @@ pub fn raw_stream(self: &Arc<Self>) -> impl Stream<Item = Result<KeyVal<'_>>> +
use crate::pool::Seek; use crate::pool::Seek;
let opts = super::read_options_default(); let opts = super::read_options_default();
let state = stream::State::new(&self.db, &self.cf, opts); let state = stream::State::new(self, opts);
if is_cached(self) { if is_cached(self) {
let state = state.init_fwd(None); let state = state.init_fwd(None);
return task::consume_budget() return task::consume_budget()
@ -64,9 +64,9 @@ pub fn raw_stream(self: &Arc<Self>) -> impl Stream<Item = Result<KeyVal<'_>>> +
skip_all, skip_all,
fields(%map), fields(%map),
)] )]
pub(super) fn is_cached(map: &super::Map) -> bool { pub(super) fn is_cached(map: &Arc<super::Map>) -> bool {
let opts = super::cache_read_options_default(); let opts = super::cache_read_options_default();
let state = stream::State::new(&map.db, &map.cf, opts).init_fwd(None); let state = stream::State::new(map, opts).init_fwd(None);
!state.is_incomplete() !state.is_incomplete()
} }

View file

@ -78,7 +78,7 @@ where
use crate::pool::Seek; use crate::pool::Seek;
let opts = super::read_options_default(); let opts = super::read_options_default();
let state = stream::State::new(&self.db, &self.cf, opts); let state = stream::State::new(self, opts);
if is_cached(self, from) { if is_cached(self, from) {
let state = state.init_fwd(from.as_ref().into()); let state = state.init_fwd(from.as_ref().into());
return task::consume_budget() return task::consume_budget()
@ -116,7 +116,7 @@ where
P: AsRef<[u8]> + ?Sized, P: AsRef<[u8]> + ?Sized,
{ {
let opts = super::cache_read_options_default(); let opts = super::cache_read_options_default();
let state = stream::State::new(&map.db, &map.cf, opts).init_fwd(from.as_ref().into()); let state = stream::State::new(map, opts).init_fwd(from.as_ref().into());
!state.is_incomplete() !state.is_incomplete()
} }

View file

@ -6,14 +6,14 @@ mod keys_rev;
use std::sync::Arc; use std::sync::Arc;
use conduwuit::{utils::exchange, Result}; use conduwuit::{utils::exchange, Result};
use rocksdb::{ColumnFamily, DBRawIteratorWithThreadMode, ReadOptions}; use rocksdb::{DBRawIteratorWithThreadMode, ReadOptions};
pub(crate) use self::{items::Items, items_rev::ItemsRev, keys::Keys, keys_rev::KeysRev}; pub(crate) use self::{items::Items, items_rev::ItemsRev, keys::Keys, keys_rev::KeysRev};
use crate::{ use crate::{
engine::Db, engine::Db,
keyval::{Key, KeyVal, Val}, keyval::{Key, KeyVal, Val},
util::{is_incomplete, map_err}, util::{is_incomplete, map_err},
Engine, Slice, Map, Slice,
}; };
pub(crate) struct State<'a> { pub(crate) struct State<'a> {
@ -45,9 +45,9 @@ type Inner<'a> = DBRawIteratorWithThreadMode<'a, Db>;
type From<'a> = Option<Key<'a>>; type From<'a> = Option<Key<'a>>;
impl<'a> State<'a> { impl<'a> State<'a> {
pub(super) fn new(db: &'a Arc<Engine>, cf: &'a Arc<ColumnFamily>, opts: ReadOptions) -> Self { pub(super) fn new(map: &'a Arc<Map>, opts: ReadOptions) -> Self {
Self { Self {
inner: db.db.raw_iterator_cf_opt(&**cf, opts), inner: map.db().db.raw_iterator_cf_opt(&map.cf(), opts),
init: true, init: true,
seek: false, seek: false,
} }