NuriKit v0.1.0b2
Loading...
Searching...
No Matches
index_set.h
Go to the documentation of this file.
1//
2// Project NuriKit - Copyright 2025 SNU Compbio Lab.
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#ifndef NURI_CORE_CONTAINER_INDEX_SET_H_
7#define NURI_CORE_CONTAINER_INDEX_SET_H_
8
10#include <functional>
11#include <iterator>
12#include <utility>
13#include <vector>
14
15#include <absl/algorithm/container.h>
16#include <boost/container/flat_set.hpp>
18
20
21namespace nuri {
22namespace internal {
23 class IndexSet
24 : public boost::container::flat_set<int, std::less<>, std::vector<int>> {
25 private:
26 using Base = boost::container::flat_set<int, std::less<>, std::vector<int>>;
27
28 public:
29 using Base::Base;
30
31 explicit IndexSet(std::vector<int> &&vec) noexcept {
32 adopt_sequence(std::move(vec));
33 }
34
35 IndexSet(boost::container::ordered_unique_range_t tag,
36 std::vector<int> &&vec) noexcept {
37 adopt_sequence(tag, std::move(vec));
38 }
39
40 template <class UnaryPred>
41 void erase_if(UnaryPred &&pred) {
42 std::vector<int> work = extract_sequence();
43 nuri::erase_if(work, std::forward<UnaryPred>(pred));
44 adopt_sequence(boost::container::ordered_unique_range, std::move(work));
45 }
46
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));
52 }
53
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));
59 }
60
61 int operator[](int idx) const { return sequence()[idx]; }
62
63 int find_index(int id) const {
64 auto it = find(id);
65 return static_cast<int>(it - begin());
66 }
67
68 void remap(const std::vector<int> &old_to_new);
69 };
70} // namespace internal
71} // namespace nuri
72
73#endif /* NURI_CORE_CONTAINER_INDEX_SET_H_ */
Definition crdgen.h:16
std::vector< T, Alloc >::size_type erase_if(std::vector< T, Alloc > &c, Pred &&pred)
Definition container_ext.h:55