Replace boost::find() calls with std::ranges::find() and std::ranges::contains() to leverage modern C++ standard library features. This change reduces external dependencies and modernizes the codebase. The following changes were made: - Replaced boost::find() with std::ranges::find() where index/iterator is needed - Used std::ranges::contains() for simple element presence checks Signed-off-by: Kefu Chai <kefu.chai@scylladb.com> Closes scylladb/scylladb#22920
39 lines
1.1 KiB
C++
39 lines
1.1 KiB
C++
/*
|
|
* Copyright (C) 2020-present ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.0
|
|
*/
|
|
|
|
#include "test/lib/dummy_sharder.hh"
|
|
|
|
unsigned dummy_sharder::shard_of(const dht::token& t) const {
|
|
auto it = std::ranges::find(_tokens, t);
|
|
// Unknown tokens are assigned to shard 0
|
|
return it == _tokens.end() ? 0 : std::distance(_tokens.begin(), it) % sharder::shard_count();
|
|
}
|
|
|
|
dht::token dummy_sharder::token_for_next_shard(const dht::token& t, shard_id shard, unsigned spans) const {
|
|
// Find the first token that belongs to `shard` and is larger than `t`
|
|
auto it = std::find_if(_tokens.begin(), _tokens.end(), [this, &t, shard] (const dht::token& shard_token) {
|
|
return shard_token > t && shard_of(shard_token) == shard;
|
|
});
|
|
|
|
if (it == _tokens.end()) {
|
|
return dht::maximum_token();
|
|
}
|
|
|
|
--spans;
|
|
|
|
while (spans) {
|
|
if (std::distance(it, _tokens.end()) <= sharder::shard_count()) {
|
|
return dht::maximum_token();
|
|
}
|
|
it += sharder::shard_count();
|
|
--spans;
|
|
}
|
|
|
|
return *it;
|
|
}
|