MCPcopy Create free account
hub / github.com/comaps/comaps / ExcludeUnavailableAndSortEndpoints

Method ExcludeUnavailableAndSortEndpoints

libs/storage/pinger.cpp:48–69  ·  view source on GitHub ↗

static

Source from the content-addressed store, hash-verified

46{
47// static
48Pinger::Endpoints Pinger::ExcludeUnavailableAndSortEndpoints(Endpoints const & urls)
49{
50 auto const size = urls.size();
51 CHECK_GREATER(size, 0, ());
52
53 using EntryT = std::pair<int64_t, size_t>;
54 std::vector<EntryT> timeUrls(size, {pinger::kInvalidPing, 0});
55 {
56 base::DelayedThreadPool pool(size, base::DelayedThreadPool::Exit::ExecPending);
57 for (size_t i = 0; i < size; ++i)
58 pool.Push([&urls, &timeUrls, i] { timeUrls[i] = {pinger::DoPing(urls[i]), i}; });
59 }
60
61 std::sort(timeUrls.begin(), timeUrls.end(), [](EntryT const & e1, EntryT const & e2) { return e1.first < e2.first; });
62
63 Endpoints readyUrls;
64 for (auto const & [ping, index] : timeUrls)
65 if (ping >= 0)
66 readyUrls.push_back(urls[index]);
67
68 return readyUrls;
69}
70} // namespace storage

Callers

nothing calls this directly

Calls 6

DoPingFunction · 0.85
sizeMethod · 0.45
PushMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected