@@ -1,6 +1,7 @@
|
||||
#ifndef LIBCATBOY_ECS_SPARSE_SET_HPP
|
||||
#define LIBCATBOY_ECS_SPARSE_SET_HPP
|
||||
|
||||
#include <span>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
@@ -18,8 +19,11 @@ public:
|
||||
isparse_set(const isparse_set&) = default;
|
||||
isparse_set& operator=(const isparse_set&) = default;
|
||||
public:
|
||||
virtual bool contains(std::size_t key) const noexcept = 0;
|
||||
virtual void erase(std::size_t key) noexcept = 0;
|
||||
virtual bool contains(std::size_t key) const noexcept = 0;
|
||||
virtual void erase(std::size_t key) noexcept = 0;
|
||||
virtual std::size_t size() const noexcept = 0;
|
||||
virtual std::size_t sparse_size() const noexcept = 0;
|
||||
virtual std::span<std::size_t> dense_map() noexcept = 0;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
@@ -70,6 +74,14 @@ public:
|
||||
m_reverseMap.pop_back();
|
||||
set_index(key, TOMBSTONE);
|
||||
}
|
||||
public:
|
||||
std::size_t size() const noexcept override { return m_dense.size(); }
|
||||
|
||||
std::size_t sparse_size() const noexcept override { return m_map.size(); }
|
||||
|
||||
std::span<std::size_t> dense_map() noexcept override {
|
||||
return m_reverseMap;
|
||||
}
|
||||
private:
|
||||
void set_index(std::size_t key, std::size_t dense) {
|
||||
if (key >= m_map.size()) m_map.resize(key + 1, TOMBSTONE);
|
||||
|
||||
Reference in New Issue
Block a user