Crates.io | common-cache |
lib.rs | common-cache |
version | |
source | src |
created_at | 2024-11-21 13:47:16.678383 |
updated_at | 2024-11-21 13:47:16.678383 |
description | A hierarchical cache data structure that prioritizes the most commonly used and recently accessed items and can dynamically grow and shrink in size. |
homepage | |
repository | https://github.com/tage64/common-cache |
max_upload_size | |
id | 1456129 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
A hierarchical cache data structure that prioritizes the most commonly used and recently accessed items and can dynamically grow and shrink in size.
This is a small, fast-on-average, and intuitive cache-like structure that keeps and promotes the most commonly and most recently used items.
The structure roughly has the following properties:
You may want to use this data structure if:
One example use case is autocompletion for commands or searches. The cache can remember and autocomplete the most recently and most frequently used commands or queries.
The structure roughly works as follows:
n
is base^n
. However, most levels will usually only be partially filled.l
, remove it and set the insertion level to be the level above l
(if it wasn't already at the top). Then go to step 3.i
in the range [0, base^l)
, where l
is the index of the level (with the top level having index 0). This range corresponds to the size of the level.i
is less than the number of actual elements stored at that level, move the i
-th item on this level to the level below.get
operation, it is removed from its current level and inserted into the level above, following the same algorithm described above. The only difference is that if an item is moved down from the lowest level, a new level is not created, and that item is discarded.