Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mohsaka committed Jul 1, 2024
1 parent 334413d commit c64c12c
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions velox/functions/prestosql/IPAddressFunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,12 @@ inline int128_t getIPSubnetMax(int128_t ip, uint8_t prefix) {
memcpy(&result, &ip, 16);

if (isIPV4(ip)) {
if (prefix < 32) {
result |= (mask << 32 - prefix) - 1;
}
result |= (mask << 32 - prefix) - 1;
} else {
// Special case. Return all bits set to 1;
// Special case: Overflow to all 0 subtracting 1 does not work.
if (prefix == 0) {
result = -1;
} else if (prefix < 128) {
} else {
result |= (mask << 128 - prefix) - 1;
}
}
Expand Down Expand Up @@ -167,13 +165,14 @@ struct IPSubnetOfFunction {
int128_t checkIP = ip;

if (isIPV4(ipPrefix->ip)) {
if (prefix < 32) {
checkIP &= ((mask << 32 - prefix) - 1) ^ -1;
}
checkIP &= ((mask << 32 - prefix) - 1) ^ -1;
} else {
if (prefix < 128) {
checkIP &= ((mask << 128 - prefix) - 1) ^ -1;
}
// Special case: Overflow to all 0 subtracting 1 does not work.
if (prefix == 0) {
checkIP = 0;
} else {
checkIP &= ((mask << 128 - prefix) - 1) ^ -1;
}
}
result = (ipPrefix->ip == checkIP);
}
Expand Down

0 comments on commit c64c12c

Please sign in to comment.