Skip to content

Commit

Permalink
gears level of kv_store
Browse files Browse the repository at this point in the history
  • Loading branch information
NYBACHOK committed Oct 10, 2024
1 parent ca34f23 commit 1a84664
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 2 deletions.
5 changes: 5 additions & 0 deletions gears/src/types/store/gas/range/infallible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ pub struct RangeIter<'a, DB> {
}

impl<DB> RangeIter<'_, DB> {
pub fn rev_iter(mut self) -> Self {
self.range = self.range.rev_iter();
self
}

pub fn error(&self) -> Option<&GasStoreErrors> {
self.err.as_ref()
}
Expand Down
12 changes: 12 additions & 0 deletions gears/src/types/store/gas/range/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ pub struct GasRange<'a, DB> {
guard: GasGuard,
}

impl<'a, DB> GasRange<'a, DB> {
pub fn rev_iter(self) -> Self {
let Self { inner, guard } = self;
let inner = match inner {
RangeBackend::Kv(range) => RangeBackend::Kv(range.rev_iter()),
RangeBackend::Prefix(range) => RangeBackend::Prefix(range.rev_iter()),
};

Self { inner, guard }
}
}

impl<'a, DB> GasRange<'a, DB> {
pub(super) fn new_kv(inner: Range<'a, DB>, guard: GasGuard) -> Self {
Self {
Expand Down
8 changes: 8 additions & 0 deletions gears/src/types/store/range/infallible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ enum InfallibleRangeBackend<'a, DB> {
pub struct RangeIter<'a, DB>(InfallibleRangeBackend<'a, DB>);

impl<DB> RangeIter<'_, DB> {
pub fn rev_iter(self) -> Self {
match self.0 {
InfallibleRangeBackend::Gas(range) => range.rev_iter().into(),
InfallibleRangeBackend::Kv(range) => range.rev_iter().into(),
InfallibleRangeBackend::Prefix(range) => range.rev_iter().into(),
}
}

pub fn error(&self) -> Option<GasStoreErrors> {
match &self.0 {
InfallibleRangeBackend::Gas(var) => var.error().cloned(),
Expand Down
10 changes: 9 additions & 1 deletion gears/src/types/store/range/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod infallible;
pub mod result;

use std::borrow::Cow;

use database::Database;
Expand All @@ -19,6 +19,14 @@ enum StoreRangeBackend<'a, DB> {
pub struct StoreRange<'a, DB>(StoreRangeBackend<'a, DB>);

impl<'a, DB> StoreRange<'a, DB> {
pub fn rev_iter(self) -> Self {
match self.0 {
StoreRangeBackend::Gas(range) => range.rev_iter().into(),
StoreRangeBackend::Kv(range) => range.rev_iter().into(),
StoreRangeBackend::Prefix(range) => range.rev_iter().into(),
}
}

pub fn to_infallible_iter(self) -> RangeIter<'a, DB> {
match self.0 {
StoreRangeBackend::Gas(var) => var.to_infallible_iter().into(),
Expand Down
1 change: 0 additions & 1 deletion gears/src/types/store/range/result.rs

This file was deleted.

7 changes: 7 additions & 0 deletions kv_store/src/store/prefix/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ pub struct PrefixRange<'a, DB> {
pub(crate) prefix_length: usize,
}

impl<DB> PrefixRange<'_, DB> {
pub fn rev_iter(mut self) -> Self {
self.parent_range = self.parent_range.rev_iter();
self
}
}

impl<'a, DB: Database> Iterator for PrefixRange<'a, DB> {
type Item = (Cow<'a, Vec<u8>>, Cow<'a, Vec<u8>>);

Expand Down

0 comments on commit 1a84664

Please sign in to comment.