1
0
mirror of https://github.com/Zygo/bees.git synced 2025-05-18 05:45:45 +02:00

BeesFileRange: coalesce is not used, subtract was never implemented

Less dead code to maintain.  Also more Doxygen comments.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
This commit is contained in:
Zygo Blaxell 2022-11-20 23:19:45 -05:00
parent 152e69a6d1
commit 23c16aa978
2 changed files with 8 additions and 48 deletions

View File

@ -238,42 +238,6 @@ BeesFileRange::overlaps(const BeesFileRange &that) const
return false;
}
bool
BeesFileRange::coalesce(const BeesFileRange &that)
{
// Let's define coalesce-with-null as identity,
// and coalesce-null-with-null as coalesced
if (!*this) {
operator=(that);
return true;
}
if (!that) {
return true;
}
// Can't coalesce different files
if (!is_same_file(that)) return false;
pair<uint64_t, uint64_t> a(m_begin, m_end);
pair<uint64_t, uint64_t> b(that.m_begin, that.m_end);
// range a starts lower than or equal b
if (b.first < a.first) {
swap(a, b);
}
// if b starts within a, they overlap
// (and the intersecting region is b.first..min(a.second, b.second))
// (and the union region is a.first..max(a.second, b.second))
if (b.first >= a.first && b.first < a.second) {
m_begin = a.first;
m_end = max(a.second, b.second);
return true;
}
return false;
}
BeesFileRange::operator BeesBlockData() const
{
BEESTRACE("operator BeesBlockData " << *this);

View File

@ -277,35 +277,31 @@ public:
bool is_same_file(const BeesFileRange &that) const;
bool overlaps(const BeesFileRange &that) const;
// If file ranges overlap, extends this to include that.
// Coalesce with empty bfr = non-empty bfr
bool coalesce(const BeesFileRange &that);
// Remove that from this, creating 0, 1, or 2 new objects
pair<BeesFileRange, BeesFileRange> subtract(const BeesFileRange &that) const;
off_t begin() const { return m_begin; }
off_t end() const { return m_end; }
off_t size() const;
// Lazy accessors
/// @{ Lazy accessors
off_t file_size() const;
BeesFileId fid() const;
/// @}
// Get the fd if there is one
/// Get the fd if there is one
Fd fd() const;
// Get the fd, opening it if necessary
/// Get the fd, opening it if necessary
Fd fd(const shared_ptr<BeesContext> &ctx);
/// Copy the BeesFileId but not the Fd
BeesFileRange copy_closed() const;
// Is it defined?
/// Is it defined?
operator bool() const { return !!m_fd || m_fid; }
// Make range larger
/// @{ Make range larger
off_t grow_end(off_t delta);
off_t grow_begin(off_t delta);
/// @}
friend ostream & operator<<(ostream &os, const BeesFileRange &bfr);
};