From 94cd1b4df8c10187ab1a8096ae0bc2eb94806f2c Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Wed, 25 May 2022 11:07:44 +0200 Subject: [PATCH] continue to debug cc with index --- .../CGAL/Compact_container_with_index.h | 106 +++++++++++++----- Combinatorial_map/include/CGAL/Dart.h | 41 ++++++- .../demo/Linear_cell_complex/typedefs.h | 3 + 3 files changed, 115 insertions(+), 35 deletions(-) diff --git a/Combinatorial_map/include/CGAL/Compact_container_with_index.h b/Combinatorial_map/include/CGAL/Compact_container_with_index.h index 71c961538e0..f8baef67da8 100644 --- a/Combinatorial_map/include/CGAL/Compact_container_with_index.h +++ b/Combinatorial_map/include/CGAL/Compact_container_with_index.h @@ -106,16 +106,31 @@ public: void init() { m_free_list=std::stack(); - m_used.assign(m_cc_with_index->capacity(), false); + if(m_cc_with_index->capacity()>0) + { m_used.assign(m_cc_with_index->capacity(), false); } m_first_free_index=0; + + // TEMPO FOR DEBUG + /* if(m_cc_with_index->capacity()>0) + { + for(size_type i=static_cast(m_cc_with_index->capacity())-1; i>0; --i) + { m_free_list.push(i); } + m_free_list.push(0); + } */ } void increase_to(size_type old_size) { CGAL_USE(old_size); CGAL_assertion(m_cc_with_index->capacity()>old_size); + CGAL_assertion(m_first_free_index==old_size); m_used.resize(m_cc_with_index->capacity(), false); // m_first_free_index does not change, thus nothing more to do. + + // TEMPO FOR DEBUG + /* for(size_type i=static_cast(m_cc_with_index->capacity())-1; i>old_size; --i) + { m_free_list.push(i); } + m_free_list.push(old_size); */ } void swap(Self& other) @@ -132,16 +147,19 @@ public: bool is_used(size_type i) const { - CGAL_assertion(icapacity()); + CGAL_assertion(icapacity() && i!=null_descriptor); return m_used[i]; } + // Push the ith element on the free list: it becomes free void push(size_type i) { + CGAL_assertion(icapacity() && i!=null_descriptor); + CGAL_assertion(is_used(i)); m_used[i]=false; - if(i+1==m_first_free_index) + /*if(i+1==m_first_free_index) { --m_first_free_index; } - else + else*/ { m_free_list.push(i); } } @@ -150,12 +168,14 @@ public: CGAL_assertion(!is_empty()); if(m_first_free_index!=m_cc_with_index->capacity()) { return m_first_free_index; } - return m_free_list.front(); + return m_free_list.top(); } + // Pop one element from the free list (the top): it becomes used size_type pop() { CGAL_assertion(!is_empty()); + CGAL_assertion(!is_used(top())); size_type res=m_cc_with_index->capacity(); if(m_first_free_index!=m_cc_with_index->capacity()) { @@ -164,8 +184,6 @@ public: } else { - // TODO: do we want to test if !m_free_list.empty() - // in non debug mode? res=m_free_list.top(); m_free_list.pop(); } @@ -177,7 +195,7 @@ public: {} protected: - CC_with_index* m_cc_with_index; + CC_with_index* const m_cc_with_index; std::stack m_free_list; std::vector m_used; size_type m_first_free_index; @@ -201,21 +219,38 @@ public: void init() { - m_used.assign(m_cc_with_index->capacity(), false); - m_free_list=0; - for(size_type i=0; i(m_cc_with_index->capacity()); ++i) - { Traits::set_size_t(m_cc_with_index[i], i+1); } - // Next of the last element is capacity() which is the "nullptr". + if(m_cc_with_index->capacity()>0) + { + m_used.assign(m_cc_with_index->capacity(), false); + m_free_list=0; + for(size_type i=0; + i(m_cc_with_index->capacity()-1); ++i) + { Traits::set_size_t((*m_cc_with_index)[i], i+1); } + // Next of the last element is null_descriptor. + Traits::set_size_t((*m_cc_with_index)[m_cc_with_index->capacity()-1], + null_descriptor); + } + else + { + m_free_list=null_descriptor; + m_used.clear(); + } } void increase_to(size_type old_size) { CGAL_assertion(m_cc_with_index->capacity()>old_size); - CGAL_assertion(m_free_list==old_size); // Previous container was full + CGAL_assertion(m_free_list==null_descriptor); // Previous container was full m_used.resize(m_cc_with_index->capacity(), false); - for(size_type i=0; i(m_cc_with_index->capacity()); ++i) - { Traits::set_size_t(m_cc_with_index[i], i+1); } - // Nothing to do with m_free_list, because it was equal to old_size. + size_type i=0; + if(old_size>0) + { i=old_size-1; } + for(; i(m_cc_with_index->capacity()-1); ++i) + { Traits::set_size_t((*m_cc_with_index)[i], i+1); } + // Next of the last element is null_descriptor. + Traits::set_size_t((*m_cc_with_index)[m_cc_with_index->capacity()-1], + null_descriptor); + m_free_list=old_size; } void swap(Self& other) @@ -226,19 +261,21 @@ public: } bool is_empty() const - { return m_free_list==m_cc_with_index->capacity(); } + { return m_free_list==null_descriptor; } bool is_used(size_type i) const { - CGAL_assertion(icapacity()); + CGAL_assertion(icapacity() && i!=null_descriptor); return m_used[i]; } + // Push the ith element on the free list: it becomes free void push(size_type i) { - CGAL_assertion(icapacity()); + CGAL_assertion(icapacity() && i!=null_descriptor); + CGAL_assertion(is_used(i)); m_used[i]=false; - Traits::set_size_t(m_cc_with_index[i], m_free_list); + Traits::set_size_t((*m_cc_with_index)[i], m_free_list); m_free_list=i; } @@ -248,11 +285,13 @@ public: return m_free_list; } + // Pop one element from the free list (the top): it becomes used size_type pop() { CGAL_assertion(!is_empty()); + CGAL_assertion(!is_used(top())); size_type res=m_free_list; - m_free_list=Traits::size_t(m_cc_with_index[res]); + m_free_list=Traits::size_t((*m_cc_with_index)[res]); m_used[res]=true; return res; } @@ -261,9 +300,9 @@ public: { Traits::set_size_t(dest, Traits::size_t(src)); } protected: - CC_with_index* m_cc_with_index; - size_type m_free_list; // First free element, capacity if no free - std::vector m_used; + CC_with_index* const m_cc_with_index; + size_type m_free_list; // First free element, capacity if no free + std::vector m_used; }; // (3) Case with the "in place" free list, and "in place" Booleans. @@ -287,14 +326,14 @@ public: m_free_list=0; for(size_type i=0; i(m_cc_with_index->capacity()); ++i) { static_set_val(m_cc_with_index[i], i+1, FREE); } - // Next of the last element is capacity() which is the "nullptr". + // Next of the last element is capacity() which is the "nullptr". TODO WRONG } void increase_to(size_type old_size) { CGAL_assertion(m_cc_with_index->capacity()>old_size); CGAL_assertion(m_free_list==old_size); // Previous container was full - for(size_type i=0; i(m_cc_with_index->capacity()); ++i) + for(size_type i=old_size; i(m_cc_with_index->capacity()); ++i) { static_set_val(m_cc_with_index[i], i+1, FREE); } // Nothing to do with m_free_list, because it was equal to old_size. } @@ -462,7 +501,7 @@ public: using Index=Index_for_cc_with_index; using TFree_list_management=Free_list_management - ; + ; static const size_type null_descriptor=TFree_list_management::null_descriptor; @@ -741,6 +780,7 @@ private: void init() { block_size=Incr_policy::first_block_size; + //block_size=10000000; capacity_ =0; size_ =0; all_items =nullptr; @@ -783,7 +823,8 @@ void Compact_container_with_index::me }*/ template < class T, class Allocator, class Increment_policy, class IndexType > -void Compact_container_with_index::clear() +void Compact_container_with_index:: +clear() { for (size_type i=0; i::construct - (alloc, &(all_items2[index]), std::move(all_items[index])); + /*std::allocator_traits::construct + (alloc, &(all_items2[index]), std::move(all_items[index]));*/ + new (&all_items2[index]) value_type(all_items[index]); + // TEMPO TO DEBUG + CGAL_assertion(all_items[index]==all_items2[index]); alloc.destroy(&(all_items[index])); } else diff --git a/Combinatorial_map/include/CGAL/Dart.h b/Combinatorial_map/include/CGAL/Dart.h index 3ae2a9d449e..25900743e62 100644 --- a/Combinatorial_map/include/CGAL/Dart.h +++ b/Combinatorial_map/include/CGAL/Dart.h @@ -155,11 +155,31 @@ namespace CGAL { /** Copy constructor: * @param adart a dart. */ - Dart_without_info(const Dart_without_info& adart) : mmarks(adart.mmarks), - mattribute_descriptors(adart.mattribute_descriptors) + Dart_without_info(const Dart_without_info& other) : + mmarks(other.mmarks), + mattribute_descriptors(other.mattribute_descriptors) { - for (unsigned int i = 0; i <= dimension; ++i) - mf[i] = adart.mf[i]; + for (unsigned int i=0; i<=dimension; ++i) + { mf[i]=other.mf[i]; } + } + + Self& operator=(const Self& other) + { + mmarks=other.mmarks; + mattribute_descriptors=other.mattribute_descriptors; + for (unsigned int i=0; i<=dimension; ++i) + { mf[i]=other.mf[i]; } + return *this; + } + + friend bool operator==(const Self& d1, const Self& d2) + { + if(d1.mmarks!=d2.mmarks || + d1.mattribute_descriptors!=d2.mattribute_descriptors) + { return false; } + for(unsigned int i=0; i<=dimension; ++i) + { if(d1.mf[i]!=d2.mf[i]) { return false; }} + return true; } /** Return the mark value of a given mark number. @@ -238,6 +258,8 @@ namespace CGAL { struct Dart : public Dart_without_info { public: + using Base=Dart_without_info; + template friend class Compact_container; @@ -289,6 +311,9 @@ namespace CGAL { const Info_& info() const { return minfo; } + friend bool operator==(const Self& d1, const Self& d2) + { return Base(d1)==Base(d2) && d1.minfo==d2.minfo; } + protected: Info minfo; }; @@ -301,6 +326,14 @@ namespace CGAL { typedef CGAL::Void Info; }; + // Specialization of Dart class when info==CGAL::Void + template + struct Dart : public Dart_without_info + { + public: + typedef CGAL::Void Info; + }; + } // namespace CGAL #endif // CGAL_DART_H // diff --git a/Linear_cell_complex/demo/Linear_cell_complex/typedefs.h b/Linear_cell_complex/demo/Linear_cell_complex/typedefs.h index 69807ad31b4..31fde91f697 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/typedefs.h +++ b/Linear_cell_complex/demo/Linear_cell_complex/typedefs.h @@ -57,6 +57,9 @@ public: m_status( LCC_DEMO_VISIBLE | LCC_DEMO_FILLED ) {} + friend bool operator==(const Volume_info& v1, const Volume_info& v2) + { return v1.m_color==v2.m_color && v1.m_status==v2.m_status; } + CGAL::IO::Color& color() { return m_color; } const CGAL::IO::Color& color() const