/* * Copyright (C) 2025-present ScyllaDB */ /* * SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.0 */ #pragma once #include "seastar/core/shared_ptr.hh" #include namespace vector_search { template class load_balancer { public: load_balancer(std::vector> container, RandomNumberEngine& g) : _container(std::move(container)) , _g(g) { } seastar::lw_shared_ptr next() { if (_container.empty()) { return nullptr; } return pop(randomize_index()); } private: using distribution = std::uniform_int_distribution; size_t randomize_index() { return _dist(_g, distribution::param_type(0, _container.size() - 1)); } seastar::lw_shared_ptr pop(size_t index) { auto ret = _container[index]; std::swap(_container[index], _container.back()); _container.pop_back(); return ret; } std::vector> _container; RandomNumberEngine& _g; distribution _dist; }; } // namespace vector_search