Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Artemis: Proposed changes for increased performance #35

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/datastructures/list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ OpsList::Shuffle(std::list<int> &l) {
* @param end the end index of the slice (exclusive)
* @return a new list with the elements of l sliced
*/
std::list<int>
OpsList::Slice(std::list<int> &l, int start, int end) {
std::list<int> OpsList::Slice(std::list<int> &l, int start, int end) {
std::list<int> ret;
for (int i = start; i < end; i++) {
std::list<int>::iterator it = l.begin();
std::advance(it, i);
ret.push_back(*it);
auto it = l.begin();
std::advance(it, start);
for (int i = start; i < end && it != l.end(); i++) {
ret.push_back(*it++);
}
return ret;
}
}
23 changes: 6 additions & 17 deletions src/datastructures/vector.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <algorithm>
#include "vector.h"

void
Expand Down Expand Up @@ -55,20 +56,9 @@ OpsVector::SearchVector(std::vector<int> &v, int n) {
* @param v Vector to sort.
* @return The sorted vector.
*/
std::vector<int>
OpsVector::SortVector(std::vector<int> &v) {
std::vector<int> ret(v);

for (int i = 0; i < (int) ret.size(); i += 1) {
for (int j = 0; j < (int) ret.size() - 1; j += 1) {
if (ret[j] > ret[j + 1]) {
int temp = ret[j];
ret[j] = ret[j + 1];
ret[j + 1] = temp;
}
}
}
return ret;
std::vector<int> OpsVector::SortVector(std::vector<int> &v) {
std::sort(v.begin(), v.end());
return v;
}

/**
Expand All @@ -94,8 +84,7 @@ OpsVector::ReverseVector(std::vector<int> &v) {
* @param n Number of elements to rotate by.
* @return The rotated vector.
*/
std::vector<int>
OpsVector::RotateVector(std::vector<int> &v, int n) {
std::vector<int> OpsVector::RotateVector(std::vector<int> &v, int n) {
std::vector<int> ret;

for (int i = n; i < (int) v.size(); i += 1) {
Expand Down Expand Up @@ -126,4 +115,4 @@ OpsVector::MergeVectors(std::vector<int> &v1, std::vector<int> &v2) {
}

return ret;
}
}
13 changes: 6 additions & 7 deletions src/math/vectoralgebra.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,22 @@ MathVectorAlgebra::Cubic(int a, int b, int c, int d, std::vector<double> &x) {
*
* @return Pointer to array of y values (output)
*/
std::vector<double>
MathVectorAlgebra::Convolve(int offset, std::vector<double> &h, std::vector<double> &x) {
std::vector<double> MathVectorAlgebra::Convolve(int offset, std::vector<double> &h, std::vector<double> &x) {
int m = h.size();
int n = x.size();
int sum_h = 0;
std::vector<double> y = std::vector<double>(n);
double sum_h = 0;
std::vector<double> y(n, 0);
for (int i = 0; i < m; i += 1) {
sum_h += std::abs(h[i]);
}
if (sum_h == 0) {
sum_h = 1;
}
for (int i = 0; i < n; i += 1) {
y[i] = 0;
for (int j = 0; j < m; j += 1) {
if (i - offset + j >= 0 && i - offset + j < n) {
y[i] += h[j] * x[i - offset + j] / sum_h;
int idx = i - offset + j;
if (idx >= 0 && idx < n) {
y[i] += h[j] * x[idx] / sum_h;
}
}
}
Expand Down
9 changes: 2 additions & 7 deletions src/strings/strops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

std::string
StrOps::ReverseString(std::string &s) {
std::string ret;

for (std::string::reverse_iterator rit = s.rbegin(); rit != s.rend(); ++rit) {
ret.insert(ret.end(), *rit);
}
return ret;
return {s.crbegin(), s.crend()};
}

bool
Expand All @@ -18,4 +13,4 @@ StrOps::IsPalindrome(const std::string &s) {
}

return false;
}
}