Skip to content

Commit

Permalink
Move DriveChunkMarker implementation to drivertools.cc
Browse files Browse the repository at this point in the history
  • Loading branch information
RCoeurjoly committed May 22, 2024
1 parent 021423a commit 69972c0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 37 deletions.
32 changes: 32 additions & 0 deletions kernel/drivertools.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
50 changes: 13 additions & 37 deletions kernel/drivertools.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 69972c0

Please sign in to comment.