Skip to content

Commit 1fc25c3

Browse files
authored
Merge branch 'master' into supriya_changes
2 parents 7c6b145 + e63ba4b commit 1fc25c3

File tree

559 files changed

+28953
-4095
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

559 files changed

+28953
-4095
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
uses: actions/setup-java@v4
1111
with:
1212
java-version: 21
13-
distribution: 'adopt'
13+
distribution: 'temurin'
1414
- name: Build with Maven
1515
run: mvn --batch-mode --update-snapshots verify
1616
- name: Upload coverage to codecov (tokenless)

.github/workflows/codeql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
uses: actions/setup-java@v4
3131
with:
3232
java-version: 21
33-
distribution: 'adopt'
33+
distribution: 'temurin'
3434

3535
- name: Initialize CodeQL
3636
uses: github/codeql-action/init@v3

.github/workflows/infer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
uses: actions/setup-java@v4
1919
with:
2020
java-version: 21
21-
distribution: 'adopt'
21+
distribution: 'temurin'
2222

2323
- name: Set up OCaml
2424
uses: ocaml/setup-ocaml@v3

DIRECTORY.md

Lines changed: 323 additions & 4 deletions
Large diffs are not rendered by default.

checkstyle.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183
<!-- See https://checkstyle.org/checks/misc/index.html -->
184184
<module name="ArrayTypeStyle"/>
185185
<!-- TODO <module name="FinalParameters"/> -->
186-
<!-- TODO <module name="TodoComment"/> -->
186+
<module name="TodoComment"/>
187187
<module name="UpperEll"/>
188188

189189
<!-- https://checkstyle.org/filters/suppressionxpathfilter.html -->

pom.xml

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<dependency>
2121
<groupId>org.junit</groupId>
2222
<artifactId>junit-bom</artifactId>
23-
<version>5.11.2</version>
23+
<version>5.11.3</version>
2424
<type>pom</type>
2525
<scope>import</scope>
2626
</dependency>
@@ -31,7 +31,7 @@
3131
<dependency>
3232
<groupId>org.junit.jupiter</groupId>
3333
<artifactId>junit-jupiter</artifactId>
34-
<version>5.11.2</version>
34+
<version>5.11.3</version>
3535
<scope>test</scope>
3636
</dependency>
3737
<dependency>
@@ -40,11 +40,18 @@
4040
<version>${assertj.version}</version>
4141
<scope>test</scope>
4242
</dependency>
43+
<dependency>
44+
<groupId>org.mockito</groupId>
45+
<artifactId>mockito-core</artifactId>
46+
<version>5.14.2</version>
47+
<scope>test</scope>
48+
</dependency>
49+
4350

4451
<dependency>
4552
<groupId>org.junit.jupiter</groupId>
4653
<artifactId>junit-jupiter-api</artifactId>
47-
<version>5.11.2</version>
54+
<version>5.11.3</version>
4855
<scope>test</scope>
4956
</dependency>
5057
<dependency>
@@ -63,7 +70,7 @@
6370
<plugins>
6471
<plugin>
6572
<artifactId>maven-surefire-plugin</artifactId>
66-
<version>3.5.0</version>
73+
<version>3.5.2</version>
6774
<configuration>
6875
<forkNode implementation="org.apache.maven.plugin.surefire.extensions.SurefireForkNodeFactory"/>
6976
</configuration>
@@ -107,7 +114,7 @@
107114
<plugin>
108115
<groupId>org.apache.maven.plugins</groupId>
109116
<artifactId>maven-checkstyle-plugin</artifactId>
110-
<version>3.5.0</version>
117+
<version>3.6.0</version>
111118
<configuration>
112119
<configLocation>checkstyle.xml</configLocation>
113120
<consoleOutput>true</consoleOutput>
@@ -118,14 +125,14 @@
118125
<dependency>
119126
<groupId>com.puppycrawl.tools</groupId>
120127
<artifactId>checkstyle</artifactId>
121-
<version>10.18.2</version>
128+
<version>10.20.1</version>
122129
</dependency>
123130
</dependencies>
124131
</plugin>
125132
<plugin>
126133
<groupId>com.github.spotbugs</groupId>
127134
<artifactId>spotbugs-maven-plugin</artifactId>
128-
<version>4.8.6.4</version>
135+
<version>4.8.6.5</version>
129136
<configuration>
130137
<excludeFilterFile>spotbugs-exclude.xml</excludeFilterFile>
131138
<includeTests>true</includeTests>
@@ -146,7 +153,7 @@
146153
<plugin>
147154
<groupId>org.apache.maven.plugins</groupId>
148155
<artifactId>maven-pmd-plugin</artifactId>
149-
<version>3.25.0</version>
156+
<version>3.26.0</version>
150157
<configuration>
151158
<printFailingErrors>true</printFailingErrors>
152159
<includeTests>true</includeTests>

