blazemap
Provides a wrapper for replacing a small number of clumsy objects with identifiers, and also implements a vector-based
slab-like map with an interface similar to that of HashMap.
Let's imagine that at runtime you create a small number of clumsy objects that are used as keys in hashmaps.
This crate allows you to seamlessly replace them with lightweight identifiers in a slab-like manner
using the register_blazemap_id_wrapper macro as well as using them as keys in
the BlazeMap
— a vector-based slab-like map with an interface similar to that of HashMap.
You can also use the register_blazemap_id macro if you want to create a new type based on usize
that is generated incrementally to use as such a key.
No-brain vs blazemap approach
The logic behind the register_blazemap_id_wrapper macro is shown below.
Standard no-brain approach
let clumsy = new;
let mut map = new;
map.insert // Too inefficient
blazemap approach
use ;
register_blazemap_id_wrapper!
let clumsy = new;
let clumsy_id = new;
let mut map = new;
map.insert // Very efficient
Type-generating macros
register_blazemap_id_wrapper
Creates a new type that acts as an usize-based replacement for the old type
that can be used as a key for blazemap collections.
This macro supports optional inference of standard traits using the following syntax:
Derive(as for Original Type)— derives traits as for the original type for whichblazemapID is being registered. Each call to methods on these traits requires an additional.readcall on the internal synchronization primitive, so — all other things being equal — their calls may be less optimal than the corresponding calls on instances of the original key's type. This method supports inference of the following traits:DefaultPartialOrd(mutually exclusive withOrd)Ord(also derivesPartialOrd, so mutually exclusive withPartialOrd)DebugDisplaySerialize(withserdefeature only)Deserialize(withserdefeature only)
Derive(as for Serial Number)— derives traits in the same way as for the serial number assigned when registering an instance of the original type the first timeIdWrapper::newwas called. Because methods inferred by this option do not require additional locking on synchronization primitives, they do not incur any additional overhead compared to methods inferred for plainusize. This method supports inference of the following traits:PartialOrd(mutually exclusive withOrd)Ord(also derivesPartialOrd, so mutually exclusive withPartialOrd)
Example
use ;
register_blazemap_id_wrapper!
let key_1 = new;
let key_2 = new;
let key_3 = new;
let mut map = new;
map.insert;
map.insert;
map.insert;
assert_eq!
register_blazemap_id
Creates a new type based on incrementally generated usize instances
that can be used as a key for blazemap collections.
This macro supports optional inference of standard traits using the following syntax:
Derive— derives traits in the same way as for the serial number assigned when creating a new instance of the type. Because methods inferred by this option do not require additional locking on synchronization primitives, they do not incur any additional overhead compared to methods inferred for plainusize. This method supports inference of the following traits:PartialOrd(mutually exclusive withOrd)Ord(also derivesPartialOrd, so mutually exclusive withPartialOrd)Serialize(withserdefeature only)
Example
use ;
register_blazemap_id!
let key_1 = new;
let key_2 = new;
let key_3 = new;
let mut map = new;
map.insert;
map.insert;
map.insert;
assert_eq!