Skip to content

Commit

Permalink
Major rework to header files | clang-tidy integration
Browse files Browse the repository at this point in the history
  • Loading branch information
spirosmaggioros committed Jul 6, 2024
1 parent df9f7a3 commit 542006d
Show file tree
Hide file tree
Showing 63 changed files with 35 additions and 91 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/cmake-single-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ jobs:
- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}

- name: Test
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest --output-on-failure
- name: clang-tidy
run: bash ../clang_tidy.sh
#- name: get coverage
# run: make coverage
#- name: Run tests and collect coverage
Expand Down
1 change: 1 addition & 0 deletions clang_tidy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
find src/ -name '*.h' -exec clang-tidy {} -- -x c++ -std=c++17 \;
1 change: 0 additions & 1 deletion src/algorithms/dynamic_programming/coin_change.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#ifndef COIN_CHANGE_H
#define COIN_CHANGE_H

Expand Down
3 changes: 1 addition & 2 deletions src/algorithms/dynamic_programming/fib.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#ifndef FIB_H
#define FIB_H

Expand Down Expand Up @@ -67,4 +66,4 @@ int64_t fibonacci_binet(int64_t n) {
double phi = (std::sqrt(5) + 1) / 2;
return (int64_t)std::round(std::pow(phi, n) / sqrt(5));
}
#endif
#endif
1 change: 0 additions & 1 deletion src/algorithms/dynamic_programming/kadane.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#ifndef KADANE_H
#define KADANE_H

Expand Down
10 changes: 5 additions & 5 deletions src/algorithms/dynamic_programming/lcs.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#pragma once
#ifndef LCS_H
#define LCS_H

#ifdef __cplusplus
#include <cstdint>
#include <iostream>
#include <string>
#include <vector>
#endif

