Skip to content

Commit

Permalink
remove std
Browse files Browse the repository at this point in the history
  • Loading branch information
martial-plains committed Mar 6, 2024
1 parent a3c186a commit c73298f
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 23 deletions.
6 changes: 2 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ authors = ["Allister Isaiah Harvey <[email protected]>"]
edition = "2021"

[features]
default = ["hashbrown"]
std = []
hashbrown = ["dep:hashbrown"]


[dependencies]
num = "0.4.0"
rand = "0.8.5"
hashbrown = { version = "0.14.0", optional = true }
hashbrown = { version = "0.14.3" }


[dev-dependencies]
Expand Down
6 changes: 0 additions & 6 deletions src/dynamic_programming/memoize.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use core::hash::Hash;

#[cfg(not(feature = "std"))]
use hashbrown::HashMap;
#[cfg(feature = "std")]
use std::collections::HashMap;

/// Memoizes the result of a function to avoid redundant function calls.
///
Expand All @@ -20,10 +17,7 @@ use std::collections::HashMap;
/// # Example
///
/// ```
/// #[cfg(not(feature = "std"))]
/// use hashbrown::HashMap;
/// #[cfg(feature = "std")]
/// use std::collections::HashMap;
/// use algorithms::dynamic_programming::memoize;
///
/// fn fibonacci(cache: &mut HashMap<u32, u64>, n: u32) -> u64 {
Expand Down
5 changes: 2 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
#![feature(cfg_match, decl_macro)]
#![no_std]

#[cfg(feature = "std")]
extern crate std;

extern crate alloc;

pub mod dynamic_programming;
Expand All @@ -42,3 +39,5 @@ pub mod higher_order_functions;
#[doc = include_str!("sorts/README.md")]
pub mod sorts;
pub mod strings;

pub use hashbrown;
5 changes: 1 addition & 4 deletions src/macros/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ pub macro hashmap {
($($key:expr => $value:expr,)+) => { hashmap!($($key => $value),+) },
($($key:expr => $value:expr),*) => {
{
#[cfg(not(feature = "std"))]
use hashbrown::HashMap;
#[cfg(feature = "std")]
use std::collections::HashMap;
use $crate::hashbrown::HashMap;

let capacity = hashmap!(@count $($key),*);
let mut map = HashMap::with_capacity(capacity);
Expand Down
3 changes: 0 additions & 3 deletions src/math/fibonacci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@
//!
//! [Wikipedia](https://en.wikipedia.org/wiki/Fibonacci_number)
#[cfg(not(feature = "std"))]
use hashbrown::HashMap;
#[cfg(feature = "std")]
use std::collections::HashMap;

use crate::dynamic_programming::memoize;

Expand Down
3 changes: 0 additions & 3 deletions src/strings/search/word_occurrences.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#[cfg(not(feature = "std"))]
use hashbrown::HashMap;
#[cfg(feature = "std")]
use std::collections::HashMap;

/// Create a map containing count of each word
///
Expand Down

0 comments on commit c73298f

Please sign in to comment.