Skip to content

Commit

Permalink
Improved objects comparison function.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alvov1 committed Jan 5, 2024
1 parent ef8d915 commit 5c31f1f
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions Aesi.h
Original file line number Diff line number Diff line change
Expand Up @@ -655,14 +655,17 @@ class Aesi final {
case Positive:
switch (other.sign) {
case Positive: {
const auto thisLength = lineLength(blocks), valueLength = lineLength(other.blocks);
if(thisLength != valueLength)
return (thisLength > valueLength) ? AesiCMP::greater : AesiCMP::less;

for(long long i = thisLength; i >= 0; --i)
if(blocks[i] != other.blocks[i])
return (blocks[i] > other.blocks[i]) ? AesiCMP::greater : AesiCMP::less;

for(long long i = blocksNumber; i >= 0; --i) {
const block thisBlock = blocks[i], otherBlock = other.blocks[i];
if(thisBlock != 0) {
if(thisBlock > otherBlock)
return AesiCMP::greater;
if(thisBlock < otherBlock)
return AesiCMP::less;
} else
if (otherBlock != 0)
return AesiCMP::less;
}
return AesiCMP::equal;
}
case Zero:
Expand All @@ -672,14 +675,17 @@ class Aesi final {
case Negative:
switch (other.sign) {
case Negative: {
const auto thisLength = lineLength(blocks), valueLength = lineLength(other.blocks);
if(thisLength != valueLength)
return (static_cast<long long>(thisLength) * -1 > static_cast<long long>(valueLength) * -1) ? AesiCMP::greater : AesiCMP::less;

for(long long i = thisLength; i >= 0; --i)
if(blocks[i] != other.blocks[i])
return (static_cast<long>(blocks[i]) * -1 > static_cast<long>(other.blocks[i]) * -1) ? AesiCMP::greater : AesiCMP::less;

for(long long i = blocksNumber; i >= 0; --i) {
const block thisBlock = blocks[i], otherBlock = other.blocks[i];
if(thisBlock != 0) {
if(thisBlock > otherBlock)
return AesiCMP::less;
if(thisBlock < otherBlock)
return AesiCMP::greater;
} else
if (otherBlock != 0)
return AesiCMP::greater;
}
return AesiCMP::equal;
}
case Zero:
Expand Down Expand Up @@ -764,8 +770,8 @@ class Aesi final {
const std::size_t blockNumber = index / sizeof(block), byteInBlock = index % sizeof(block), shift = byteInBlock * bitsInByte;
blocks[blockNumber] &= ~(0xffU << shift); blocks[blockNumber] |= static_cast<block>(byte) << shift;

if(sign != Zero && isLineEmpty(blocks)) sign = Zero;
if(sign == Zero && !isLineEmpty(blocks)) sign = Positive;
if(sign == Zero && blocks[blockNumber] != 0) sign = Positive;
if(sign != Zero && blocks[blockNumber] == 0 && isLineEmpty(blocks)) sign = Zero;
}

/**
Expand Down

0 comments on commit 5c31f1f

Please sign in to comment.