Blender  V2.93
BLI_vector_set_slots.hh
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #pragma once
18 
39 #include "BLI_sys_types.h"
40 
41 namespace blender {
42 
47 template<typename Key> class SimpleVectorSetSlot {
48  private:
49 #define s_is_empty -1
50 #define s_is_removed -2
51 
55  int64_t state_ = s_is_empty;
56 
57  public:
61  bool is_occupied() const
62  {
63  return state_ >= 0;
64  }
65 
69  bool is_empty() const
70  {
71  return state_ == s_is_empty;
72  }
73 
77  int64_t index() const
78  {
79  BLI_assert(this->is_occupied());
80  return state_;
81  }
82 
87  template<typename ForwardKey, typename IsEqual>
88  bool contains(const ForwardKey &key,
89  const IsEqual &is_equal,
91  const Key *keys) const
92  {
93  if (state_ >= 0) {
94  return is_equal(key, keys[state_]);
95  }
96  return false;
97  }
98 
104  {
105  BLI_assert(!this->is_occupied());
106  state_ = index;
107  }
108 
114  {
115  BLI_assert(this->is_occupied());
116  state_ = index;
117  }
118 
122  void remove()
123  {
124  BLI_assert(this->is_occupied());
125  state_ = s_is_removed;
126  }
127 
131  bool has_index(int64_t index) const
132  {
133  return state_ == index;
134  }
135 
140  template<typename Hash> uint64_t get_hash(const Key &key, const Hash &hash) const
141  {
142  BLI_assert(this->is_occupied());
143  return hash(key);
144  }
145 
146 #undef s_is_empty
147 #undef s_is_removed
148 };
149 
150 template<typename Key> struct DefaultVectorSetSlot;
151 
152 template<typename Key> struct DefaultVectorSetSlot {
154 };
155 
156 } // namespace blender
#define BLI_assert(a)
Definition: BLI_assert.h:58
#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:169
__int64 int64_t
Definition: stdint.h:92
unsigned __int64 uint64_t
Definition: stdint.h:93