mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Add function to calculate the list index
This commit is contained in:
@@ -7,6 +7,14 @@ use core::ptr;
|
|||||||
/// the block alignment (alignments must be always powers of 2).
|
/// the block alignment (alignments must be always powers of 2).
|
||||||
const BLOCK_SIZES: &[usize] = &[8, 16, 32, 64, 128, 256, 512, 1024, 2048];
|
const BLOCK_SIZES: &[usize] = &[8, 16, 32, 64, 128, 256, 512, 1024, 2048];
|
||||||
|
|
||||||
|
/// Choose an appropriate block size for the given layout.
|
||||||
|
///
|
||||||
|
/// Returns an index into the `BLOCK_SIZES` array.
|
||||||
|
fn list_index(layout: &Layout) -> Option<usize> {
|
||||||
|
let required_block_size = layout.size().max(layout.align());
|
||||||
|
BLOCK_SIZES.iter().position(|&s| s >= required_block_size)
|
||||||
|
}
|
||||||
|
|
||||||
struct ListNode {
|
struct ListNode {
|
||||||
next: Option<&'static mut ListNode>,
|
next: Option<&'static mut ListNode>,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user