Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the crate no-std #10

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "2.0.5"
authors = ["Eric Stokes <letaris@gmail.com>"]
publish = true
description = "A fast immutable map and set with batch insert and update methods, COW operations, and big O efficient implementations of set and merge operations"
categories = ["data-structures"]
categories = ["data-structures", "no-std"]
keywords = ["map", "set", "immutable", "persistent", "functional"]
license = "Apache-2.0 OR MIT"
documentation = "https://docs.rs/immutable-chunkmap"
Expand All @@ -17,8 +17,8 @@ serde = ["dep:serde"]
rayon = ["dep:rayon"]

[dependencies]
arrayvec = "0.7"
serde = { version = "1", optional = true }
arrayvec = { version = "0.7", default-features = false }
serde = { version = "1", default-features = false, features = ["alloc"], optional = true }
rayon = { version = "1", optional = true }

[dev-dependencies]
Expand All @@ -27,3 +27,4 @@ serde = "1"
serde_json = "1"
paste = "1"
rand = "0.8"
hashbrown = "0.15"
4 changes: 2 additions & 2 deletions src/avl.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::chunk::{Chunk, Loc, MutUpdate, Update, UpdateChunk};
use arrayvec::ArrayVec;
use std::{
use alloc::{sync::{Arc, Weak}, vec::Vec};
use core::{
borrow::Borrow,
cmp::{max, min, Eq, Ord, Ordering, PartialEq, PartialOrd},
default::Default,
Expand All @@ -10,7 +11,6 @@ use std::{
marker::PhantomData,
ops::{Bound, Index, RangeBounds, RangeFull},
slice,
sync::{Arc, Weak},
};

// until we get 128 bit machines with exabytes of memory
Expand Down
4 changes: 2 additions & 2 deletions src/chunk.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use arrayvec::ArrayVec;
use std::{
use alloc::{sync::Arc, vec::Vec};
use core::{
borrow::Borrow,
cmp::{min, Ord, Ordering},
fmt::{self, Debug, Formatter},
iter, mem,
ops::Deref,
slice,
sync::Arc,
};

#[derive(PartialEq)]
Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
//! Immutable maps and sets. See map and set modules for details.

#![cfg_attr(not(feature = "rayon"), no_std)]

extern crate alloc;

pub(crate) mod chunk;
pub(crate) mod avl;
pub mod map;
Expand Down
17 changes: 9 additions & 8 deletions src/map.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::avl::{Iter, IterMut, Tree, WeakTree};
pub use crate::chunk::DEFAULT_SIZE;
use std::{
use core::{
borrow::Borrow,
cmp::{Eq, Ord, Ordering, PartialEq, PartialOrd},
default::Default,
Expand All @@ -18,7 +18,7 @@ use serde::{
};

#[cfg(feature = "serde")]
use std::marker::PhantomData;
use core::marker::PhantomData;

#[cfg(feature = "rayon")]
use rayon::{
Expand All @@ -45,7 +45,8 @@ use rayon::{
///
/// # Examples
/// ```
/// use std::string::String;
/// # extern crate alloc;
/// use alloc::string::String;
/// use self::immutable_chunkmap::map::MapM;
///
/// let m =
Expand Down Expand Up @@ -377,7 +378,7 @@ where
///
/// #Examples
/// ```
/// use std::iter::FromIterator;
/// use core::iter::FromIterator;
/// use self::immutable_chunkmap::map::MapM;
///
/// let m = MapM::from_iter((0..4).map(|k| (k, k)));
Expand Down Expand Up @@ -512,7 +513,7 @@ where
///
/// # Examples
/// ```
/// use std::iter::FromIterator;
/// use core::iter::FromIterator;
/// use self::immutable_chunkmap::map::MapM;
///
/// let m0 = MapM::from_iter((0..10).map(|k| (k, 1)));
Expand Down Expand Up @@ -550,7 +551,7 @@ where
///
/// # Examples
///```
/// use std::iter::FromIterator;
/// use core::iter::FromIterator;
/// use self::immutable_chunkmap::map::MapM;
///
/// let m0 = MapM::from_iter((0..100000).map(|k| (k, 1)));
Expand Down Expand Up @@ -580,7 +581,7 @@ where
///
/// # Examples
///```
/// use std::iter::FromIterator;
/// use core::iter::FromIterator;
/// use self::immutable_chunkmap::map::MapM;
///
/// let m0 = MapM::from_iter((0..10000).map(|k| (k, 1)));
Expand Down Expand Up @@ -647,7 +648,7 @@ where
///
/// # Example
/// ```
/// use std::iter::FromIterator;
/// use core::iter::FromIterator;
/// use self::immutable_chunkmap::map::MapM as Map;
///
/// let mut m = Map::from_iter((0..100).map(|k| (k, Map::from_iter((0..100).map(|k| (k, 1))))));
Expand Down
13 changes: 7 additions & 6 deletions src/set.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::avl::{Iter, Tree, WeakTree};
pub use crate::chunk::DEFAULT_SIZE;
use std::{
use core::{
borrow::Borrow,
cmp::{Eq, Ord, Ordering, PartialEq, PartialOrd},
default::Default,
Expand All @@ -18,7 +18,7 @@ use serde::{
};

#[cfg(feature = "serde")]
use std::marker::PhantomData;
use core::marker::PhantomData;

#[cfg(feature = "rayon")]
use rayon::{
Expand All @@ -31,7 +31,8 @@ use rayon::{
/// log(N) get, insert, and remove operations.
/// # Examples
/// ```
/// use std::string::String;
/// # extern crate alloc;
/// use alloc::string::String;
/// use self::immutable_chunkmap::set::SetM;
///
/// let m =
Expand Down Expand Up @@ -423,7 +424,7 @@ where
///
/// # Examples
/// ```
/// use std::iter::FromIterator;
/// use core::iter::FromIterator;
/// use self::immutable_chunkmap::set::SetM;
///
/// let s0 = SetM::from_iter(0..10);
Expand All @@ -442,7 +443,7 @@ where
/// the number of intersecting chunks.
///
/// # Examples
/// use std::iter::FromIterator;
/// use core::iter::FromIterator;
/// use self::immutable_chunkmap::set::SetM;
///
/// let s0 = SetM::from_iter(0..100);
Expand Down Expand Up @@ -471,7 +472,7 @@ where
///
/// # Examples
/// ```
/// use std::iter::FromIterator;
/// use core::iter::FromIterator;
/// use self::immutable_chunkmap::set::SetM;
///
/// let s0 = SetM::from_iter(0..100);
Expand Down
17 changes: 4 additions & 13 deletions src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
use crate::{avl, chunk::DEFAULT_SIZE, map::MapM, set::SetM};
use rand::Rng;
use std::{
use alloc::{collections::BTreeMap, string::String, sync::Arc, vec::Vec, vec};
use core::{
borrow::Borrow,
cmp::Ordering,
collections::{BTreeMap, HashMap, HashSet},
fmt::Debug,
hash::Hash,
i32,
iter::{FromIterator, IntoIterator},
ops::Bound::{Excluded, Included},
sync::Arc,
vec::Vec,
};
use hashbrown::{HashMap, HashSet};
use rand::Rng;

const STRSIZE: usize = 10;
const SIZE: usize = 500000;
Expand Down Expand Up @@ -612,14 +611,6 @@ where
break (j, i);
}
};
println!(
"start: {:?}:{:?} end {:?}:{:?} len {:?}",
start,
vals[start],
end,
vals[end],
vals.len()
);
{
let mut i = start;
for (k, v) in t.range(&vals[i].0..&vals[end].0) {
Expand Down