Blender V4.3
BLI_vector_set_slots.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
27#include "BLI_sys_types.h"
28
29namespace blender {
30
35template<typename Key, typename IndexT = int64_t> class SimpleVectorSetSlot {
36 static_assert(std::is_integral_v<IndexT> && std::is_signed_v<IndexT>);
37
38 private:
39#define s_is_empty -1
40#define s_is_removed -2
41
45 IndexT state_ = s_is_empty;
46
47 public:
51 bool is_occupied() const
52 {
53 return state_ >= 0;
54 }
55
59 bool is_empty() const
60 {
61 return state_ == s_is_empty;
62 }
63
67 IndexT index() const
68 {
69 BLI_assert(this->is_occupied());
70 return state_;
71 }
72
77 template<typename ForwardKey, typename IsEqual>
78 bool contains(const ForwardKey &key,
79 const IsEqual &is_equal,
80 uint64_t /*hash*/,
81 const Key *keys) const
82 {
83 if (state_ >= 0) {
84 return is_equal(key, keys[state_]);
85 }
86 return false;
87 }
88
93 void occupy(IndexT index, uint64_t /*hash*/)
94 {
95 BLI_assert(!this->is_occupied());
96 state_ = index;
97 }
98
103 void update_index(IndexT index)
104 {
105 BLI_assert(this->is_occupied());
106 state_ = index;
107 }
108
112 void remove()
113 {
114 BLI_assert(this->is_occupied());
115 state_ = s_is_removed;
116 }
117
121 bool has_index(IndexT index) const
122 {
123 return state_ == index;
124 }
125
130 template<typename Hash> uint64_t get_hash(const Key &key, const Hash &hash) const
131 {
132 BLI_assert(this->is_occupied());
133 return hash(key);
134 }
135
136#undef s_is_empty
137#undef s_is_removed
138};
139
140template<typename Key> struct DefaultVectorSetSlot;
141
142template<typename Key> struct DefaultVectorSetSlot {
144};
145
146} // namespace blender
#define BLI_assert(a)
Definition BLI_assert.h:50
#define s_is_removed
#define s_is_empty
bool contains(const ForwardKey &key, const IsEqual &is_equal, uint64_t, const Key *keys) const
bool has_index(IndexT index) const
void occupy(IndexT index, uint64_t)
uint64_t get_hash(const Key &key, const Hash &hash) const
#define hash
Definition noise.c:154
unsigned __int64 uint64_t
Definition stdint.h:90