16 #ifndef SURGSIM_DATASTRUCTURES_GROUPS_INL_H 17 #define SURGSIM_DATASTRUCTURES_GROUPS_INL_H 21 namespace DataStructures
24 template <
typename Key,
typename T>
27 UniqueLock lock(m_mutex);
28 auto result = m_groups[group].insert(element);
29 if (result.second ==
true)
31 m_membership[element].insert(group);
37 template <
typename Key,
typename T>
41 for (
auto& group : groups)
43 result = add(group, element) || result;
49 template <
typename Key,
typename T>
53 for (
auto& members : other.m_membership)
55 result = add(std::vector<Key>(members.second.begin(), members.second.end()), members.first) || result;
61 template <
typename Key,
typename T>
65 UniqueLock lock(m_mutex);
66 auto found = m_groups.find(group);
67 if (found != m_groups.end())
69 auto count = found->second.erase(element);
72 if (found->second.empty())
74 m_groups.erase(group);
77 m_membership[element].erase(group);
79 if (m_membership[element].empty())
81 m_membership.erase(element);
90 template <
typename Key,
typename T>
93 std::vector<T> result;
94 SharedLock lock(m_mutex);
95 auto found = m_groups.find(group);
96 if (found != m_groups.end())
98 result.assign(found->second.cbegin(), found->second.cend());
103 template <
typename Key,
typename T>
106 std::vector<Key> result;
107 SharedLock lock(m_mutex);
108 auto found = m_membership.find(element);
109 if (found != m_membership.end())
111 result.assign(found->second.cbegin(), found->second.cend());
116 template <
typename Key,
typename T>
119 std::vector<Key> result;
121 SharedLock lock(m_mutex);
122 std::for_each(m_groups.cbegin(), m_groups.cend(),
123 [&result](
const std::pair<Key, std::unordered_set<T>>& value)
125 result.emplace(result.end(), value.first);
131 template <
typename Key,
typename T>
135 UniqueLock lock(m_mutex);
136 if (m_membership.find(element) != m_membership.end())
138 for (
auto& group : m_membership[element])
140 m_groups[group].erase(element);
142 m_membership.erase(element);
148 template <
typename Key,
typename T>
152 return getMembers(group);
156 template <
typename Key,
typename T>
159 UniqueLock lock(m_mutex);
161 m_membership.clear();
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
Class to wrap grouping operations, gives access to the members of a group and the groups of members...
Definition: Groups.h:37
std::vector< T > operator[](const Key &group) const
Return all the members of the given group.
Definition: Groups-inl.h:149
void clear()
Erases all entries.
Definition: Groups-inl.h:157
bool add(const Key &group, const T &element)
Add an element to the given group, if the group doesn't exist it will be created, if the element is a...
Definition: Groups-inl.h:25
std::vector< Key > getGroups() const
Definition: Groups-inl.h:117
std::vector< T > getMembers(const Key &group) const
Return all the members of the given group.
Definition: Groups-inl.h:91
bool remove(const Key &group, const T &element)
Remove an element from a given group, if the group does not exist or the element is not a member of t...
Definition: Groups-inl.h:62