1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//! Common utilities used in [`frozen_core`]
/// Returns `true` if `x` is a power of two.
///
/// ## Example
///
/// ```
/// use frozen_core::utils::is_power_of_2;
///
/// assert!(is_power_of_2(1u16));
/// assert!(is_power_of_2(2u32));
/// assert!(is_power_of_2(4u64));
/// assert!(is_power_of_2(1024usize));
///
/// assert!(!is_power_of_2(0u16));
/// assert!(!is_power_of_2(3u32));
/// assert!(!is_power_of_2(5u64));
/// assert!(!is_power_of_2(1023usize));
/// ```
/// Size of a single IO buffer.
///
/// All variants are powers of two, which enables efficient alignment, masking, indexing, and allocator-friendly
/// memory layouts throughout the storage engine.
///
/// The value of each variant is the buffer size in bytes.
///
/// *NOTE:* The [`BufferSize::S16384`] is an upper limit for available buffer sizes, as it is large enough to never
/// create any sort of inconvience for the user, and small enough to never create overflow issues in arithmatic
/// operation across storage engine/s.
///
/// ## Example
///
/// ```
/// let buf_size = frozen_core::utils::BufferSize::S128.bytes();
/// assert!(frozen_core::utils::is_power_of_2(buf_size));
/// ```