Skip to content

Commit

Permalink
Move DriveChunkMultiple 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 69972c0 commit daff630
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 @@ -910,6 +910,38 @@ bool DriveChunkMultiple::try_append(DriveChunkMultiple const &chunk)
return true;
}

DriveChunkMultiple::DriveChunkMultiple(DriveBitMultiple const &bit)
: width_(1)
{
for (auto const &bit : bit.multiple())
multiple_.emplace(bit);
}

pool<DriveChunk> const &DriveChunkMultiple::multiple() const
{
return multiple_;
}

int DriveChunkMultiple::size() const { return width_; }


bool DriveChunkMultiple::operator==(const DriveChunkMultiple &other) const
{
return width_ == other.width_ && multiple_ == other.multiple_;
}

bool DriveChunkMultiple::operator<(const DriveChunkMultiple &other) const
{
if (multiple_.size() < other.multiple_.size())
multiple_.sort();
return false; // TODO: implement, canonicalize order
}

unsigned int DriveChunkMultiple::hash() const
{
return mkhash(width_, multiple_.hash());
}

bool DriveChunk::can_append(DriveBit const &bit) const
{
if (size() == 0)
Expand Down
50 changes: 13 additions & 37 deletions kernel/drivertools.h
Original file line number Diff line number Diff line change
Expand Up @@ -265,47 +265,23 @@ struct DriveChunkMarker
struct DriveChunkMultiple
{
private:
mutable pool<DriveChunk> multiple_;
int width_;
mutable pool<DriveChunk> multiple_;
int width_;

public:
pool<DriveChunk> const &multiple() const { return multiple_; }
pool<DriveChunk> const &multiple() const;

DriveChunkMultiple(DriveBitMultiple const &bit) : width_(1) {
for (auto const &bit : bit.multiple())
multiple_.emplace(bit);
}

int size() const { return width_; }

DriveBitMultiple operator[](int i) const;

bool can_append(DriveBitMultiple const &bit) const;

bool try_append(DriveBitMultiple const &bit);
DriveChunkMultiple(DriveBitMultiple const &bit);


bool can_append(DriveChunkMultiple const &bit) const;

bool try_append(DriveChunkMultiple const &bit);

bool operator==(const DriveChunkMultiple &other) const
{
return width_ == other.width_ && multiple_ == other.multiple_;
}

bool operator<(const DriveChunkMultiple &other) const
{
if (multiple_.size() < other.multiple_.size())

multiple_.sort();
return false; // TODO implement, canonicalize order
}

unsigned int hash() const
{
return mkhash(width_, multiple_.hash());
}
int size() const;
DriveBitMultiple operator[](int i) const;
bool can_append(DriveBitMultiple const &bit) const;
bool try_append(DriveBitMultiple const &bit);
bool can_append(DriveChunkMultiple const &bit) const;
bool try_append(DriveChunkMultiple const &bit);
bool operator==(const DriveChunkMultiple &other) const;
bool operator<(const DriveChunkMultiple &other) const;
unsigned int hash() const;
};

struct DriveChunk
Expand Down

0 comments on commit daff630

Please sign in to comment.