/**
Expand All @@ -15,10 +15,10 @@
* @param b second input string
* @return int64_t the longest common subsequence of a to b
*/
int64_t lcs(std::string a, std::string b) {
int64_t lcs(const std::string a, const std::string b) {
int64_t m = a.length(), n = b.length();
int64_t res[m + 1][n + 1];
int64_t trace[20][20];
std::vector<std::vector<int64_t> > res(m + 1, std::vector<int64_t>(n + 1));
std::vector<std::vector<int64_t> > trace(20, std::vector<int64_t>(20));

for (int64_t i = 0; i < m + 1; i++) {
for (int64_t j = 0; j < n + 1; j++) {
Expand Down Expand Up @@ -52,4 +52,4 @@ int64_t lcs(std::string a, std::string b) {
return res[m][n];
}

#endif
#endif
3 changes: 1 addition & 2 deletions src/algorithms/dynamic_programming/lis.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#ifndef LIS_H
#define LIS_H

Expand Down Expand Up @@ -27,4 +26,4 @@ template <typename T> int64_t lis(std::vector<T> arr) {
return ans.size();
}

#endif
#endif
3 changes: 1 addition & 2 deletions src/algorithms/number_theory/eratosthenes_sieve.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#ifndef ERATOSTHENES_SIEVE_H
#define ERATOSTHENES_SIEVE_H

Expand Down Expand Up @@ -27,4 +26,4 @@ std::vector<bool> soe(int64_t n) {
return prime;
}

#endif
#endif
3 changes: 1 addition & 2 deletions src/algorithms/number_theory/gcd.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#ifndef GCD_H
#define GCD_H

Expand Down Expand Up @@ -60,4 +59,4 @@ int64_t euclidean_gcd(int64_t a, int64_t b) {
return (a + b);
}

#endif
#endif
3 changes: 1 addition & 2 deletions src/algorithms/number_theory/mersenne_primes.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#ifndef MERSENNE_PRIMES_H
#define MERSENNE_PRIMES_H

Expand All @@ -25,4 +24,4 @@ std::vector<int> mersenne(int64_t n) {
}
return elements;
}
#endif
#endif
1 change: 0 additions & 1 deletion src/algorithms/searching/bfs.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#ifndef BFS_H
#define BFS_H

Expand Down
1 change: 0 additions & 1 deletion src/algorithms/searching/binary_search.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#ifndef BINARY_SEARCH_H
#define BINARY_SEARCH_H

Expand Down
1 change: 0 additions & 1 deletion src/algorithms/searching/dfs.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#ifndef DFS_H
#define DFS_H

Expand Down
3 changes: 1 addition & 2 deletions src/algorithms/searching/exponential_search.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#ifndef EXPONENTIAL_SEARCH_H
#define EXPONENTIAL_SEARCH_H

Expand Down Expand Up @@ -36,4 +35,4 @@ template <typename T> int64_t exponential_search(std::vector<T> arr, T key) {
return -1;
}

#endif
#endif
1 change: 0 additions & 1 deletion src/algorithms/searching/interpolation_search.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#ifndef INTERPOLATION_SEARCH_H
#define INTERPOLATION_SEARCH_H

Expand Down
3 changes: 1 addition & 2 deletions src/algorithms/searching/jump_search.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#ifndef JUMP_SEARCH_H
#define JUMP_SEARCH_H

Expand Down Expand Up @@ -33,4 +32,4 @@ template <typename T> int64_t jump_search(std::vector<T> arr, T key) {
return (arr[prev] == key) ? prev : -1;
}

#endif
#endif
3 changes: 1 addition & 2 deletions src/algorithms/searching/linear_search.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#ifndef LINEAR_SEARCH_H
#define LINEAR_SEARCH_H

Expand All @@ -23,4 +22,4 @@ template <typename T> bool linear_search(std::vector<T> arr, T key) {
return false;
}

#endif
#endif
1 change: 0 additions & 1 deletion src/algorithms/searching/ternary_search.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#ifndef TERNARY_SEARCH_H
#define TERNARY_SEARCH_H

Expand Down
3 changes: 1 addition & 2 deletions src/algorithms/sorting/bubble_sort.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#ifndef BUBBLE_SORT_H
#define BUBBLE_SORT_H

Expand Down Expand Up @@ -27,4 +26,4 @@ template <typename T> void bubble_sort(std::vector<T> &arr) {
}
}

#endif
#endif
1 change: 0 additions & 1 deletion src/algorithms/sorting/bucket_sort.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#ifndef BUCKET_SORT_H
#define BUCKET_SORT_H

Expand Down
1 change: 0 additions & 1 deletion src/algorithms/sorting/counting_sort.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#ifndef ALGOPLUS_COUNTING_SORT_H
#define ALGOPLUS_COUNTING_SORT_H

Expand Down
2 changes: 1 addition & 1 deletion src/algorithms/sorting/heap_sort.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ template <typename T> void heap_sort(std::vector<T> &arr) {
}
}

#endif
#endif
3 changes: 1 addition & 2 deletions src/algorithms/sorting/insertion_sort.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#ifndef INSERTION_SORT_H
#define INSERTION_SORT_H

Expand All @@ -22,4 +21,4 @@ template <typename T> void insertion_sort(std::vector<T> &arr) {
}
}

#endif
#endif
1 change: 0 additions & 1 deletion src/algorithms/sorting/merge_sort.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#ifndef MERGE_SORT_H
#define MERGE_SORT_H

Expand Down
1 change: 0 additions & 1 deletion src/algorithms/sorting/quick_sort.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#ifndef ALGOPLUS_QUICK_SORT_H
#define ALGOPLUS_QUICK_SORT_H

Expand Down
1 change: 0 additions & 1 deletion src/algorithms/sorting/radix_sort.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#ifndef RADIX_SORT_H
#define RADIX_SORT_H

Expand Down
3 changes: 1 addition & 2 deletions src/algorithms/sorting/selection_sort.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#ifndef SELECTION_SORT_H
#define SELECTION_SORT_H

Expand Down Expand Up @@ -27,4 +26,4 @@ template <typename T> void selection_sort(std::vector<T> &arr) {
}
}

#endif
#endif
8 changes: 4 additions & 4 deletions src/algorithms/string/edit_distance.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#pragma once
#ifndef MIN_DISTANCE_H
#define MIN_DISTANCE_H

#ifdef __cplusplus
#include <cstdint>
#include <iostream>
#include <string>
#include <vector>
#endif