spotbugs-exclude.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@
8787
<Bug pattern="RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE" />
8888
</Match>
8989
<!-- fb-contrib -->
90-
<Match>
91-
<Bug pattern="OCP_OVERLY_CONCRETE_PARAMETER" />
92-
</Match>
9390
<Match>
9491
<Bug pattern="LSC_LITERAL_STRING_COMPARISON" />
9592
</Match>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.thealgorithms.audiofilters;
2+
3+
/**
4+
* Exponential Moving Average (EMA) Filter for smoothing audio signals.
5+
*
6+
* <p>This filter applies an exponential moving average to a sequence of audio
7+
* signal values, making it useful for smoothing out rapid fluctuations.
8+
* The smoothing factor (alpha) controls the degree of smoothing.
9+
*
10+
* <p>Based on the definition from
11+
* <a href="https://en.wikipedia.org/wiki/Moving_average">Wikipedia link</a>.
12+
*/
13+
public class EMAFilter {
14+
private final double alpha;
15+
private double emaValue;
16+
/**
17+
* Constructs an EMA filter with a given smoothing factor.
18+
*
19+
* @param alpha Smoothing factor (0 < alpha <= 1)
20+
* @throws IllegalArgumentException if alpha is not in (0, 1]
21+
*/
22+
public EMAFilter(double alpha) {
23+
if (alpha <= 0 || alpha > 1) {
24+
throw new IllegalArgumentException("Alpha must be between 0 and 1.");
25+
}
26+
this.alpha = alpha;
27+
this.emaValue = 0.0;
28+
}
29+
/**
30+
* Applies the EMA filter to an audio signal array.
31+
*
32+
* @param audioSignal Array of audio samples to process
33+
* @return Array of processed (smoothed) samples
34+
*/
35+
public double[] apply(double[] audioSignal) {
36+
if (audioSignal.length == 0) {
37+
return new double[0];
38+
}
39+
double[] emaSignal = new double[audioSignal.length];
40+
emaValue = audioSignal[0];
41+
emaSignal[0] = emaValue;
42+
for (int i = 1; i < audioSignal.length; i++) {
43+
emaValue = alpha * audioSignal[i] + (1 - alpha) * emaValue;
44+
emaSignal[i] = emaValue;
45+
}
46+
return emaSignal;
47+
}
48+
}

src/main/java/com/thealgorithms/audiofilters/IIRFilter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void setCoeffs(double[] aCoeffs, double[] bCoeffs) throws IllegalArgument
5858
throw new IllegalArgumentException("bCoeffs must be of size " + order + ", got " + bCoeffs.length);
5959
}
6060

