From f66da5e5ee01913e35a8f84b544e68adf2485425 Mon Sep 17 00:00:00 2001 From: Hardik Pawar <97388607+Hardvan@users.noreply.github.com> Date: Thu, 23 Oct 2025 01:12:11 +0530 Subject: [PATCH] refactor: Enhance docs, add tests in `PrintMatrixInSpiralOrder` (#6636) * refactor: Enhance docs, add tests in `PrintMatrixInSpiralOrder` * Fix error in BloomFilter * Fix * Fix * Fix --- .../bloomfilter/BloomFilter.java | 33 +++++--- .../matrix/PrintAMatrixInSpiralOrder.java | 36 ++++++-- .../others/PrintAMatrixInSpiralOrder.java | 52 ------------ .../matrix/PrintAMatrixInSpiralOrderTest.java | 83 +++++++++++++++++++ .../matrix/TestPrintMatrixInSpiralOrder.java | 26 ------ .../others/TestPrintMatrixInSpiralOrder.java | 26 ------ 6 files changed, 135 insertions(+), 121 deletions(-) delete mode 100644 src/main/java/com/thealgorithms/others/PrintAMatrixInSpiralOrder.java create mode 100644 src/test/java/com/thealgorithms/matrix/PrintAMatrixInSpiralOrderTest.java delete mode 100644 src/test/java/com/thealgorithms/matrix/TestPrintMatrixInSpiralOrder.java delete mode 100644 src/test/java/com/thealgorithms/others/TestPrintMatrixInSpiralOrder.java diff --git a/src/main/java/com/thealgorithms/datastructures/bloomfilter/BloomFilter.java b/src/main/java/com/thealgorithms/datastructures/bloomfilter/BloomFilter.java index c84f25bd7..90625ad1c 100644 --- a/src/main/java/com/thealgorithms/datastructures/bloomfilter/BloomFilter.java +++ b/src/main/java/com/thealgorithms/datastructures/bloomfilter/BloomFilter.java @@ -6,8 +6,10 @@ import java.util.BitSet; /** * A generic BloomFilter implementation for probabilistic membership checking. *
- * Bloom filters are space-efficient data structures that provide a fast way to test whether an - * element is a member of a set. They may produce false positives, indicating an element is + * Bloom filters are space-efficient data structures that provide a fast way to + * test whether an + * element is a member of a set. They may produce false positives, indicating an + * element is * in the set when it is not, but they will never produce false negatives. *
* @@ -21,11 +23,14 @@ public class BloomFilter- * This method hashes the element using all defined hash functions and sets the corresponding + * This method hashes the element using all defined hash functions and sets the + * corresponding * bits in the bit array. *
* @@ -66,13 +73,16 @@ public class BloomFilter- * This method checks the bits at the positions computed by each hash function. If any of these - * bits are not set, the element is definitely not in the filter. If all bits are set, the element + * This method checks the bits at the positions computed by each hash function. + * If any of these + * bits are not set, the element is definitely not in the filter. If all bits + * are set, the element * might be in the filter. *
* * @param key the element to check for membership in the Bloom filter - * @return {@code true} if the element might be in the Bloom filter, {@code false} if it is definitely not + * @return {@code true} if the element might be in the Bloom filter, + * {@code false} if it is definitely not */ public boolean contains(T key) { for (Hash- * Each instance of this class represents a different hash function based on its index. + * Each instance of this class represents a different hash function based on its + * index. *
* * @param+ * Given a 2D array (matrix), this class provides a method to return the + * elements + * of the matrix in spiral order, starting from the top-left corner and moving + * clockwise. + *
+ * + * @author Sadiul Hakim (https://github.com/sadiul-hakim) + */ public class PrintAMatrixInSpiralOrder { + /** - * Search a key in row and column wise sorted matrix + * Returns the elements of the given matrix in spiral order. * - * @param matrix matrix to be searched - * @param row number of rows matrix has - * @param col number of columns matrix has - * @author Sadiul Hakim : https://github.com/sadiul-hakim + * @param matrix the 2D array to traverse in spiral order + * @param row the number of rows in the matrix + * @param col the number of columns in the matrix + * @return a list containing the elements of the matrix in spiral order + * + *+ * Example: + * + *
+ * int[][] matrix = {
+ * {1, 2, 3},
+ * {4, 5, 6},
+ * {7, 8, 9}
+ * };
+ * print(matrix, 3, 3) returns [1, 2, 3, 6, 9, 8, 7, 4, 5]
+ *
+ *
*/
public List