/**
Expand All @@ -15,7 +15,7 @@
* @return int64_t the minimum steps to make word1 equal to word2(i.e. the
* distance of word1 and word2)
*/
int64_t min_dist(std::string word1, std::string word2) {
int64_t min_dist(const std::string word1, const std::string word2) {
if (word1.size() == 0 && word2.size() == 0) {
return 0;
}
Expand All @@ -26,7 +26,7 @@ int64_t min_dist(std::string word1, std::string word2) {
return word1.size();
}
int n = word1.size(), w = word2.size();
int dp[n + 1][w + 1];
std::vector<std::vector<int> > dp(n + 1, std::vector<int>(w + 1));
for (int i = 0; i <= n; i++) {
dp[i][0] = i;
}
Expand All @@ -49,4 +49,4 @@ int64_t min_dist(std::string word1, std::string word2) {
return dp[n][w];
}

#endif
#endif
3 changes: 1 addition & 2 deletions src/algorithms/string/find_and_replace.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#ifndef ALGOPLUS_REGEX_PATTERNS_H
#define ALGOPLUS_REGEX_PATTERNS_H

Expand Down Expand Up @@ -51,4 +50,4 @@ void find_and_replace(std::string &str, const std::string pattern,
}
}

#endif // ALGOPLUS_REGEX_PATTERNS_H
#endif // ALGOPLUS_REGEX_PATTERNS_H
3 changes: 1 addition & 2 deletions src/algorithms/string/kmp.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#ifndef KMP_H
#define KMP_H

Expand Down Expand Up @@ -42,4 +41,4 @@ bool kmp(std::string pattern, std::string text) {
return false;
}

#endif
#endif
2 changes: 1 addition & 1 deletion src/algorithms/string/rabin_karp.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,4 @@ std::vector<size_t> rabin_karp(const std::string &text, const std::string &patte
return result;
}

#endif
#endif
3 changes: 1 addition & 2 deletions src/classes/disjoint_set/disjoint_set.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#ifndef DISJOINT_SET_H
#define DISJOINT_SET_H

Expand Down Expand Up @@ -132,4 +131,4 @@ class dsu {
int64_t get_min(int64_t i) { return min_el[find(i)]; }
};

#endif
#endif
1 change: 0 additions & 1 deletion src/classes/graph/graph.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#ifndef GRAPH_H
#define GRAPH_H

Expand Down
1 change: 0 additions & 1 deletion src/classes/hash_table/hash_table.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#ifndef HASH_TABLE_H
#define HASH_TABLE_H

Expand Down
3 changes: 1 addition & 2 deletions src/classes/heap/min_heap.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#ifndef MIN_HEAP_H
#define MIN_HEAP_H
#ifdef __cplusplus
Expand Down Expand Up @@ -144,4 +143,4 @@ template <typename T> class min_heap {
}
};

#endif
#endif
3 changes: 1 addition & 2 deletions src/classes/list/circular_linked_list.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#ifndef CIRCULAR_LINKED_LIST_H
#define CIRCULAR_LINKED_LIST_H

Expand Down Expand Up @@ -375,4 +374,4 @@ template <typename T> class circular_linked_list<T>::Iterator {
*/
T operator*() { return curr_root->val; }
};
#endif
#endif
1 change: 0 additions & 1 deletion src/classes/list/doubly_linked_list.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#ifndef DOUBLY_LINKED_LIST_H
#define DOUBLY_LINKED_LIST_H

Expand Down
1 change: 0 additions & 1 deletion src/classes/list/frequency_list.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#ifndef FREQUENCY_LIST_H
#define FREQUENCY_LIST_H

Expand Down
1 change: 0 additions & 1 deletion src/classes/list/linked_list.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#ifndef LINKED_LIST_H
#define LINKED_LIST_H

Expand Down
1 change: 0 additions & 1 deletion src/classes/list/skip_list.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#ifndef SKIP_LIST_H
#define SKIP_LIST_H

Expand Down
3 changes: 1 addition & 2 deletions src/classes/queue/dequeue_list.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#pragma once
#ifndef QUEUE_H
#define QUEUE_H

Expand Down Expand Up @@ -241,4 +240,4 @@ template <typename T> class dequeue_list<T>::Iterator {
T operator*() { return curr_root->val; }
};

#endif
#endif
Loading

0 comments on commit 542006d

Please sign in to comment.