Switch iter and iter_from in database interface to range() #106

Closed
opened 2021-07-13 18:06:35 +00:00 by shadowjonathan · 4 comments
shadowjonathan commented 2021-07-13 18:06:35 +00:00 (Migrated from gitlab.com)

RangeBounds (everything in rust that is .., a..b, ..c, etc.) is more explicit about it's range inclusion/exclusion, for a while, iter_from was not.

I'd like to change the interface to be a little more explicit and flexible, to something like .range(..=prefix).

.iter() would become .range(..), .iter_from(prefix, false) would become .range(prefix..)

I'd like to implement the "backwards" flag into something idiomatic, that you could do .range(..=prefix).reverse() then. Though not with double-ended iterators, as currently sqlite makes it impossible to make those, so it's better to have an explicit forwards-going or backwards-going iterator.

`RangeBounds` (everything in rust that is `..`, `a..b`, `..c`, etc.) is more explicit about it's range inclusion/exclusion, for a while, `iter_from` was not. I'd like to change the interface to be a little more explicit and flexible, to something like `.range(..=prefix)`. `.iter()` would become `.range(..)`, `.iter_from(prefix, false)` would become `.range(prefix..)` I'd like to implement the "backwards" flag into something idiomatic, that you could do `.range(..=prefix).reverse()` then. Though not with double-ended iterators, as currently sqlite makes it impossible to make those, so it's better to have an explicit forwards-going or backwards-going iterator.
shadowjonathan commented 2021-07-13 18:06:35 +00:00 (Migrated from gitlab.com)

assigned to @jonathandejong02

assigned to @jonathandejong02
shadowjonathan commented 2021-07-14 10:40:31 +00:00 (Migrated from gitlab.com)

Hmm, half-open ranges don't seem to be stable yet; https://caniuse.rs/features/half_open_range_patterns

Hmm, half-open ranges don't seem to be stable yet; https://caniuse.rs/features/half_open_range_patterns
ahmedcharles commented 2021-08-12 01:33:16 +00:00 (Migrated from gitlab.com)

I gave this some thought:

  1. Tree is a trait object, so it can't have a range function which takes a template parameter. This necessitates a wrapper to convert from the range bounds to a single common representation. This can be a wrapper class that contains an Arc<dyn Tree> with forwarding functions.
  2. Some range bounds are invalid, like range(..b), which can be fixed by having a custom trait for only the supported bounds.
  3. I think it would be better to support reverse via tree.rev().range(a..), which allows avoiding runtime errors by preventing something like tree.range(a..).rev() or simply tree.range(..b).
I gave this some thought: 1. `Tree` is a trait object, so it can't have a range function which takes a template parameter. This necessitates a wrapper to convert from the range bounds to a single common representation. This can be a wrapper class that contains an `Arc<dyn Tree>` with forwarding functions. 2. Some range bounds are invalid, like `range(..b)`, which can be fixed by having a custom trait for only the supported bounds. 3. I think it would be better to support reverse via `tree.rev().range(a..)`, which allows avoiding runtime errors by preventing something like `tree.range(a..).rev()` or simply `tree.range(..b)`.
tglman commented 2021-08-12 20:08:11 +00:00 (Migrated from gitlab.com)

Hi,

It should be possible to implement this with a signature like:

    fn range<'a, R:RangeBounds<Vec<u8>>>(&'a self, range:R) -> Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + 'a>
        where Self:Sized;

the 'where' condition allow to have the range bound on the trait, so the 1 problem can be excluded

hope this help.

Regards

Hi, It should be possible to implement this with a signature like: ``` fn range<'a, R:RangeBounds<Vec<u8>>>(&'a self, range:R) -> Box<dyn Iterator<Item = (Vec<u8>, Vec<u8>)> + 'a> where Self:Sized; ``` the 'where' condition allow to have the range bound on the trait, so the 1 problem can be excluded hope this help. Regards
Sign in to join this conversation.
No labels
Android
CS::needs customer feedback
CS::needs follow up
CS::needs on prem installation
CS::waiting
Chrome
Design:: Ready
Design:: in progress
Design::UX
E2EE
Edge
Firefox
GDPR
Iteration 13 IM
Linux
MacOS
Need::Discussion
Need::Steps to reproduce
Need::Upstream fix
Needs:: Planning
Needs::Dev-Team
Needs::More information
Needs::Priority
Needs::Product
Needs::Refinement
Needs::Severity
Priority::1-Critical
Priority::2-Max
Priority::3-Impending
Priority::4-High
Priority::5-Medium
Priority::6-Low
Priority::7-None
Progress::Backlog
Progress::Review
Progress::Started
Progress::Testing
Progress::Triage
Progress::Waiting
Reporter::Sentry
Safari
Target::Community
Target::Customer
Target::Internal
Target::PoC
Target::Security
Team:Customer-Success
Team:Design
Team:Infrastructure
Team:Instant-Messaging
Team:Product
Team:Workflows
Type::Bug
Type::Design
Type::Documentation
Type::Feature
Type::Improvement
Type::Support
Type::Tests
Windows
blocked
blocked-by-spec
cla-signed
conduit
contribution::advanced
contribution::easy
contribution::help needed
from::review
iOS
p::ti-tenant
performance
product::triage
proposal
refactor
release-blocker
s: dart_openapi_codegen
s::Famedly-Patient
s::Org-Directory
s::Passport-Generator
s::Requeuest
s:CRM
s:Famedly-App
s:Famedly-Web
s:Fhiroxide
s:Fhiroxide-cli
s:Fhiroxide-client
s:Fhirs
s:Hedwig
s:LISA
s:Matrix-Dart-SDK
s:Role-Manager
s:Synapse
s:User-Directory
s:WFS-Matrix
s:Workflow Engine
s:dtls
s:famedly-error
s:fcm-shared-isolate
s:matrix-api-lite
s:multiple-tab-detector
s:native-imaging
severity::1
severity::2
severity::3
severity::4
technical-debt
voip
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Matthias/conduit#106
No description provided.