Drop in support for no_std float operations
1#[cfg(feature = "std")]
2mod std {
3 pub type Box<A> = ::std::boxed::Box<A>;
4 pub type Map<K, V> = ::std::collections::HashMap<K, V>;
5 pub type Vec<A> = ::std::vec::Vec<A>;
6 pub type ChildrenVec<A> = ::std::vec::Vec<A>;
7 pub type ParentsVec<A> = ::std::vec::Vec<A>;
8
9 pub fn new_map_with_capacity<K, V>(capacity: usize) -> Map<K, V>
10 where
11 K: Eq + ::std::hash::Hash,
12 {
13 Map::with_capacity(capacity)
14 }
15
16 pub fn new_vec_with_capacity<A>(capacity: usize) -> Vec<A> {
17 Vec::with_capacity(capacity)
18 }
19
20 #[inline]
21 pub fn round(value: f32) -> f32 {
22 value.round()
23 }
24
25 #[inline]
26 pub fn abs(value: f32) -> f32 {
27 value.abs()
28 }
29}
30
31#[cfg(feature = "alloc")]
32mod alloc {
33 pub type Box<A> = ::alloc::boxed::Box<A>;
34 pub type Map<K, V> = ::hashbrown::HashMap<K, V>;
35 pub type Vec<A> = ::alloc::vec::Vec<A>;
36 pub type ChildrenVec<A> = ::alloc::vec::Vec<A>;
37 pub type ParentsVec<A> = ::alloc::vec::Vec<A>;
38
39 pub fn new_map_with_capacity<K, V>(capacity: usize) -> Map<K, V> {
40 Map::with_capacity(capacity)
41 }
42
43 pub fn new_vec_with_capacity<A>(capacity: usize) -> Vec<A> {
44 Vec::with_capacity(capacity)
45 }
46
47 #[inline]
48 pub fn round(value: f32) -> f32 {
49 num_traits::float::FloatCore::round(value)
50 }
51
52 #[inline]
53 pub fn abs(value: f32) -> f32 {
54 num_traits::float::FloatCore::abs(value)
55 }
56}
57
58#[cfg(all(not(feature = "alloc"), not(feature = "std")))]
59mod core {
60 use typenum::marker_traits::Unsigned;
61
62 type MaxNodeCount = heapless::consts::U256;
63 type MaxChildCount = heapless::consts::U16;
64 type MaxParentsCount = heapless::consts::U1;
65
66 pub type Map<K, V> = ::heapless::FnvIndexMap<K, V, MaxNodeCount>;
67 pub type Vec<A> = ::arrayvec::ArrayVec<[A; MaxNodeCount::USIZE]>;
68 pub type ChildrenVec<A> = ::arrayvec::ArrayVec<[A; MaxChildCount::USIZE]>;
69 pub type ParentsVec<A> = ::arrayvec::ArrayVec<[A; MaxParentsCount::USIZE]>;
70
71 pub fn new_map_with_capacity<K, V>(_capacity: usize) -> Map<K, V>
72 where
73 K: Eq + ::hash32::Hash,
74 {
75 Map::new()
76 }
77
78 pub fn new_vec_with_capacity<T, A>(_capacity: usize) -> ::arrayvec::ArrayVec<A>
79 where
80 A: ::arrayvec::Array<Item = T>,
81 {
82 ::arrayvec::ArrayVec::new()
83 }
84
85 #[inline]
86 pub fn round(value: f32) -> f32 {
87 num_traits::float::FloatCore::round(value)
88 }
89
90 #[inline]
91 pub fn abs(value: f32) -> f32 {
92 num_traits::float::FloatCore::abs(value)
93 }
94}
95
96#[cfg(feature = "alloc")]
97pub use self::alloc::*;
98#[cfg(all(not(feature = "alloc"), not(feature = "std")))]
99pub use self::core::*;
100#[cfg(feature = "std")]
101pub use self::std::*;