6#ifndef NURI_CORE_CONTAINER_INDEX_SET_H_
7#define NURI_CORE_CONTAINER_INDEX_SET_H_
15#include <absl/algorithm/container.h>
16#include <boost/container/flat_set.hpp>
24 :
public boost::container::flat_set<int, std::less<>, std::vector<int>> {
26 using Base = boost::container::flat_set<int, std::less<>, std::vector<int>>;
31 explicit IndexSet(std::vector<int> &&vec)
noexcept {
32 adopt_sequence(std::move(vec));
35 IndexSet(boost::container::ordered_unique_range_t tag,
36 std::vector<int> &&vec)
noexcept {
37 adopt_sequence(tag, std::move(vec));
40 template <
class UnaryPred>
41 void erase_if(UnaryPred &&pred) {
42 std::vector<int> work = extract_sequence();
44 adopt_sequence(boost::container::ordered_unique_range, std::move(work));
47 void union_with(
const IndexSet &other) {
48 std::vector<int> result;
49 result.reserve(size() + other.size());
50 absl::c_set_union(*
this, other, std::back_inserter(result));
51 adopt_sequence(boost::container::ordered_unique_range, std::move(result));
54 void difference(
const IndexSet &other) {
55 std::vector<int> result;
56 result.reserve(size());
57 absl::c_set_difference(*
this, other, std::back_inserter(result));
58 adopt_sequence(boost::container::ordered_unique_range, std::move(result));
61 int operator[](
int idx)
const {
return sequence()[idx]; }
63 int find_index(
int id)
const {
65 return static_cast<int>(it - begin());
68 void remap(
const std::vector<int> &old_to_new);
std::vector< T, Alloc >::size_type erase_if(std::vector< T, Alloc > &c, Pred &&pred)
Definition container_ext.h:55