Blender  V3.3
BLI_vector_set_slots.hh
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #pragma once
4 
25 #include "BLI_sys_types.h"
26 
27 namespace blender {
28 
33 template<typename Key> class SimpleVectorSetSlot {
34  private:
35 #define s_is_empty -1
36 #define s_is_removed -2
37 
41  int64_t state_ = s_is_empty;
42 
43  public:
47  bool is_occupied() const
48  {
49  return state_ >= 0;
50  }
51 
55  bool is_empty() const
56  {
57  return state_ == s_is_empty;
58  }
59 
63  int64_t index() const
64  {
65  BLI_assert(this->is_occupied());
66  return state_;
67  }
68 
73  template<typename ForwardKey, typename IsEqual>
74  bool contains(const ForwardKey &key,
75  const IsEqual &is_equal,
77  const Key *keys) const
78  {
79  if (state_ >= 0) {
80  return is_equal(key, keys[state_]);
81  }
82  return false;
83  }
84 
90  {
91  BLI_assert(!this->is_occupied());
92  state_ = index;
93  }
94 
100  {
101  BLI_assert(this->is_occupied());
102  state_ = index;
103  }
104 
108  void remove()
109  {
110  BLI_assert(this->is_occupied());
111  state_ = s_is_removed;
112  }
113 
117  bool has_index(int64_t index) const
118  {
119  return state_ == index;
120  }
121 
126  template<typename Hash> uint64_t get_hash(const Key &key, const Hash &hash) const
127  {
128  BLI_assert(this->is_occupied());
129  return hash(key);
130  }
131 
132 #undef s_is_empty
133 #undef s_is_removed
134 };
135 
136 template<typename Key> struct DefaultVectorSetSlot;
137 
138 template<typename Key> struct DefaultVectorSetSlot {
140 };
141 
142 } // namespace blender
#define BLI_assert(a)
Definition: BLI_assert.h:46
#define UNUSED(x)
#define s_is_removed
#define s_is_empty
bool has_index(int64_t index) const
void occupy(int64_t index, uint64_t UNUSED(hash))
bool contains(const ForwardKey &key, const IsEqual &is_equal, uint64_t UNUSED(hash), const Key *keys) const
uint64_t get_hash(const Key &key, const Hash &hash) const
#define hash
Definition: noise.c:153
__int64 int64_t
Definition: stdint.h:89
unsigned __int64 uint64_t
Definition: stdint.h:90