diff --git a/kernel/drivertools.cc b/kernel/drivertools.cc index 29efab01d14..27ebd20b284 100644 --- a/kernel/drivertools.cc +++ b/kernel/drivertools.cc @@ -703,6 +703,38 @@ bool DriveChunkMarker::try_append(DriveChunkMarker const &chunk) return true; } +DriveChunkMarker::DriveChunkMarker(int marker, int offset, int width) + : marker(marker), offset(offset), width(width) {} + +DriveChunkMarker::DriveChunkMarker(DriveBitMarker const &bit) + : marker(bit.marker), offset(bit.offset), width(1) {} + +int DriveChunkMarker::size() const { return width; } + +DriveBitMarker DriveChunkMarker::operator[](int i) const +{ + log_assert(i >= 0 && i < width); + return DriveBitMarker(marker, offset + i); +} + +bool DriveChunkMarker::operator==(const DriveChunkMarker &other) const +{ + return marker == other.marker && offset == other.offset && width == other.width; +} + +bool DriveChunkMarker::operator<(const DriveChunkMarker &other) const +{ + if (marker != other.marker) + return marker < other.marker; + if (width != other.width) + return width < other.width; + return offset < other.offset; +} + +unsigned int DriveChunkMarker::hash() const +{ + return mkhash_add(mkhash(marker, width), offset); +} bool DriveChunkMultiple::can_append(DriveBitMultiple const &bit) const { diff --git a/kernel/drivertools.h b/kernel/drivertools.h index f98860c51d7..4f6c7a7befe 100644 --- a/kernel/drivertools.h +++ b/kernel/drivertools.h @@ -245,45 +245,21 @@ struct DriveChunkPort struct DriveChunkMarker { - int marker; - int offset; - int width; - - DriveChunkMarker(int marker, int offset, int width) : - marker(marker), offset(offset), width(width) {} - DriveChunkMarker(DriveBitMarker const &bit) : - marker(bit.marker), offset(bit.offset), width(1) {} - - int size() const { return width; } - - DriveBitMarker operator[](int i) const - { - log_assert(i >= 0 && i < width); - return DriveBitMarker(marker, offset + i); - } - - bool can_append(DriveBitMarker const &bit) const; - bool try_append(DriveBitMarker const &bit); - bool try_append(DriveChunkMarker const &chunk); - - bool operator==(const DriveChunkMarker &other) const - { - return marker == other.marker && offset == other.offset && width == other.width; - } + int marker; + int offset; + int width; - bool operator<(const DriveChunkMarker &other) const - { - if (marker != other.marker) - return marker < other.marker; - if (width != other.width) - return width < other.width; - return offset < other.offset; - } + DriveChunkMarker(int marker, int offset, int width); + DriveChunkMarker(DriveBitMarker const &bit); - unsigned int hash() const - { - return mkhash_add(mkhash(marker, width), offset); - } + int size() const; + DriveBitMarker operator[](int i) const; + bool can_append(DriveBitMarker const &bit) const; + bool try_append(DriveBitMarker const &bit); + bool try_append(DriveChunkMarker const &chunk); + bool operator==(const DriveChunkMarker &other) const; + bool operator<(const DriveChunkMarker &other) const; + unsigned int hash() const; }; struct DriveChunkMultiple