CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
IndexSet.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8// Based on https://github.com/TheLartians/IndexSet
9
10#pragma once
11
12#pragma once
13
14#include "BitView.hpp"
15
17
20
21#include <ostream>
22
23namespace CeresEngine {
24
25 struct IndexSet {
26 public:
30 using Index = std::size_t;
31
36
37 void fit() {
38 while(current != max && !bits[current])
39 ++current;
40 }
41
42 [[nodiscard]] bool init() {
43 fit();
44 return current != max;
45 }
46
47 [[nodiscard]] bool advance() {
48 ++current;
49 fit();
50 return current != max;
51 }
52
53 [[nodiscard]] IndexSet::Index value() const { return current; }
54 };
55
56 private:
58 void tighten();
59
60 public:
63
64 void ensureFits(Index idx);
65
66 [[nodiscard]] bool hasIndex(Index idx) const;
67 void addIndex(Index idx);
68 void removeIndex(Index idx);
69
70 void add(const IndexSet& other);
71 void remove(const IndexSet& other);
72 void intersect(const IndexSet& other);
73 void clear();
74
75 [[nodiscard]] size_t upperBound() const;
76 [[nodiscard]] bool isEmpty() const;
77 [[nodiscard]] size_t count() const;
78
79 [[nodiscard]] bool operator==(const IndexSet&) const;
80 [[nodiscard]] bool operator!=(const IndexSet&) const;
81
83 };
84
87 std::ostream& operator<<(std::ostream&, const IndexSet&);
88
89} // namespace CeresEngine
Definition BitView.hpp:101
Definition Application.hpp:19
IndexSet createIndexSetFromIndices(const Vector< IndexSet::Index > &input)
constexpr Byte operator<<(const Byte arg, const _IntType shift) noexcept
Definition DataTypes.hpp:44
std::vector< T, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > Vector
Vector is a sequence container that encapsulates dynamic size arrays.
Definition Vector.hpp:17
IndexSet createIndexSetFromIndex(IndexSet::Index idx)
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Definition IndexSet.hpp:32
bool advance()
Definition IndexSet.hpp:47
void fit()
Definition IndexSet.hpp:37
Index current
Definition IndexSet.hpp:33
Index max
Definition IndexSet.hpp:33
IndexIterator(const IndexSet::Index c, const IndexSet::Index m, const IndexSet::ConstBits b)
Definition IndexSet.hpp:35
ConstBits bits
Definition IndexSet.hpp:34
bool init()
Definition IndexSet.hpp:42
IndexSet::Index value() const
Definition IndexSet.hpp:53
Definition IndexSet.hpp:25
void ensureFits(Index idx)
void intersect(const IndexSet &other)
void add(const IndexSet &other)
bool operator!=(const IndexSet &) const
bool operator==(const IndexSet &) const
void addIndex(Index idx)
std::size_t Index
Definition IndexSet.hpp:30
bool hasIndex(Index idx) const
Vector< UInt32 > Data
Definition IndexSet.hpp:27
void remove(const IndexSet &other)
size_t count() const
auto indices() const
Definition IndexSet.hpp:82
bool isEmpty() const
void removeIndex(Index idx)
size_t upperBound() const
ConstBits getBitView() const
Data mData
Definition IndexSet.hpp:57
When used as a base class for a iterator type, MakeIterable will call the bool init() member before i...
Definition Iterator.hpp:523