mirror of https://github.com/CGAL/cgal
Access to the "current" size of the compact container
This commit is contained in:
parent
a96e69af29
commit
bcce26f2b5
|
|
@ -36,6 +36,7 @@
|
|||
#include <CGAL/memory.h>
|
||||
#include <CGAL/iterator.h>
|
||||
#include <CGAL/CC_safe_handle.h>
|
||||
#include <CGAL/atomic.h>
|
||||
|
||||
#include <tbb/tbb.h>
|
||||
|
||||
|
|
@ -255,6 +256,11 @@ public:
|
|||
{
|
||||
std::swap(m_alloc, c.m_alloc);
|
||||
std::swap(m_capacity, c.m_capacity);
|
||||
{ // non-atomic swap
|
||||
size_type other_size = c.m_size;
|
||||
c.m_size = size_type(m_size);
|
||||
m_size = other_size;
|
||||
}
|
||||
std::swap(m_block_size, c.m_block_size);
|
||||
std::swap(m_first_item, c.m_first_item);
|
||||
std::swap(m_last_item, c.m_last_item);
|
||||
|
|
@ -445,6 +451,7 @@ private:
|
|||
#ifndef CGAL_NO_ASSERTIONS
|
||||
std::memset(&*x, 0, sizeof(T));
|
||||
#endif*/
|
||||
--m_size;
|
||||
put_on_free_list(&*x, fl);
|
||||
}
|
||||
public:
|
||||
|
|
@ -465,9 +472,11 @@ public:
|
|||
// The complexity is O(size(free list = capacity-size)).
|
||||
void merge(Self &d);
|
||||
|
||||
// Do not call this function while others are inserting/erasing elements
|
||||
// If `CGAL_NO_ATOMIC` is defined, do not call this function while others
|
||||
// are inserting/erasing elements
|
||||
size_type size() const
|
||||
{
|
||||
#ifdef CGAL_NO_ATOMIC
|
||||
size_type size = m_capacity;
|
||||
for( typename Free_lists::iterator it_free_list = m_free_lists.begin() ;
|
||||
it_free_list != m_free_lists.end() ;
|
||||
|
|
@ -476,6 +485,9 @@ public:
|
|||
size -= it_free_list->size();
|
||||
}
|
||||
return size;
|
||||
#else // atomic can be used
|
||||
return m_size;
|
||||
#endif
|
||||
}
|
||||
|
||||
size_type max_size() const
|
||||
|
|
@ -587,6 +599,7 @@ private:
|
|||
{
|
||||
CGAL_assertion(type(ret) == USED);
|
||||
fl->dec_size();
|
||||
++m_size;
|
||||
return iterator(ret, 0);
|
||||
}
|
||||
|
||||
|
|
@ -674,6 +687,7 @@ private:
|
|||
m_first_item = NULL;
|
||||
m_last_item = NULL;
|
||||
m_all_items = All_items();
|
||||
m_size = 0;
|
||||
}
|
||||
|
||||
allocator_type m_alloc;
|
||||
|
|
@ -684,6 +698,11 @@ private:
|
|||
pointer m_last_item;
|
||||
All_items m_all_items;
|
||||
mutable Mutex m_mutex;
|
||||
#ifdef CGAL_NO_ATOMIC
|
||||
size_type m_size;
|
||||
#else
|
||||
CGAL::cpp11::atomic<size_type> m_size;
|
||||
#endif
|
||||
};
|
||||
|
||||
template < class T, class Allocator >
|
||||
|
|
|
|||
Loading…
Reference in New Issue