rand_set 0.1.0

A hash set with O(1) random element access and all standard set operations
Documentation
  • Coverage
  • 11.11%
    2 out of 18 items documented1 out of 17 items with examples
  • Size
  • Source code size: 13 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 2.15 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 25s Average build duration of successful builds.
  • all releases: 24s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • RonHachmon

RandSet

A hash set that supports efficient random element access.

RandSet combines the fast lookup of a hash set with the ability to efficiently retrieve random elements, using the get_rand() method.

rest of the method work the same as a HashSet https://doc.rust-lang.org/std/collections/struct.HashSet.html

Key Differences from Standard Sets

Unlike a regular HashSet, elements stored in RandSet must implement the Clone trait. All other methods work like a regular set (insertion, removal, containment checking, etc.).

Example

use rand_set::RandSet;

let mut set = RandSet::new();
set.insert("hello");
set.insert("world");

// Fast containment check (works like HashSet)
assert!(set.contains(&"hello"));

// Unique feature: Get a random element in O(1)
if let Some(random_item) = set.get_rand() {
    println!("Random: {}", random_item);
}