| Crates.io | static-id |
| lib.rs | static-id |
| version | 0.3.1 |
| created_at | 2024-09-01 04:57:48.55467+00 |
| updated_at | 2025-04-09 04:07:41.09104+00 |
| description | A memory-efficient library for handling interned identifiers |
| homepage | |
| repository | https://github.com/JunbeomL22/static-id |
| max_upload_size | |
| id | 1359338 |
| size | 53,427 |
This library provides an extremely memory-efficient implementation of StaticId for handling interned identifiers with optimal performance.
StaticId: A highly optimized, interned identifier type combining a code and a venue.StaticId is represented by a single 64-bit pointer.code and venue are fixed: For StaticIdNxM, the maximum length of code and venue is N and M respectively. The exceeding characters will be truncated.StaticId combines a Code (up to 32 bytes) and a Venue (up to 16 bytes) into an interned identifier:
use crate::StaticId;
// Create from string slices
let id = StaticId::from_str("AAPL", "NASDAQ");
// Create from byte slices
let id_bytes = StaticId::from_bytes(b"AAPL", b"NASDAQ");
assert_eq!(id.get_id().code.as_str(), "AAPL");
assert_eq!(id.get_id().venue.as_str(), "NASDAQ");
// Get the length of the combined code and venue
println!("Length: {}", id.len()); // Outputs the sum of code and venue lengths
// Get the number of unique StaticIds in the cache
println!("Cache size: {}", StaticId::cache_len());
// Fast equality check (compares only 8 bytes)
let id2 = StaticId::from_str("AAPL", "NASDAQ");
assert_eq!(id, id2);
// Memory usage
println!("Size of StaticId: {} bytes", std::mem::size_of::<StaticId>()); // Outputs: 8 bytes
Add this to your Cargo.toml:
[dependencies]
static_id = "0.1"
StaticId with unique content will involve allocation and interning. Subsequent creations of StaticIds with the same content will reuse the interned value.cache_len() method allows you to monitor the size of the intern cache, which can be useful for understanding memory usage in your application.This project is licensed under [LICENSE NAME] - see the LICENSE.md file for details.
Contributions are welcome! Please feel free to submit a Pull Request.