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

Add Map of Deque #15

Open
webmaster128 opened this issue Oct 19, 2022 · 1 comment
Open

Add Map of Deque #15

webmaster128 opened this issue Oct 19, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@webmaster128
Copy link
Member

Maps and Deques are great. But how to combine them? Both a list of maps and a map of lists are interesting.

In order to get a map of Deques I currently have to use a workaround like this:

/// Add an element to the unprocessed drand jobs queue of this round
pub fn jobs_queue_enqueue(storage: &mut dyn Storage, round: u64, value: &Job) -> StdResult<()> {
    let prefix = format!("drand_jobs_{:0>10}", round);
    Deque::new(&prefix).push_back(storage, value)
}

/// Remove an element from the unprocessed drand jobs queue of this round
pub fn jobs_queue_dequeue(storage: &mut dyn Storage, round: u64) -> StdResult<Option<Job>> {
    let prefix = format!("drand_jobs_{:0>10}", round);
    Deque::new(&prefix).pop_front(storage)
}

I.e. I have to create new Deques on the fly after composing the correct key. It works but does not look beautiful. Wouldn't it be great to make a DequeMap instead which has all the power of key composability of a Map plus many storage items (a deque) per key? That would allow maps of stacks as well as maps of queues.

@uint uint added the enhancement New feature or request label Nov 22, 2022
@TrevorJTClarke
Copy link

Not sure if this is exactly what you're hoping for, but maybe another example/inspiration: https://docs.rs/near-sdk/3.1.0/near_sdk/collections/struct.TreeMap.html
This was very helpful for using things like floor_key

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants