style: include IM_AVERAGE_COMPUTATION_COULD_OVERFLOW (#5131)

This commit is contained in:
Piotr Idzik 2024-05-01 11:58:04 +02:00 committed by GitHub
parent b075c19a54
commit 2513ccd62b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 6 additions and 9 deletions

View File

@ -8,9 +8,6 @@
<Match> <Match>
<Bug pattern="ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD" /> <Bug pattern="ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD" />
</Match> </Match>
<Match>
<Bug pattern="IM_AVERAGE_COMPUTATION_COULD_OVERFLOW" />
</Match>
<Match> <Match>
<Bug pattern="DMI_RANDOM_USED_ONLY_ONCE" /> <Bug pattern="DMI_RANDOM_USED_ONLY_ONCE" />
</Match> </Match>

View File

@ -97,7 +97,7 @@ public class LongestIncreasingSubsequence {
return end + 1; return end + 1;
} }
while (left < right - 1) { while (left < right - 1) {
int middle = (left + right) / 2; final int middle = (left + right) >>> 1;
if (t[middle] < key) { if (t[middle] < key) {
left = middle; left = middle;
} else { } else {

View File

@ -26,7 +26,7 @@ public class RangeInSortedArray {
if (left > right) { if (left > right) {
return; return;
} }
int mid = (left + right) / 2; int mid = (left + right) >>> 1;
if (nums[mid] > key) { if (nums[mid] > key) {
alteredBinSearch(nums, key, left, mid - 1, range, goLeft); alteredBinSearch(nums, key, left, mid - 1, range, goLeft);
} else if (nums[mid] < key) { } else if (nums[mid] < key) {
@ -52,7 +52,7 @@ public class RangeInSortedArray {
// of 'key' // of 'key'
public static void alteredBinSearchIter(int[] nums, int key, int left, int right, int[] range, boolean goLeft) { public static void alteredBinSearchIter(int[] nums, int key, int left, int right, int[] range, boolean goLeft) {
while (left <= right) { while (left <= right) {
int mid = (left + right) / 2; final int mid = (left + right) >>> 1;
if (nums[mid] > key) { if (nums[mid] > key) {
right = mid - 1; right = mid - 1;
} else if (nums[mid] < key) { } else if (nums[mid] < key) {
@ -84,7 +84,7 @@ public class RangeInSortedArray {
public static int getLessThan(int[] nums, int key, int left, int right) { public static int getLessThan(int[] nums, int key, int left, int right) {
int count = 0; int count = 0;
while (left <= right) { while (left <= right) {
int mid = (left + right) / 2; final int mid = (left + right) >>> 1;
if (nums[mid] > key) { if (nums[mid] > key) {
right = mid - 1; right = mid - 1;
} else if (nums[mid] <= key) { } else if (nums[mid] <= key) {

View File

@ -10,7 +10,7 @@ public class BinaryInsertionSort {
int high = i - 1; int high = i - 1;
while (low <= high) { while (low <= high) {
int mid = (low + high) / 2; final int mid = (low + high) >>> 1;
if (temp < array[mid]) { if (temp < array[mid]) {
high = mid - 1; high = mid - 1;
} else { } else {

View File

@ -16,7 +16,7 @@ public class SlowSort implements SortAlgorithm {
if (SortUtils.greaterOrEqual(i, j)) { if (SortUtils.greaterOrEqual(i, j)) {
return; return;
} }
int m = (i + j) / 2; final int m = (i + j) >>> 1;
sort(array, i, m); sort(array, i, m);
sort(array, m + 1, j); sort(array, m + 1, j);
if (SortUtils.less(array[j], array[m])) { if (SortUtils.less(array[j], array[m])) {