Вход на сайт

Просмотр новости

Найдите то, что Вас интересует

Multi_bimap - many-to-many bimap freely made of two arbitrary maps

Дата публикации: 16-10-2026 12:38:11


The popular Rust crate for bidirectional maps, bimap, is limited to one-to-one relations (bijections) only (and appears unmaintained). But sometimes you need to have one-to-many and many-to-many relations, or have them made of arbitrary containers instead of having to always use either BTreeMap or HashMap.
I couldn't find anything for that, so I wrote my own Rust crate, multi_bimap:

github.com




GitHub - mikwielgus/multi_bimap: Many-to-many bidirectional map (aka. bipartite...
Many-to-many bidirectional map (aka. bipartite graph, relation) in Rust.






It's fully generic over its underlying containers (two antiparallel maps of sets), so you can have an arbitrary setup. You can e.g. have two hash maps of hash sets, or two B-tree maps of vecs. You are not limited to many-to-many relations, you can also have type-enforced one-to-one, one-to-many bimaps. You can have different types for the left-to-right and right-to-left constituent maps. You can use third-party collection types, e.g. indexmap::IndexMap as a constituent map and tinyvec::TinyVec as a constituent set. You can put keys inside Rc to avoid Clones for larger data.
This possible through a crate that I developed earlier, maplike, which provides common traits for collections and containers.
Here's a simple code example:
let mut produce: HashMultiBimap<&str, &str> = HashMultiBimap::new();
produce.insert("tomato", "red");
produce.insert("tomato", "fruit");
produce.insert("carrot", "orange");
produce.insert("carrot", "vegetable");
produce.insert("apple", "red");
produce.insert("apple", "fruit");
produce.insert("spinach", "green");
produce.insert("spinach", "vegetable");
assert_eq!(
produce.get_by_left("tomato"),
Some(&HashSet::from(["red", "fruit"])),
);
assert_eq!(
produce.get_by_right("fruit"),
Some(&HashSet::from(["tomato", "apple"])),
);
assert_eq!(
produce.get_by_right("vegetable"),
Some(&HashSet::from(["carrot", "spinach"])),
);
1 post - 1 participant
Read full topic

Схожие новости

#Наименование новостиТональностьИнформативностьДата публикации
1Maplike - Crate with traits for abstract containers and operations on them2706-07-2026
2I wrote a small library for exclusive component filtering in bevy014.9313-10-2026
3FerroProve - C-to-Rust lifter emitting #![forbid(unsafe_code)] crates with a differential oracle015.5117-10-2026
4Loole 0.6.0: Improved correctness, performance and Flume compatibility09.414-10-2026
5[Project] sol: A self-contained browser kernel written in Rust09.7618-10-2026
6Multicalc: Scientific computing for real time embedded systems in no_std rust09.428-07-2026
7Zaxis 0.0.5: immediate-mode GUI on wgpu, embeddable in a host's wgpu pass, with an real overlay layer for other processes010.211-10-2026
8Multicalc: Scientific computing for real-time embedded systems in no_std Rust014.3610-08-2026
9Hotcode: easy to use hot-reload09.8409-10-2026
10BloomCraft: twelve Bloom filter variants under one API, looking for feedback5606-07-2026

Классификация: . Схожих патентов: 0. Схожих новостей: 10. Тональность: 0. Информативность: 13.1. Источник: users.rust-lang.org.