mirror of https://github.com/CGAL/cgal
Use unique_ptr and add copy/move semantics
This commit is contained in:
parent
ca794fa991
commit
9ea82441c2
|
|
@ -50,11 +50,50 @@ class Small_unordered_set
|
||||||
using Set = std::unordered_set<Key>;
|
using Set = std::unordered_set<Key>;
|
||||||
|
|
||||||
Array m_array;
|
Array m_array;
|
||||||
std::shared_ptr<Set> m_set;
|
std::unique_ptr<Set> m_set;
|
||||||
std::size_t m_size = 0;
|
std::size_t m_size = 0;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
Small_unordered_set() { }
|
||||||
|
|
||||||
|
~Small_unordered_set() { }
|
||||||
|
|
||||||
|
Small_unordered_set (const Small_unordered_set& other)
|
||||||
|
: m_size (other.m_size)
|
||||||
|
{
|
||||||
|
if (other.m_set)
|
||||||
|
m_set = std::make_unique<Set>(*other.m_set);
|
||||||
|
else
|
||||||
|
m_array = other.m_array;
|
||||||
|
}
|
||||||
|
|
||||||
|
Small_unordered_set (Small_unordered_set&& other)
|
||||||
|
: m_size (other.m_size)
|
||||||
|
{
|
||||||
|
if (other.m_set)
|
||||||
|
m_set = std::move(other.m_set);
|
||||||
|
else
|
||||||
|
m_array = std::move(other.m_array);
|
||||||
|
}
|
||||||
|
|
||||||
|
Small_unordered_set& operator= (const Small_unordered_set& other)
|
||||||
|
{
|
||||||
|
m_size = other.m_size;
|
||||||
|
if (other.m_set)
|
||||||
|
m_set = std::make_unique<Set>(*other.m_set);
|
||||||
|
else
|
||||||
|
m_array = other.m_array;
|
||||||
|
}
|
||||||
|
|
||||||
|
Small_unordered_set& operator= (Small_unordered_set&& other)
|
||||||
|
{
|
||||||
|
if (other.m_set)
|
||||||
|
m_set = std::move(other.m_set);
|
||||||
|
else
|
||||||
|
m_array = std::move(other.m_array);
|
||||||
|
}
|
||||||
|
|
||||||
bool insert (const Key& key)
|
bool insert (const Key& key)
|
||||||
{
|
{
|
||||||
if (m_size != MaxSize)
|
if (m_size != MaxSize)
|
||||||
|
|
@ -68,7 +107,7 @@ public:
|
||||||
|
|
||||||
if (!m_set)
|
if (!m_set)
|
||||||
{
|
{
|
||||||
m_set = std::make_shared<Set>();
|
m_set = std::make_unique<Set>();
|
||||||
m_set->reserve (MaxSize + 1);
|
m_set->reserve (MaxSize + 1);
|
||||||
for (const Key& a : m_array)
|
for (const Key& a : m_array)
|
||||||
m_set->insert(a);
|
m_set->insert(a);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue