Skip to content

Storage and Data structures #14

@stranger-danger-zamu

Description

@stranger-danger-zamu

Data Structs

You have comments about using a std::collections::Vec, from what I know it's a perfectly serviceable stack. You could spring for std::collections::VecDeque instead so you can properly cycle (ie. moving the top most to the bottom) instead of swapping the first and second items.

You could also spring for a std::collections::BTreeMap where the key would be the position in the stack and the BTreeMap would naturally just sort the items for you. Moving items in the stack becomes more expensive if it isn't a limited operation (ie. swapping the first two items or cycling the top to the bottom since you can just get the bottom most key and "decrement" from there). But everything is a trade off.


Storage

Currently you store every item as a JSON object in a JSON array and write that to disk. There was some comment about scaling beyond 10k items (or stacks, I can't remember), but that might just be disk access. You could glue everything into one big JSON object and only read and/or write once per CLI evocation. You could just glue the related stacks together since you don't need to deal with cross stack transfers outside of related stacks.

For anything more robust, you probably are best off utilizing SQLite. Note, you don't have to do anything fancy for the schema, you could just do a single key-value table where the key would be "equivalent" to the file path and the value would be the content. You do get transactions so concurrent access is viable of you set journal_mode to WAL.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions