Crates.io | cycle_map |
lib.rs | cycle_map |
version | 0.2.0 |
source | src |
created_at | 2022-04-24 21:23:26.755841 |
updated_at | 2023-09-27 21:45:11.368787 |
description | Implementations of bi-directionally accessible hashmaps |
homepage | |
repository | https://github.com/TylerBloom/DoubleMap.git |
max_upload_size | |
id | 573333 |
size | 266,910 |
CycleMap provides several "double-sided" hash maps that associate items between two sets. It does this without keep duplicate data and while maintaining lookup speeds on par with the standard HashMap.
There are many ways that you might want to map items between sets. CycleMap supports three.
Each map contains two sets, a left set and a right set. When two items are paired, they form a cycle. That is, an item from either set can be used to uniquely lookup the item(s) it is paired with. This forms a cyclic lookup and is the core algorithm that underlies all cycle maps.
Instead of holding self-referential pointers, all cycle maps pair an item with the hash of its partner item (and an id). This prevents possible unforeseen memory bugs and makes map resizing faster since an item doesn't need to "know" where its partner is but rather how to get there.
Cycle maps aren't meant to replace the standard hashmap. In fact, they are built on top of it. Rather, they provide a clean solution to fast, bi-direction lookups.
If you find yourself creating workarounds to these sorts of problems, give a cycle map a try.
If you want to contribute to or improve upon this library, please do so. Fork this project or submit an issue or a pull request for a feature/fix/change/etc. All that I ask is for derived/iterative libraries to be open and free to use and ideally with the same license (LGPL v3). Any other application or library that uses this library can use any license.
The CycleMap
struct has a counterpart, PartialCycleMap
. This struct
looses the requirements of the CycleMap
by allowing unpaired items in
either set. A similar PartialGroupMap
struct is planned to mirror the
GroupMap
struct.