CLeanup, and get domain overlap and mapping adjustment working.
This commit is contained in:
@@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Domain, in sectors.
|
||||
/// Requires sector_size to be provided elsewhere for conversion to bytes.
|
||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq)]
|
||||
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct Domain {
|
||||
pub start: usize,
|
||||
pub end: usize,
|
||||
@@ -19,6 +19,34 @@ impl Domain {
|
||||
pub fn len(self) -> usize {
|
||||
self.end - self.start
|
||||
}
|
||||
|
||||
/// Returns the type of overlap between this domain and another.
|
||||
pub fn overlap(&self, other: Domain) -> DomainOverlap {
|
||||
if self.end <= other.start || other.end <= self.start {
|
||||
// Cases 7, 8, 12, and 13 of map::tests::test_update
|
||||
DomainOverlap::None
|
||||
} else if other.start >= self.start && other.end <= self.end {
|
||||
// Cases 3, 5, 9, and 11 of map::tests::test_update
|
||||
DomainOverlap::SelfEngulfsOther
|
||||
} else if other.start <= self.start && other.end >= self.end {
|
||||
// Cases 4, 6, and 10 of map::tests::test_update
|
||||
DomainOverlap::OtherEngulfsSelf
|
||||
} else if self.start < other.start {
|
||||
// Case 1 of map::tests::test_update
|
||||
DomainOverlap::OtherOverlapsEnd
|
||||
} else {
|
||||
// Case 2 of map::tests::test_update
|
||||
DomainOverlap::OtherOverlapsStart
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub enum DomainOverlap {
|
||||
None,
|
||||
SelfEngulfsOther,
|
||||
OtherEngulfsSelf,
|
||||
OtherOverlapsStart,
|
||||
OtherOverlapsEnd,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user