Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Implements a vector-based slab-like map with an interface similar to that of HashMap, and also provides tools for generating lightweight identifiers that can be type-safely used as keys for this map.

License

NotificationsYou must be signed in to change notification settings

andrewsonin/blazemap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Implements a vector-based slab-like map with an interface similar to that ofHashMap,and also provides tools for generating lightweight identifiers that can be type-safely used as keys for this map.

Crates.ioDocumentationMIT licensedBuild Status

Usage

Currently, this crate provides 3 ways to create new types based onusize that can be used as keys toBlazeMap.They are represented by the following macros and provide different optimizations.

1.define_key_wrapper!

Creates a new type that acts as anusize-based replacementfor the old type that can be used as a key forblazemap collections.

Example

use blazemap::prelude::{BlazeMap, define_key_wrapper};define_key_wrapper!{pubstructKey(&'staticstr);Derive(asforOriginalType):{// Optional sectionDebug,Display,};Derive(asforusize):{// Optional sectionOrd,}}let key_1 =Key::new("first");let key_2 =Key::new("second");let key_3 =Key::new("third");letmut map =BlazeMap::new();map.insert(key_2,"2");map.insert(key_1,"1");map.insert(key_3,"3");assert_eq!(format!("{map:?}"),r#"{"first": "1", "second": "2", "third": "3"}"#)

2.define_key_wrapper_bounded!

Creates a new type that acts as anusize-based replacement for the oldtype that can be used as a key forblazemap collections.

Being an analogue ofdefine_key_wrapper!for the case when the user could statically guaranteethat the number of unique keys doesn't exceedMAX_CAP, it's optimized forread operations so that they don't create any multi-thread contention.

Example

use blazemap::prelude::{BlazeMap, define_key_wrapper_bounded};define_key_wrapper_bounded!{pubstructKey(&'staticstr);MAX_CAP =40_000;Derive(asforOriginalType):{// Optional sectionDebug,Display,};Derive(asforusize):{// Optional sectionOrd,}}let key_1 =Key::new("first");let key_2 =Key::new("second");let key_3 =Key::new("third");letmut map =BlazeMap::new();map.insert(key_2,"2");map.insert(key_1,"1");map.insert(key_3,"3");assert_eq!(format!("{map:?}"),r#"{"first": "1", "second": "2", "third": "3"}"#)

3.define_plain_id!

Creates a new type based on incrementally generatedusize instancesthat can be used as a key forblazemap collections. This is the most performant way to generate keys forBlazeMap.

Example

use blazemap::prelude::{BlazeMap, define_plain_id};define_plain_id!{pubstructId;Derive:{// Optional sectionOrd};}let key_1 =Id::new();let key_2 =Id::new();let key_3 =Id::new();letmut map =BlazeMap::new();map.insert(key_2,"2");map.insert(key_1,"1");map.insert(key_3,"3");assert_eq!(format!("{map:?}"),r#"{0: "1", 1: "2", 2: "3"}"#)

About

Implements a vector-based slab-like map with an interface similar to that of HashMap, and also provides tools for generating lightweight identifiers that can be type-safely used as keys for this map.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp