Skip to content

Add Map of Deque #15

@webmaster128

Description

@webmaster128

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions