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

Fixed+ #98

Merged
merged 6 commits into from
Dec 26, 2024
Merged
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
14 changes: 13 additions & 1 deletion src/algorithms/rmq/rmq_sparse_table.h
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, i never thought of this.

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@
#include <cassert>
#endif

#ifndef count_leading_zeroes
#if defined(_MSC_VER)
# if defined(_M_ARM) || defined(_M_ARM64)
# define count_leading_zeroes(x) _CountLeadingZeros(x);
# else
# define count_leading_zeroes(x) __lzcnt(x);
# endif
#else
# define count_leading_zeroes(x) __builtin_clz(x);
#endif
#endif


/**
* @brief credits to @nealwu for his RMQ query
Expand All @@ -15,7 +27,7 @@
template<typename T, bool maximum_mode = false>
struct RMQ {
static int highest_bit(unsigned x) {
return x == 0 ? -1 : 31 - __builtin_clz(x);
return x == 0 ? -1 : 31 - count_leading_zeroes(x);
}

int n = 0;
Expand Down
1 change: 1 addition & 0 deletions src/classes/list/skip_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <stdexcept>
#include <vector>
#include <unordered_set>
#include <string>
#endif

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/algorithms/sorting/minimum_swaps.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <random>
#include <vector>
#include <cstdlib>

#include <numeric>

TEST_CASE("Testing minimum swaps [1]") {
std::vector<int> a {3, 6, 4, 8};
Expand All @@ -28,8 +28,8 @@ TEST_CASE("Testing minimum swaps [3]") {

TEST_CASE("Testing minimum swaps [4]") {
std::vector<int> a(100), b(100);
iota(a.begin(), a.end(), 1);
iota(b.begin(), b.end(), 1);
std::iota(a.begin(), a.end(), 1);
std::iota(b.begin(), b.end(), 1);

std::swap(a[0], a[99]);
REQUIRE(minimum_swaps(a, b) == 1);
Expand Down
1 change: 1 addition & 0 deletions tests/machine_learning/image/image.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "../../../src/machine_learning/image/image.h"
#include "../../../third_party/catch.hpp"
#include <vector>
#include <numeric>

TEST_CASE("Testing default constructor of Image class") {
std::vector<std::vector<int32_t> > img = {{1,0,0}, {1,0,0}, {0,0,1}, {0,0,0}} ;
Expand Down
Loading