mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:47:34 +00:00
Kernel: Add a Range::intersect(other) helper
This commit is contained in:
parent
7b22fb70a2
commit
7874b89426
2 changed files with 13 additions and 0 deletions
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||||
|
* Copyright (c) 2021, Leon Albrecht <leon2002.la@gmail.com>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -43,5 +44,15 @@ Vector<Range, 2> Range::carve(const Range& taken) const
|
||||||
parts.append({ taken.end(), end().get() - taken.end().get() });
|
parts.append({ taken.end(), end().get() - taken.end().get() });
|
||||||
return parts;
|
return parts;
|
||||||
}
|
}
|
||||||
|
Range Range::intersect(const Range& other) const
|
||||||
|
{
|
||||||
|
if (*this == other) {
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
auto new_base = max(base(), other.base());
|
||||||
|
auto new_end = min(end(), other.end());
|
||||||
|
VERIFY(new_base < new_end);
|
||||||
|
return Range(new_base, (new_end - new_base).get());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
||||||
|
* Copyright (c) 2021, Leon Albrecht <leon2002.la@gmail.com>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -67,6 +68,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<Range, 2> carve(const Range&) const;
|
Vector<Range, 2> carve(const Range&) const;
|
||||||
|
Range intersect(const Range&) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
VirtualAddress m_base;
|
VirtualAddress m_base;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue