mirror of
https://github.com/hinto-janai/cuprate.git
synced 2025-01-22 10:34:37 +00:00
remove get_range
This commit is contained in:
parent
01150ab84c
commit
7200dc08ba
5 changed files with 24 additions and 12 deletions
|
@ -1,7 +1,7 @@
|
||||||
//! Implementation of `trait Database` for `heed`.
|
//! Implementation of `trait Database` for `heed`.
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- Import
|
//---------------------------------------------------------------------------------------------------- Import
|
||||||
use std::{cell::RefCell, ops::RangeBounds};
|
use std::cell::RefCell;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
backend::heed::types::HeedDb,
|
backend::heed::types::HeedDb,
|
||||||
|
@ -96,6 +96,7 @@ fn is_empty<T: Table>(
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- DatabaseIter Impl
|
//---------------------------------------------------------------------------------------------------- DatabaseIter Impl
|
||||||
impl<T: Table> DatabaseIter<T> for HeedTableRo<'_, T> {
|
impl<T: Table> DatabaseIter<T> for HeedTableRo<'_, T> {
|
||||||
|
/*
|
||||||
#[inline]
|
#[inline]
|
||||||
fn get_range<'a, Range>(
|
fn get_range<'a, Range>(
|
||||||
&'a self,
|
&'a self,
|
||||||
|
@ -107,6 +108,8 @@ impl<T: Table> DatabaseIter<T> for HeedTableRo<'_, T> {
|
||||||
Ok(self.db.range(self.tx_ro, &range)?.map(|res| Ok(res?.1)))
|
Ok(self.db.range(self.tx_ro, &range)?.map(|res| Ok(res?.1)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn iter(
|
fn iter(
|
||||||
&self,
|
&self,
|
||||||
|
|
|
@ -65,6 +65,7 @@ fn is_empty<T: Table>(
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- DatabaseIter
|
//---------------------------------------------------------------------------------------------------- DatabaseIter
|
||||||
impl<T: Table + 'static> DatabaseIter<T> for RedbTableRo<T::Key, T::Value> {
|
impl<T: Table + 'static> DatabaseIter<T> for RedbTableRo<T::Key, T::Value> {
|
||||||
|
/*
|
||||||
#[inline]
|
#[inline]
|
||||||
fn get_range<'a, Range>(
|
fn get_range<'a, Range>(
|
||||||
&'a self,
|
&'a self,
|
||||||
|
@ -79,6 +80,8 @@ impl<T: Table + 'static> DatabaseIter<T> for RedbTableRo<T::Key, T::Value> {
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn iter(
|
fn iter(
|
||||||
&self,
|
&self,
|
||||||
|
|
|
@ -34,8 +34,14 @@ impl<T> redb::Value for StorableRedb<T>
|
||||||
where
|
where
|
||||||
T: Storable + 'static,
|
T: Storable + 'static,
|
||||||
{
|
{
|
||||||
type SelfType<'a> = T where Self: 'a;
|
type SelfType<'a>
|
||||||
type AsBytes<'a> = &'a [u8] where Self: 'a;
|
= T
|
||||||
|
where
|
||||||
|
Self: 'a;
|
||||||
|
type AsBytes<'a>
|
||||||
|
= &'a [u8]
|
||||||
|
where
|
||||||
|
Self: 'a;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn fixed_width() -> Option<usize> {
|
fn fixed_width() -> Option<usize> {
|
||||||
|
|
|
@ -225,7 +225,7 @@ fn db_read_write() {
|
||||||
|
|
||||||
// Assert the whole range is there.
|
// Assert the whole range is there.
|
||||||
{
|
{
|
||||||
let range = table_ro.get_range(..).unwrap();
|
let range = table_ro.values().unwrap();
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
for result in range {
|
for result in range {
|
||||||
let value = result.unwrap();
|
let value = result.unwrap();
|
||||||
|
@ -241,14 +241,11 @@ fn db_read_write() {
|
||||||
let range = KEY..key;
|
let range = KEY..key;
|
||||||
|
|
||||||
// Assert count is correct.
|
// Assert count is correct.
|
||||||
assert_eq!(
|
assert_eq!(N as usize, table_ro.values().unwrap().count());
|
||||||
N as usize,
|
|
||||||
table_ro.get_range(range.clone()).unwrap().count()
|
|
||||||
);
|
|
||||||
|
|
||||||
// Assert each returned value from the iterator is owned.
|
// Assert each returned value from the iterator is owned.
|
||||||
{
|
{
|
||||||
let mut iter = table_ro.get_range(range.clone()).unwrap();
|
let mut iter = table_ro.values().unwrap();
|
||||||
let value = iter.next().unwrap().unwrap(); // 1. take value out
|
let value = iter.next().unwrap().unwrap(); // 1. take value out
|
||||||
drop(iter); // 2. drop the `impl Iterator + 'a`
|
drop(iter); // 2. drop the `impl Iterator + 'a`
|
||||||
assert_value(value); // 3. assert even without the iterator, the value is alive
|
assert_value(value); // 3. assert even without the iterator, the value is alive
|
||||||
|
@ -256,7 +253,7 @@ fn db_read_write() {
|
||||||
|
|
||||||
// Assert each value is the same.
|
// Assert each value is the same.
|
||||||
{
|
{
|
||||||
let mut iter = table_ro.get_range(range).unwrap();
|
let mut iter = table_ro.values().unwrap();
|
||||||
for _ in 0..N {
|
for _ in 0..N {
|
||||||
let value = iter.next().unwrap().unwrap();
|
let value = iter.next().unwrap().unwrap();
|
||||||
assert_value(value);
|
assert_value(value);
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
//! Abstracted database table operations; `trait DatabaseRo` & `trait DatabaseRw`.
|
//! Abstracted database table operations; `trait DatabaseRo` & `trait DatabaseRw`.
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- Import
|
//---------------------------------------------------------------------------------------------------- Import
|
||||||
use std::ops::RangeBounds;
|
|
||||||
|
|
||||||
use crate::{error::RuntimeError, table::Table};
|
use crate::{error::RuntimeError, table::Table};
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------- DatabaseIter
|
//---------------------------------------------------------------------------------------------------- DatabaseIter
|
||||||
|
@ -32,6 +30,9 @@ Each iteration of the iterator has the potential to error as well."
|
||||||
/// - <https://github.com/Cuprate/cuprate/pull/102#discussion_r1548695610>
|
/// - <https://github.com/Cuprate/cuprate/pull/102#discussion_r1548695610>
|
||||||
/// - <https://github.com/Cuprate/cuprate/pull/104>
|
/// - <https://github.com/Cuprate/cuprate/pull/104>
|
||||||
pub trait DatabaseIter<T: Table> {
|
pub trait DatabaseIter<T: Table> {
|
||||||
|
/*
|
||||||
|
FIXME: <https://github.com/Cuprate/cuprate/issues/348>
|
||||||
|
|
||||||
/// Get an [`Iterator`] of value's corresponding to a range of keys.
|
/// Get an [`Iterator`] of value's corresponding to a range of keys.
|
||||||
///
|
///
|
||||||
/// For example:
|
/// For example:
|
||||||
|
@ -52,6 +53,8 @@ pub trait DatabaseIter<T: Table> {
|
||||||
where
|
where
|
||||||
Range: RangeBounds<T::Key> + 'a;
|
Range: RangeBounds<T::Key> + 'a;
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
/// Get an [`Iterator`] that returns the `(key, value)` types for this database.
|
/// Get an [`Iterator`] that returns the `(key, value)` types for this database.
|
||||||
#[doc = doc_iter!()]
|
#[doc = doc_iter!()]
|
||||||
#[expect(clippy::iter_not_returning_iterator)]
|
#[expect(clippy::iter_not_returning_iterator)]
|
||||||
|
|
Loading…
Reference in a new issue