61-
for (int i = 0; i <= order; i++) {
61+
for (int i = 0; i < order; i++) {
6262
coeffsA[i] = aCoeffs[i];
6363
coeffsB[i] = bCoeffs[i];
6464
}

src/main/java/com/thealgorithms/backtracking/ArrayCombination.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,44 @@
44
import java.util.List;
55

66
/**
7-
* Finds all combinations of 0...n-1 of length k
7+
* This class provides methods to find all combinations of integers from 0 to n-1
8+
* of a specified length k using backtracking.
89
*/
910
public final class ArrayCombination {
1011
private ArrayCombination() {
1112
}
1213

1314
/**
14-
* Finds all combinations of length k of 0..n-1 using backtracking.
15+
* Generates all possible combinations of length k from the integers 0 to n-1.
1516
*
16-
* @param n Number of the elements.
17-
* @param k Length of the combination.
18-
* @return A list of all combinations of length k.
17+
* @param n The total number of elements (0 to n-1).
18+
* @param k The desired length of each combination.
19+
* @return A list containing all combinations of length k.
20+
* @throws IllegalArgumentException if n or k are negative, or if k is greater than n.
1921
*/
2022
public static List<List<Integer>> combination(int n, int k) {
2123
if (n < 0 || k < 0 || k > n) {
22-
throw new IllegalArgumentException("Wrong input.");
24+
throw new IllegalArgumentException("Invalid input: n must be non-negative, k must be non-negative and less than or equal to n.");
2325
}
2426

2527
List<List<Integer>> combinations = new ArrayList<>();
2628
combine(combinations, new ArrayList<>(), 0, n, k);
2729
return combinations;
2830
}
2931

32+
/**
33+
* A helper method that uses backtracking to find combinations.
34+
*
35+
* @param combinations The list to store all valid combinations found.
36+
* @param current The current combination being built.
37+
* @param start The starting index for the current recursion.
38+
* @param n The total number of elements (0 to n-1).
39+
* @param k The desired length of each combination.
40+
*/
3041
private static void combine(List<List<Integer>> combinations, List<Integer> current, int start, int n, int k) {
31-
if (current.size() == k) { // Base case: combination found
32-
combinations.add(new ArrayList<>(current)); // Copy to avoid modification
42+
// Base case: combination found
43+
if (current.size() == k) {
44+
combinations.add(new ArrayList<>(current));
3345
return;
3446
}
3547

src/main/java/com/thealgorithms/backtracking/Combination.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.thealgorithms.backtracking;
22

33
import java.util.Arrays;
4+
import java.util.Collections;
45
import java.util.LinkedList;
56
import java.util.List;
67
import java.util.TreeSet;
@@ -13,8 +14,6 @@ public final class Combination {
1314
private Combination() {
1415
}
1516

16-
private static int length;
17-
1817
/**
1918
* Find all combinations of given array using backtracking
2019
* @param arr the array.
@@ -23,39 +22,45 @@ private Combination() {
2322
* @return a list of all combinations of length n. If n == 0, return null.
2423
*/
2524
public static <T> List<TreeSet<T>> combination(T[] arr, int n) {
25+
if (n < 0) {
26+
throw new IllegalArgumentException("The combination length cannot be negative.");
27+
}
28+
2629
if (n == 0) {
27-
return null;
30+
return Collections.emptyList();
2831
}
29-
length = n;
3032
T[] array = arr.clone();
3133
Arrays.sort(array);
34+
3235
List<TreeSet<T>> result = new LinkedList<>();
33-
backtracking(array, 0, new TreeSet<T>(), result);
36+
backtracking(array, n, 0, new TreeSet<T>(), result);
3437
return result;
3538
}
3639

3740
/**
3841
* Backtrack all possible combinations of a given array
3942
* @param arr the array.
43+
* @param n length of the combination
4044
* @param index the starting index.
4145
* @param currSet set that tracks current combination
4246
* @param result the list contains all combination.
4347
* @param <T> the type of elements in the array.
4448
*/
45-
private static <T> void backtracking(T[] arr, int index, TreeSet<T> currSet, List<TreeSet<T>> result) {
46-
if (index + length - currSet.size() > arr.length) {
49+
private static <T> void backtracking(T[] arr, int n, int index, TreeSet<T> currSet, List<TreeSet<T>> result) {
50+
if (index + n - currSet.size() > arr.length) {
4751
return;
4852
}
49-
if (length - 1 == currSet.size()) {
53+
if (currSet.size() == n - 1) {
5054
for (int i = index; i < arr.length; i++) {
5155
currSet.add(arr[i]);
52-
result.add((TreeSet<T>) currSet.clone());
56+
result.add(new TreeSet<>(currSet));
5357
currSet.remove(arr[i]);
5458
}
59+
return;
5560
}
5661
for (int i = index; i < arr.length; i++) {
5762
currSet.add(arr[i]);
58-
backtracking(arr, i + 1, currSet, result);
63+
backtracking(arr, n, i + 1, currSet, result);
5964
currSet.remove(arr[i]);
6065
}
6166
}

0 commit comments

Comments
 (0)