Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

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
Appearance settings

Forked version of index_vec

License

NotificationsYou must be signed in to change notification settings

oxc-project/oxc-index-vec

Repository files navigation

Crates.ioDocs.rsMIT licensedBuild StatusSponsorsDiscord chat

oxc-index-vec

Forked version ofindex_vec.

Features

This crate provides several optional features:

  • rayon - Enables parallel iteration support via Rayon
  • serde - Enables serialization/deserialization support via Serde
  • nonmax - Enablesdefine_nonmax_u32_index_type! macro for memory-efficient index types usingNonMaxU32

Usage

Add this to yourCargo.toml:

[dependencies]oxc_index ="3.1"# Enable optional features as needed:# oxc_index = { version = "3.1", features = ["serde", "nonmax"] }

Basic Index Type

use oxc_index::{IndexVec, define_index_type};define_index_type!{pubstructMyIdx =u32;}letmut vec:IndexVec<MyIdx,&str> =IndexVec::new();let idx = vec.push("hello");assert_eq!(vec[idx],"hello");

Memory-Efficient Index Type (requiresnonmax feature)

Thedefine_nonmax_u32_index_type! macro creates index types backed byNonMaxU32,which uses the niche optimization to storeOption<MyIdx> in the same space asMyIdx:

use oxc_index::{IndexVec, define_nonmax_u32_index_type};define_nonmax_u32_index_type!{pubstructCompactIdx;}// Option<CompactIdx> is the same size as CompactIdx (4 bytes)assert_eq!(    std::mem::size_of::<CompactIdx>(),    std::mem::size_of::<Option<CompactIdx>>());letmut vec:IndexVec<CompactIdx,String> =IndexVec::new();let idx = vec.push("world".to_string());

Serialization Support (requiresserde feature)

All index types andIndexVec automatically support Serde serialization when theserde feature is enabled:

use oxc_index::{IndexVec, define_index_type};use serde::{Serialize,Deserialize};define_index_type!{pubstructMyIdx =u32;}#[derive(Serialize,Deserialize)]structMyData{items:IndexVec<MyIdx,String>,}

Newly Added Features

Compared to the originalindex_vec:

  • rayon feature - Parallel iteration support
  • serde feature - Automatic serialization support using the crate's own serde dependency
  • nonmax feature - Memory-efficient index types withdefine_nonmax_u32_index_type! macro
  • Const support - Many methods are nowconst fn where possible
  • Proc macro compatibility - Macros work seamlessly with custom derive attributes like#[ast],#[estree(skip)], etc.

My sponsors

About

Forked version of index_vec

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Contributors15


[8]ページ先頭

©2009-2025 Movatter.jp