Trending

World technology news

→
A Maximite microcontroller board illustrating a memory-constrained target.
crates.ioIn-depth report

fixed-hashmap 0.1.0 publishes Rust software for fixed-capacity key-value storage

The Rust package stores fixed-size byte keys and values in buffers supplied and managed by its caller.

·crates.io
Reading progress0%

A Rust package with a fixed memory contract

fixed-hashmap 0.1.0 was published on crates.io on November 29 at 02:55:54 UTC, or 05:55:54 in Istanbul. It stores fixed-size byte keys and values in storage supplied by the caller. Docs.rs separately records a successful documentation build for the version. The generated API exposes storage and insertion errors as separate types. The publication and documentation build establish which package was distributed. The application still needs to check its own target, memory layout and runtime behavior.

The caller provides both storage areas

The documented example uses two-byte keys and two-byte values. It allocates a slot array and a separate tag buffer before constructing the map. The buffers stay under the caller’s storage plan. If it is used on a microcontroller, budget for the entries and tags together. Check the available stack or longer-lived storage for larger capacities. The map cannot outlive the memory the caller supplies, so choose the container’s lifetime with the part of the program that reads it.

Define how application identities become bytes

A device identifier must be encoded to the key width expected by the map. Different byte orders can encode the same number differently. Variable-length text needs a separate representation that fits the chosen key contract. Those rules belong to the calling program. Test both the encoding and the lookup when a key is reconstructed after a restart or read from another component. The byte array stored as a value also requires a documented decoding rule if several parts of a system share the map.

Decide how to handle a full table

The map has a fixed capacity. The caller needs a policy for adding a new key when that capacity is exhausted. Updating an existing key and admitting a new key are distinct operations in a test. Verify what happens to previous entries after a failed operation. For example, a device-status table may preserve existing rows and report that a new device could not be registered. Avoid hiding capacity with an endless retry. The application can handle the error according to what data must be preserved.

Test the limits before measuring throughput

Reproduce a small insert and lookup, then test an absent key, an update and attempts near the capacity limit. Record what remains readable after an insertion error. Those results qualify behavior before attempting a speed comparison. Measure the complete storage footprint on the target and record the capacity and key and value widths. Keep those values alongside the Rust target and package version, so a later size or performance difference can be tied back to the configuration that produced it.

Photo · RSeverson / Wikimedia Commons ↗ · CC BY-SA 3.0

Sources and verification
Be the first reader ✎ Write a comment

Reader discussion

Discussion prompt

What would you change first for maintainability and testing in your own project?

No comments yet. Be the first to contribute.

Write a comment

Comments are real visitor contributions. Repeated, link-heavy or abusive submissions may be limited.