[Bf-blender-cvs] [dbdd6b88ef7] functions: unify hash tables a bit
Jacques Lucke
noreply at git.blender.org
Sun Aug 25 14:34:51 CEST 2019
Commit: dbdd6b88ef738c171a4e09f0cf2836da83aeb61d
Author: Jacques Lucke
Date: Sun Aug 25 14:07:56 2019 +0200
Branches: functions
https://developer.blender.org/rBdbdd6b88ef738c171a4e09f0cf2836da83aeb61d
unify hash tables a bit
===================================================================
M source/blender/blenlib/BLI_map.hpp
M source/blender/blenlib/BLI_set.hpp
M source/blender/blenlib/BLI_set_vector.hpp
M source/blender/blenlib/BLI_string_map.hpp
===================================================================
diff --git a/source/blender/blenlib/BLI_map.hpp b/source/blender/blenlib/BLI_map.hpp
index 02e62401ba4..bb6541f91f9 100644
--- a/source/blender/blenlib/BLI_map.hpp
+++ b/source/blender/blenlib/BLI_map.hpp
@@ -54,8 +54,8 @@ namespace BLI {
template<typename KeyT, typename ValueT, typename Allocator = GuardedAllocator> class Map {
private:
- static constexpr uint32_t OFFSET_MASK = 3;
- static constexpr uint32_t OFFSET_SHIFT = 2;
+ static constexpr uint OFFSET_MASK = 3;
+ static constexpr uint OFFSET_SHIFT = 2;
class Item {
private:
@@ -68,19 +68,18 @@ template<typename KeyT, typename ValueT, typename Allocator = GuardedAllocator>
char m_values[4 * sizeof(ValueT)];
public:
- static constexpr uint32_t slots_per_item = 4;
+ static constexpr uint slots_per_item = 4;
Item()
{
- m_status[0] = IS_EMPTY;
- m_status[1] = IS_EMPTY;
- m_status[2] = IS_EMPTY;
- m_status[3] = IS_EMPTY;
+ for (uint offset = 0; offset < 4; offset++) {
+ m_status[offset] = IS_EMPTY;
+ }
}
~Item()
{
- for (uint32_t offset = 0; offset < 4; offset++) {
+ for (uint offset = 0; offset < 4; offset++) {
if (m_status[offset] == IS_SET) {
this->key(offset)->~KeyT();
this->value(offset)->~ValueT();
@@ -90,7 +89,7 @@ template<typename KeyT, typename ValueT, typename Allocator = GuardedAllocator>
Item(const Item &other)
{
- for (uint32_t offset = 0; offset < 4; offset++) {
+ for (uint offset = 0; offset < 4; offset++) {
uint8_t status = other.m_status[offset];
m_status[offset] = status;
if (status == IS_SET) {
@@ -102,7 +101,7 @@ template<typename KeyT, typename ValueT, typename Allocator = GuardedAllocator>
Item(Item &&other)
{
- for (uint32_t offset = 0; offset < 4; offset++) {
+ for (uint offset = 0; offset < 4; offset++) {
uint8_t status = other.m_status[offset];
m_status[offset] = status;
if (status == IS_SET) {
@@ -112,32 +111,32 @@ template<typename KeyT, typename ValueT, typename Allocator = GuardedAllocator>
}
}
- bool has_key(uint32_t offset, const KeyT &key) const
+ bool has_key(uint offset, const KeyT &key) const
{
return m_status[offset] == IS_SET && key == *this->key(offset);
}
- bool is_set(uint32_t offset) const
+ bool is_set(uint offset) const
{
return m_status[offset] == IS_SET;
}
- bool is_empty(uint32_t offset) const
+ bool is_empty(uint offset) const
{
return m_status[offset] == IS_EMPTY;
}
- KeyT *key(uint32_t offset) const
+ KeyT *key(uint offset) const
{
return (KeyT *)(m_keys + offset * sizeof(KeyT));
}
- ValueT *value(uint32_t offset) const
+ ValueT *value(uint offset) const
{
return (ValueT *)(m_values + offset * sizeof(ValueT));
}
- void copy_in(uint32_t offset, const KeyT &key, const ValueT &value)
+ void copy_in(uint offset, const KeyT &key, const ValueT &value)
{
BLI_assert(m_status[offset] != IS_SET);
m_status[offset] = IS_SET;
@@ -145,7 +144,7 @@ template<typename KeyT, typename ValueT, typename Allocator = GuardedAllocator>
new (this->value(offset)) ValueT(value);
}
- void move_in(uint32_t offset, KeyT &key, ValueT &value)
+ void move_in(uint offset, KeyT &key, ValueT &value)
{
BLI_assert(m_status[offset] != IS_SET);
m_status[offset] = IS_SET;
@@ -153,7 +152,7 @@ template<typename KeyT, typename ValueT, typename Allocator = GuardedAllocator>
new (this->value(offset)) ValueT(std::move(value));
}
- void set_dummy(uint32_t offset)
+ void set_dummy(uint offset)
{
BLI_assert(m_status[offset] == IS_SET);
m_status[offset] = IS_DUMMY;
@@ -390,7 +389,7 @@ template<typename KeyT, typename ValueT, typename Allocator = GuardedAllocator>
uint32_t item_index = 0;
for (const Item &item : m_array) {
std::cout << " Item: " << item_index++ << '\n';
- for (uint32_t offset = 0; offset < 4; offset++) {
+ for (uint offset = 0; offset < 4; offset++) {
std::cout << " " << offset << " \t";
if (item.is_empty(offset)) {
std::cout << " <empty>\n";
@@ -456,7 +455,7 @@ template<typename KeyT, typename ValueT, typename Allocator = GuardedAllocator>
const KeyT &operator*() const
{
uint32_t item_index = this->m_slot >> OFFSET_SHIFT;
- uint32_t offset = this->m_slot & OFFSET_MASK;
+ uint offset = this->m_slot & OFFSET_MASK;
const Item &item = this->m_map->m_array.item(item_index);
BLI_assert(item.is_set(offset));
return *item.key(offset);
@@ -472,7 +471,7 @@ template<typename KeyT, typename ValueT, typename Allocator = GuardedAllocator>
ValueT &operator*() const
{
uint32_t item_index = this->m_slot >> OFFSET_SHIFT;
- uint32_t offset = this->m_slot & OFFSET_MASK;
+ uint offset = this->m_slot & OFFSET_MASK;
const Item &item = this->m_map->m_array.item(item_index);
BLI_assert(item.is_set(offset));
return *item.value(offset);
@@ -499,7 +498,7 @@ template<typename KeyT, typename ValueT, typename Allocator = GuardedAllocator>
UserItem operator*() const
{
uint32_t item_index = this->m_slot >> OFFSET_SHIFT;
- uint32_t offset = this->m_slot & OFFSET_MASK;
+ uint offset = this->m_slot & OFFSET_MASK;
const Item &item = this->m_map->m_array.item(item_index);
BLI_assert(item.is_set(offset));
return {*item.key(offset), *item.value(offset)};
@@ -538,7 +537,7 @@ template<typename KeyT, typename ValueT, typename Allocator = GuardedAllocator>
{
for (; slot < m_array.slots_total(); slot++) {
uint32_t item_index = slot >> OFFSET_SHIFT;
- uint32_t offset = slot & OFFSET_MASK;
+ uint offset = slot & OFFSET_MASK;
const Item &item = m_array.item(item_index);
if (item.is_set(offset)) {
return slot;
@@ -570,7 +569,7 @@ template<typename KeyT, typename ValueT, typename Allocator = GuardedAllocator>
{
ArrayType new_array = m_array.init_reserved(min_usable_slots);
for (Item &old_item : m_array) {
- for (uint32_t offset = 0; offset < 4; offset++) {
+ for (uint offset = 0; offset < 4; offset++) {
if (old_item.is_set(offset)) {
this->add_after_grow(*old_item.key(offset), *old_item.value(offset), new_array);
}
diff --git a/source/blender/blenlib/BLI_set.hpp b/source/blender/blenlib/BLI_set.hpp
index df952fb573e..021ca4df85d 100644
--- a/source/blender/blenlib/BLI_set.hpp
+++ b/source/blender/blenlib/BLI_set.hpp
@@ -51,8 +51,8 @@ namespace BLI {
template<typename T, typename Allocator = GuardedAllocator> class Set {
private:
- static constexpr uint32_t OFFSET_MASK = 3;
- static constexpr uint32_t OFFSET_SHIFT = 2;
+ static constexpr uint OFFSET_MASK = 3;
+ static constexpr uint OFFSET_SHIFT = 2;
class Item {
private:
@@ -64,19 +64,18 @@ template<typename T, typename Allocator = GuardedAllocator> class Set {
char m_values[4 * sizeof(T)];
public:
- static constexpr uint32_t slots_per_item = 4;
+ static constexpr uint slots_per_item = 4;
Item()
{
- m_status[0] = IS_EMPTY;
- m_status[1] = IS_EMPTY;
- m_status[2] = IS_EMPTY;
- m_status[3] = IS_EMPTY;
+ for (uint offset = 0; offset < 4; offset++) {
+ m_status[offset] = IS_EMPTY;
+ }
}
~Item()
{
- for (uint32_t offset = 0; offset < 4; offset++) {
+ for (uint offset = 0; offset < 4; offset++) {
if (m_status[offset] == IS_SET) {
destruct(this->value(offset));
}
@@ -85,7 +84,7 @@ template<typename T, typename Allocator = GuardedAllocator> class Set {
Item(const Item &other)
{
- for (uint32_t offset = 0; offset < 4; offset++) {
+ for (uint offset = 0; offset < 4; offset++) {
uint8_t status = other.m_status[offset];
m_status[offset] = status;
if (status == IS_SET) {
@@ -98,7 +97,7 @@ template<typename T, typename Allocator = GuardedAllocator> class Set {
Item(Item &&other)
{
- for (uint32_t offset = 0; offset < 4; offset++) {
+ for (uint offset = 0; offset < 4; offset++) {
uint8_t status = other.m_status[offset];
m_status[offset] = status;
if (status == IS_SET) {
@@ -112,12 +111,12 @@ template<typename T, typename Allocator = GuardedAllocator> class Set {
Item &operator=(const Item &other) = delete;
Item &operator=(Item &&other) = delete;
- T *value(uint32_t offset) const
+ T *value(uint offset) const
{
return (T *)(m_values + offset * sizeof(T));
}
- void copy_in(uint32_t offset, const T &value)
+ void copy_in(uint offset, const T &value)
{
BLI_assert(m_status[offset] != IS_SET);
m_status[offset] = IS_SET;
@@ -125,7 +124,7 @@ template<typename T, typename Allocator = GuardedAllocator> class Set {
new (dst) T(value);
}
- void move_in(uint32_t offset, T &value)
+ void move_in(uint offset, T &value)
{
BLI_assert(m_status[offset] != IS_SET);
m_status[offset] = IS_SET;
@@ -133,29 +132,29 @@ template<typename T, typename Allocator = GuardedAllocator> class Set {
new (dst) T(std::move(value));
}
- void set_dummy(uint32_t offset)
+ void set_dummy(uint offset)
{
BLI_assert(m_status[offset] == IS_SET);
m_status[offset] = IS_DUMMY;
destruct(this->value(offset));
}
- bool is_empty(uint32_t offset) const
+ bool is_empty(uint offset) const
{
return m_status[offset] == IS_EMPTY;
}
- bool is_set(uint32_t offset) const
+ bool is_set(uint offset) const
{
return m_status[offset] == IS_SET;
}
- bool is_dummy(uint32_t offset) const
+ bool is_dummy(uint offset) const
{
return m_status[offset] == IS_DUMMY;
}
- bool has_value(uint32_t offset, const T &value) const
+ bool has_value(uint offset, const T &value) const
{
return m_status[offset] == IS_SET && *thi
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list