Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entry API for cuprate_database #181

Open
hinto-janai opened this issue Jun 20, 2024 · 0 comments
Open

Entry API for cuprate_database #181

hinto-janai opened this issue Jun 20, 2024 · 0 comments
Labels
A-storage Related to storage. C-proposal A proposal of some kind, and a request for comments. E-help-wanted Call for participation: Help is requested to fix this issue. E-medium Medium difficulty. Experience needed to fix: Intermediate.

Comments

@hinto-janai
Copy link
Contributor

hinto-janai commented Jun 20, 2024

What

This proposal describes a new std::collections::btree_map::Entry-like API to be added to cuprate_database.

3 public types will be added:

  • enum Entry
  • struct OccupiedEntry
  • struct VacantEntry

The API for these types will closely resemble std's API.

Where

Added onto the cuprate_database::DatabaseRw trait:

// where
//     T: Table
fn entry(&mut self, key: &T::Key) -> Entry<'_, T>;

This replaces functions like DatabaseRw::update:

fn update<F>(&mut self, key: &T::Key, mut f: F) -> Result<(), RuntimeError>

and some awkward code:

// FIXME: this would be much better expressed with a
// `btree_map::Entry`-like API, fix `trait DatabaseRw`.
let num_outputs = match tables.num_outputs().get(&amount) {
// Entry with `amount` already exists.
Ok(num_outputs) => num_outputs,
// Entry with `amount` didn't exist, this is
// the 1st output with this amount.
Err(RuntimeError::KeyNotFound) => 0,
Err(e) => return Err(e),
};

Why

All the same reasons why std::collections::btree_map::Entry exists.

@hinto-janai hinto-janai added A-storage Related to storage. C-tracking-issue An issue tracking a wider effort labels Jun 20, 2024
@hinto-janai hinto-janai self-assigned this Jun 20, 2024
@hinto-janai hinto-janai added C-proposal A proposal of some kind, and a request for comments. and removed C-tracking-issue An issue tracking a wider effort labels Jun 20, 2024
@hinto-janai hinto-janai removed their assignment Sep 11, 2024
@hinto-janai hinto-janai added E-medium Medium difficulty. Experience needed to fix: Intermediate. E-help-wanted Call for participation: Help is requested to fix this issue. labels Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-storage Related to storage. C-proposal A proposal of some kind, and a request for comments. E-help-wanted Call for participation: Help is requested to fix this issue. E-medium Medium difficulty. Experience needed to fix: Intermediate.
Projects
None yet
Development

No branches or pull requests

1 participant