Name |
Date |
Size |
#Lines |
LOC |
||
---|---|---|---|---|---|---|
.. | - | - | ||||
.circleci/ | 03-May-2024 | - | 56 | 54 | ||
src/ | 03-May-2024 | - | 3,263 | 2,746 | ||
tests/ | 03-May-2024 | - | 1,239 | 1,033 | ||
.cargo_vcs_info.json | D | 03-May-2024 | 74 | 6 | 5 | |
.gitignore | D | 03-May-2024 | 72 | 8 | 7 | |
Android.bp | D | 03-May-2024 | 1.7 KiB | 53 | 48 | |
CHANGELOG.md | D | 03-May-2024 | 2.1 KiB | 52 | 44 | |
Cargo.toml | D | 03-May-2024 | 1.1 KiB | 38 | 34 | |
Cargo.toml.orig | D | 03-May-2024 | 610 | 25 | 20 | |
LICENSE | D | 03-May-2024 | 10.6 KiB | 201 | 169 | |
LICENSE-APACHE | D | 03-May-2024 | 10.6 KiB | 201 | 169 | |
LICENSE-MIT | D | 03-May-2024 | 1.1 KiB | 26 | 23 | |
METADATA | D | 03-May-2024 | 424 | 20 | 19 | |
MODULE_LICENSE_APACHE2 | D | 03-May-2024 | 0 | |||
OWNERS | D | 03-May-2024 | 40 | 2 | 1 | |
README.md | D | 03-May-2024 | 2.6 KiB | 68 | 54 |
README.md
1# hashlink -- HashMap-like containers that hold their key-value pairs in a user controllable order 2 3[](https://circleci.com/gh/kyren/hashlink) 4[](https://crates.io/crates/hashlink) 5[](https://docs.rs/hashlink) 6 7This crate is a fork of 8[linked-hash-map](https://github.com/contain-rs/linked-hash-map) that builds on 9top of [hashbrown](https://github.com/rust-lang/hashbrown) to implement more up 10to date versions of `LinkedHashMap` `LinkedHashSet`, and `LruCache`. 11 12One important API change is that when a `LinkedHashMap` is used as a LRU cache, 13it allows you to easily retrieve an entry and move it to the back OR produce a 14new entry at the back without needlessly repeating key hashing and lookups: 15 16``` rust 17let mut lru_cache = LinkedHashMap::new(); 18let key = "key".to_owned(); 19// Try to find my expensive to construct and hash key 20let _cached_val = match lru_cache.raw_entry_mut().from_key(&key) { 21 RawEntryMut::Occupied(mut occupied) => { 22 // Cache hit, move entry to the back. 23 occupied.to_back(); 24 occupied.into_mut() 25 } 26 RawEntryMut::Vacant(vacant) => { 27 // Insert expensive to construct key and expensive to compute value, 28 // automatically inserted at the back. 29 vacant.insert(key.clone(), 42).1 30 } 31}; 32``` 33 34Or, a simpler way to do the same thing: 35 36``` rust 37let mut lru_cache = LinkedHashMap::new(); 38let key = "key".to_owned(); 39let _cached_val = lru_cache 40 .raw_entry_mut() 41 .from_key(&key) 42 .or_insert_with(|| (key.clone(), 42)); 43``` 44 45This crate contains a decent amount of unsafe code from handling its internal 46linked list, and the unsafe code has diverged quite a lot from the original 47`linked-hash-map` implementation. It currently passes tests under miri and 48sanitizers, but it should probably still receive more review and testing, and 49check for test code coverage. 50 51## Credit 52 53There is a huge amount of code in this crate that is copied verbatim from 54`linked-hash-map` and `hashbrown`, especially tests, associated types like 55iterators, and things like `Debug` impls. 56 57## License 58 59This library is licensed the same as 60[linked-hash-map](https://github.com/contain-rs/linked-hash-map) and 61[hashbrown](https://github.com/rust-lang/hashbrown), it is licensed under either 62of: 63 64* MIT license [LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT 65* Apache License 2.0 [LICENSE-APACHE](LICENSE-APACHE) or https://opensource.org/licenses/Apache-2.0 66 67at your option. 68