Skip to content

Commit

Permalink
Lab function inlining 1
Browse files Browse the repository at this point in the history
  • Loading branch information
simveit committed Dec 19, 2024
1 parent d18afd0 commit ce07752
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
21 changes: 1 addition & 20 deletions labs/core_bound/function_inlining_1/solution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,6 @@
#include <algorithm>
#include <stdlib.h>

static int compare(const void *lhs, const void *rhs) {
auto &a = *reinterpret_cast<const S *>(lhs);
auto &b = *reinterpret_cast<const S *>(rhs);

if (a.key1 < b.key1)
return -1;

if (a.key1 > b.key1)
return 1;

if (a.key2 < b.key2)
return -1;

if (a.key2 > b.key2)
return 1;

return 0;
}

void solution(std::array<S, N> &arr) {
qsort(arr.data(), arr.size(), sizeof(S), compare);
std::sort(arr.begin(), arr.end());
}
16 changes: 16 additions & 0 deletions labs/core_bound/function_inlining_1/solution.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ constexpr size_t N = 10000;
struct S {
uint32_t key1;
uint32_t key2;

bool operator<(const S &other) const {
if (key1 < other.key1) {
return true;
}
if (key1 > other.key1) {
return false;
}
if (key2 < other.key2) {
return true;
}
if (key2 > other.key2) {
return false;
}
}

};

void init(std::array<S, N> &arr);
Expand Down

0 comments on commit ce07752

Please sign in to comment.