pub mod hex_format;
pub mod serializable_hob;
use r_efi::efi::Guid;
use alloc::format;
use alloc::string::String;
use alloc::vec;
use alloc::vec::Vec;
pub fn format_guid(guid: Guid) -> String {
let (time_low, time_mid, time_hi_and_version, clk_seq_hi_res, clk_seq_low, node) = guid.as_fields();
format!(
"{:08x}-{:04x}-{:04x}-{:02x}{:02x}-{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}",
time_low,
time_mid,
time_hi_and_version,
clk_seq_hi_res,
clk_seq_low,
node[0],
node[1],
node[2],
node[3],
node[4],
node[5]
)
}
pub trait Interval: Clone + Ord {
fn start(&self) -> u64;
fn end(&self) -> u64;
fn merge(&self, other: &Self) -> Self;
fn length(&self) -> u64 {
self.end() - self.start()
}
fn contains(&self, other: &Self) -> bool {
self.start() <= other.start() && self.end() >= other.end()
}
fn overlaps(&self, other: &Self) -> bool {
self.start() < other.end() && other.start() < self.end()
}
fn adjacent(&self, other: &Self) -> bool {
self.end() == other.start() || other.end() == self.start()
}
fn try_merge(&self, other: &Self) -> Option<Self> {
if self.overlaps(other) || self.adjacent(other) { Some(self.merge(other)) } else { None }
}
fn merge_intervals(intervals: &[&Self]) -> Vec<Self> {
if intervals.is_empty() {
return Vec::new();
}
let mut sorted = intervals.to_vec();
sorted.sort();
let mut result = vec![sorted[0].clone()];
for current in sorted.into_iter().skip(1) {
let last = result.last_mut().unwrap();
if let Some(merged) = last.try_merge(current) {
*last = merged;
} else {
result.push((*current).clone());
}
}
result
}
}