simplify iterator state constructor arguments

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk
2025-01-10 07:03:34 +00:00
parent cc1889d135
commit 685b127f99
10 changed files with 23 additions and 19 deletions
+5 -1
View File
@@ -77,7 +77,11 @@ pub fn property(&self, name: &str) -> Result<String> { self.db.property(&self.cf
#[inline]
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 {
+1 -1
View File
@@ -23,7 +23,7 @@ pub fn raw_keys(self: &Arc<Self>) -> impl Stream<Item = Result<Key<'_>>> + Send
use crate::pool::Seek;
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) {
let state = state.init_fwd(None);
return task::consume_budget()
+1 -1
View File
@@ -54,7 +54,7 @@ pub fn raw_keys_from<P>(self: &Arc<Self>, from: &P) -> impl Stream<Item = Result
use crate::pool::Seek;
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) {
return stream::Keys::<'_>::from(state.init_fwd(from.as_ref().into())).boxed();
}
+1 -1
View File
@@ -23,7 +23,7 @@ pub fn rev_raw_keys(self: &Arc<Self>) -> impl Stream<Item = Result<Key<'_>>> + S
use crate::pool::Seek;
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) {
let state = state.init_rev(None);
return task::consume_budget()
+1 -1
View File
@@ -62,7 +62,7 @@ pub fn rev_raw_keys_from<P>(
use crate::pool::Seek;
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) {
return stream::KeysRev::<'_>::from(state.init_rev(from.as_ref().into())).boxed();
}
+3 -3
View File
@@ -32,7 +32,7 @@ pub fn rev_raw_stream(self: &Arc<Self>) -> impl Stream<Item = Result<KeyVal<'_>>
use crate::pool::Seek;
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) {
let state = state.init_rev(None);
return task::consume_budget()
@@ -65,9 +65,9 @@ pub fn rev_raw_stream(self: &Arc<Self>) -> impl Stream<Item = Result<KeyVal<'_>>
skip_all,
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 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()
}
+2 -2
View File
@@ -81,7 +81,7 @@ pub fn rev_raw_stream_from<P>(
use crate::pool::Seek;
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) {
let state = state.init_rev(from.as_ref().into());
return task::consume_budget()
@@ -119,7 +119,7 @@ pub(super) fn is_cached<P>(map: &Arc<super::Map>, from: &P) -> bool
P: AsRef<[u8]> + ?Sized,
{
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())
.status();
+3 -3
View File
@@ -31,7 +31,7 @@ pub fn raw_stream(self: &Arc<Self>) -> impl Stream<Item = Result<KeyVal<'_>>> +
use crate::pool::Seek;
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) {
let state = state.init_fwd(None);
return task::consume_budget()
@@ -64,9 +64,9 @@ pub fn raw_stream(self: &Arc<Self>) -> impl Stream<Item = Result<KeyVal<'_>>> +
skip_all,
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 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()
}
+2 -2
View File
@@ -78,7 +78,7 @@ pub fn raw_stream_from<P>(
use crate::pool::Seek;
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) {
let state = state.init_fwd(from.as_ref().into());
return task::consume_budget()
@@ -116,7 +116,7 @@ pub(super) fn is_cached<P>(map: &Arc<super::Map>, from: &P) -> bool
P: AsRef<[u8]> + ?Sized,
{
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()
}
+4 -4
View File
@@ -6,14 +6,14 @@
use std::sync::Arc;
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};
use crate::{
engine::Db,
keyval::{Key, KeyVal, Val},
util::{is_incomplete, map_err},
Engine, Slice,
Map, Slice,
};
pub(crate) struct State<'a> {
@@ -45,9 +45,9 @@ fn seek_and_get(&mut self) -> Option<Result<T>> {
type From<'a> = Option<Key<'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 {
inner: db.db.raw_iterator_cf_opt(&**cf, opts),
inner: map.db().db.raw_iterator_cf_opt(&map.cf(), opts),
init: true,
seek: false,
}