use super::{FastBuildHasher, FastHashMap, FastHashSet, SmallBuffer};
#[inline]
#[must_use]
pub fn fast_hash_map_with_capacity<K, V>(capacity: usize) -> FastHashMap<K, V> {
FastHashMap::with_capacity_and_hasher(capacity, FastBuildHasher::default())
}
#[inline]
#[must_use]
pub fn fast_hash_set_with_capacity<T>(capacity: usize) -> FastHashSet<T> {
FastHashSet::with_capacity_and_hasher(capacity, FastBuildHasher::default())
}
#[must_use]
pub fn small_buffer_with_capacity_8<T>(capacity: usize) -> SmallBuffer<T, 8> {
SmallBuffer::with_capacity(capacity)
}
#[must_use]
pub fn small_buffer_with_capacity_2<T>(capacity: usize) -> SmallBuffer<T, 2> {
SmallBuffer::with_capacity(capacity)
}
#[must_use]
pub fn small_buffer_with_capacity_16<T>(capacity: usize) -> SmallBuffer<T, 16> {
SmallBuffer::with_capacity(capacity)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_capacity_helpers() {
eprintln!(
"small_buffer_with_capacity_2: use case is facet-to-cell relationships (2 cells per facet)"
);
eprintln!(
"small_buffer_with_capacity_16: use case is batch vertex/cell collections in higher-dimensional operations"
);
let map = fast_hash_map_with_capacity::<u64, usize>(100);
assert!(map.capacity() >= 100);
let set = fast_hash_set_with_capacity::<u64>(50);
assert!(set.capacity() >= 50);
let mut buffer_8 = small_buffer_with_capacity_8::<i32>(5);
assert!(buffer_8.capacity() >= 5);
for i in 0..9 {
buffer_8.push(i);
}
assert!(buffer_8.spilled());
let mut buffer_2 = small_buffer_with_capacity_2::<i32>(10);
assert!(buffer_2.capacity() >= 10);
buffer_2.extend(0..3); assert!(buffer_2.spilled());
let mut buffer_16 = small_buffer_with_capacity_16::<String>(25);
assert!(buffer_16.capacity() >= 25);
buffer_16.extend(std::iter::repeat_n(String::new(), 17)); assert!(buffer_16.spilled());
let mut test_buffer2: SmallBuffer<f64, 2> = small_buffer_with_capacity_2(3);
test_buffer2.push(1.0);
test_buffer2.push(2.0);
assert_eq!(test_buffer2.len(), 2);
let mut test_buffer16: SmallBuffer<char, 16> = small_buffer_with_capacity_16(5);
test_buffer16.push('a');
test_buffer16.push('b');
assert_eq!(test_buffer16.len(), 2);
let _buffer2_zero = small_buffer_with_capacity_2::<u8>(0);
let _buffer16_zero = small_buffer_with_capacity_16::<u32>(0);
}
}