Skip to content

A heap-allocated chunk of memory populated by a fixed set of types

License

Notifications You must be signed in to change notification settings

gymore-io/stadium

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Documentation Crates.io

stadium provides the Stadium structure. This datastructure allows you to allocate any given set of objects (that can be of different types) in a continuous chunk of the memory.

Example

// The first step is to build the stadium using a builder.
// This registers the data that will be used inside of the stadium.
let mut builder = stadium::builder();

let h_vec = builder.insert(vec![2019, 2020, 2021]);
let h_str = builder.insert("Hello, world!");
let h_int_a = builder.insert(68u64);
let h_int_b = builder.insert(65u64)

// Once the initialization is done, the actual stadium can be created.
let mut stadium = builder.build();

// Values can be retrieved.
assert_eq!(&stadium[h_vec], &[2019, 2020, 2021][..]);
assert_eq!(stadium[h_str], "Hello, world!");
assert_eq!(stadium[h_int_a], 68);

// Or mutated.
stadium[h_vec].push(2022);
stadium[h_int_b] = 70;

// Other operations are supported.
assert_eq!(stadium.replace(h_str, "FOOBAR"), "Hello, world!");

stadium.swap(h_int_a, h_int_b);
assert_eq!(stadium[h_int_a], 70);
assert_eq!(stadium[h_int_b], 68);

About

A heap-allocated chunk of memory populated by a fixed set of types

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages