Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always init time_stamp to -2 #8714

Merged
merged 7 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ template <typename Cb>
class Cell_base_with_timestamp
: public Cb
{
std::size_t time_stamp_;
std::size_t time_stamp_ = std::size_t(-2);

public:
using Has_timestamp = CGAL::Tag_true;
Expand All @@ -112,7 +112,7 @@ class Cell_base_with_timestamp
public:
template <typename... Args>
Cell_base_with_timestamp(const Args&... args)
: Cb(args...), time_stamp_(-1)
: Cb(args...)
{ }

Cell_base_with_timestamp(const Cell_base_with_timestamp& other)
Expand Down
2 changes: 1 addition & 1 deletion Mesh_2/include/CGAL/Delaunay_mesh_face_base_2.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Delaunay_mesh_face_base_2 : public Fb

void set_time_stamp(const std::size_t& ts) { time_stamp_ = ts; }

std::size_t time_stamp_;
std::size_t time_stamp_ = std::size_t(-2);
};

} // namespace CGAL
Expand Down
2 changes: 1 addition & 1 deletion Mesh_2/include/CGAL/Delaunay_mesh_vertex_base_2.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Delaunay_mesh_vertex_base_2 : public Vb

void set_time_stamp(const std::size_t& ts) { time_stamp_ = ts; }

std::size_t time_stamp_;
std::size_t time_stamp_ = std::size_t(-2);
#endif // CGAL_MESH_2_DEBUG_REFINEMENT_POINTS
};

Expand Down
2 changes: 1 addition & 1 deletion Mesh_3/include/CGAL/Compact_mesh_cell_base_3.h
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ class Compact_mesh_cell_3
#ifdef CGAL_INTRUSIVE_LIST
Cell_handle next_intrusive_ = {}, previous_intrusive_ = {};
#endif
std::size_t time_stamp_;
std::size_t time_stamp_ = std::size_t(-2);

std::array<Index, 4> surface_center_index_table_ = {};
/// Stores visited facets (4 first bits)
Expand Down
2 changes: 1 addition & 1 deletion Mesh_3/include/CGAL/Mesh_cell_base_3.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class Mesh_cell_base_3
#ifdef CGAL_INTRUSIVE_LIST
Cell_handle next_intrusive_, previous_intrusive_;
#endif
std::size_t time_stamp_;
std::size_t time_stamp_ = std::size_t(-2);

}; // end class Mesh_cell_base_3

Expand Down
13 changes: 6 additions & 7 deletions Mesh_3/include/CGAL/Mesh_polyhedron_3.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ public CGAL::HalfedgeDS_vertex_base<Refs, Tag, Point>
typedef CGAL::HalfedgeDS_vertex_base<Refs, Tag, Point> Pdv_base;

Set_of_indices indices;
std::size_t time_stamp_;

std::size_t time_stamp_ = std::size_t(-2);
lrineau marked this conversation as resolved.
Show resolved Hide resolved
public:
int nb_of_feature_edges;
int nb_of_feature_edges = 0;

bool is_corner() const {
return nb_of_feature_edges > 2;
Expand Down Expand Up @@ -85,8 +84,8 @@ public CGAL::HalfedgeDS_vertex_base<Refs, Tag, Point>
return indices;
}

Mesh_polyhedron_vertex() : Pdv_base(), time_stamp_(-1), nb_of_feature_edges(0) {}
Mesh_polyhedron_vertex(const Point& p) : Pdv_base(p), time_stamp_(-1), nb_of_feature_edges(0) {}
Mesh_polyhedron_vertex() = default;
Mesh_polyhedron_vertex(const Point& p) : Pdv_base(p) {}
};

template <class Refs, class Tprev, class Tvertex, class Tface>
Expand All @@ -95,7 +94,7 @@ public CGAL::HalfedgeDS_halfedge_base<Refs,Tprev,Tvertex,Tface>
{
private:
bool feature_edge;
std::size_t time_stamp_;
std::size_t time_stamp_ = std::size_t(-2);

public:

Expand Down Expand Up @@ -143,7 +142,7 @@ public CGAL::HalfedgeDS_face_base<Refs,T_,Pln_>
{
private:
Patch_id_ patch_id_;
std::size_t time_stamp_;
std::size_t time_stamp_ = std::size_t(-2);

public:

Expand Down
2 changes: 1 addition & 1 deletion Mesh_3/include/CGAL/Mesh_vertex_base_3.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class Mesh_vertex_3
Vertex_handle next_intrusive_;
Vertex_handle previous_intrusive_;
#endif
std::size_t time_stamp_;
std::size_t time_stamp_ = std::size_t(-2);
public:

friend std::istream& operator>>(std::istream &is, Mesh_vertex_3& v)
Expand Down
17 changes: 2 additions & 15 deletions SMDS_3/include/CGAL/Compact_simplicial_mesh_cell_base_3.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,7 @@ class Compact_simplicial_mesh_cell_3

public:
// Constructors
Compact_simplicial_mesh_cell_3()
: time_stamp_(std::size_t(-1))
{}

Compact_simplicial_mesh_cell_3(const Compact_simplicial_mesh_cell_3& rhs)
: N(rhs.N)
, V(rhs.V)
, time_stamp_(rhs.time_stamp_)
, subdomain_index_(rhs.subdomain_index_)
{
for(int i=0; i <4; i++){
surface_index_table_[i] = rhs.surface_index_table_[i];
}
}
Compact_simplicial_mesh_cell_3() = default;

Compact_simplicial_mesh_cell_3(Vertex_handle v0,
Vertex_handle v1,
Expand Down Expand Up @@ -279,7 +266,7 @@ class Compact_simplicial_mesh_cell_3
std::array<Cell_handle, 4> N;
std::array<Vertex_handle, 4> V;

std::size_t time_stamp_;
std::size_t time_stamp_ = std::size_t(-2);

// The index of the cell of the input complex that contains me
Subdomain_index subdomain_index_ = {};
Expand Down
6 changes: 2 additions & 4 deletions SMDS_3/include/CGAL/Simplicial_mesh_cell_base_3.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ class Simplicial_mesh_cell_base_3
};

public:
Simplicial_mesh_cell_base_3()
: time_stamp_(std::size_t(-1))
{}
Simplicial_mesh_cell_base_3() = default;

Simplicial_mesh_cell_base_3(const Simplicial_mesh_cell_base_3& rhs)
: Cb(static_cast<const Cb&>(rhs)),
Expand Down Expand Up @@ -191,7 +189,7 @@ class Simplicial_mesh_cell_base_3
/// Stores surface_index for each facet of the cell
std::array<Surface_patch_index, 4> surface_index_table_ = {};

std::size_t time_stamp_;
std::size_t time_stamp_ = std::size_t(-2);

// The index of the cell of the input complex that contains me
Subdomain_index subdomain_index_ = {};
Expand Down
3 changes: 1 addition & 2 deletions SMDS_3/include/CGAL/Simplicial_mesh_vertex_base_3.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ private :
, index_()
, dimension_(-1)
, cache_validity(false)
, time_stamp_(std::size_t(-1))
{}

// Default copy constructor and assignment operator are ok
Expand Down Expand Up @@ -218,7 +217,7 @@ private :
// that contains me. Negative values are a marker for special vertices.
short dimension_;
bool cache_validity;
std::size_t time_stamp_;
std::size_t time_stamp_ = std::size_t(-2);

public:
friend std::istream& operator>>(std::istream& is,
Expand Down
136 changes: 54 additions & 82 deletions STL_Extension/include/CGAL/Compact_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ class Compact_container
CGAL_INCREMENT_COMPACT_CONTAINER_BLOCK_SIZE>
>::type Increment_policy;
typedef TimeStamper_ Ts;

template <typename U> using EraseCounterStrategy =
internal::Erase_counter_strategy<internal::has_increment_erase_counter<U>::value>;

typedef Compact_container <T, Al, Ip, Ts> Self;
typedef Compact_container_traits <T> Traits;
public:
Expand Down Expand Up @@ -354,7 +358,7 @@ class Compact_container
return all_items[block_number].first[index_in_block];
}

friend void swap(Compact_container& a, Compact_container b) {
friend void swap(Compact_container& a, Compact_container b) noexcept {
a.swap(b);
}

Expand Down Expand Up @@ -390,22 +394,16 @@ class Compact_container
// (just forward the arguments to the constructor, to optimize a copy).
template < typename... Args >
iterator
emplace(const Args&... args)
emplace(Args&&... args)
{
if (free_list == nullptr)
allocate_new_block();

pointer ret = free_list;
free_list = clean_pointee(ret);
std::size_t ts;
CGAL_USE(ts);
if constexpr (Time_stamper::has_timestamp) {
ts = ret->time_stamp();
}
new (ret) value_type(args...);
if constexpr (Time_stamper::has_timestamp) {
ret->set_time_stamp(ts);
}
const auto ts = Time_stamper::time_stamp(ret);
new (ret) value_type(std::forward<Args>(args)...);
Time_stamper::restore_timestamp(ret, ts);
Time_stamper::set_time_stamp(ret, time_stamp);
CGAL_assertion(type(ret) == USED);
++size_;
Expand All @@ -414,24 +412,7 @@ class Compact_container

iterator insert(const T &t)
{
if (free_list == nullptr)
allocate_new_block();

pointer ret = free_list;
free_list = clean_pointee(ret);
std::size_t ts;
CGAL_USE(ts);
if constexpr (Time_stamper::has_timestamp) {
ts = ret->time_stamp();
}
std::allocator_traits<allocator_type>::construct(alloc, ret, t);
if constexpr (Time_stamper::has_timestamp) {
ret->set_time_stamp(ts);
}
Time_stamper::set_time_stamp(ret, time_stamp);
CGAL_assertion(type(ret) == USED);
++size_;
return iterator(ret, 0);
return emplace(t);
}

template < class InputIterator >
Expand All @@ -450,22 +431,14 @@ class Compact_container

void erase(iterator x)
{
typedef internal::Erase_counter_strategy<
internal::has_increment_erase_counter<T>::value> EraseCounterStrategy;

CGAL_precondition(type(&*x) == USED);
EraseCounterStrategy::increment_erase_counter(*x);
std::size_t ts;
CGAL_USE(ts);
if constexpr (Time_stamper::has_timestamp) {
ts = x->time_stamp();
}
std::allocator_traits<allocator_type>::destroy(alloc, &*x);
if constexpr (Time_stamper::has_timestamp) {
x->set_time_stamp(ts);
}

put_on_free_list(&*x);
auto ptr = &*x;
CGAL_precondition(type(ptr) == USED);
EraseCounterStrategy<T>::increment_erase_counter(*x);
const auto ts = Time_stamper::time_stamp(ptr);
std::allocator_traits<allocator_type>::destroy(alloc, ptr);
Time_stamper::restore_timestamp(ptr, ts);

put_on_free_list(ptr);
--size_;
}

Expand Down Expand Up @@ -598,25 +571,7 @@ class Compact_container
while ( capacity_<n )
{ // Pb because the order of free list is no more the order of
// allocate_new_block();
pointer new_block = alloc.allocate(block_size + 2);
all_items.push_back(std::make_pair(new_block, block_size + 2));
capacity_ += block_size;
// We insert this new block at the end.
if (last_item == nullptr) // First time
{
first_item = new_block;
last_item = new_block + block_size + 1;
set_type(first_item, nullptr, START_END);
}
else
{
set_type(last_item, new_block, BLOCK_BOUNDARY);
set_type(new_block, last_item, BLOCK_BOUNDARY);
last_item = new_block + block_size + 1;
}
set_type(last_item, nullptr, START_END);
// Increase the block_size for the next time.
Increment_policy::increase_size(*this);
push_back_new_block();
}

// Now we put all the new elements on freelist, starting from the last block
Expand All @@ -627,16 +582,18 @@ class Compact_container
do
{
--curblock; // We are sure we have at least create a new block
pointer new_block = all_items[curblock].first;
for (size_type i = all_items[curblock].second-2; i >= 1; --i)
put_on_free_list(new_block + i);
auto [new_block, block_size] = all_items[curblock];
put_block_on_free_list(new_block, block_size - 2);
}
while ( curblock>lastblock );
}

private:

void allocate_new_block();
std::pair<pointer, size_type> push_back_new_block();
void put_block_on_free_list(pointer new_block, size_type block_size);

void allocate_new_block();

void put_on_free_list(pointer x)
{
Expand Down Expand Up @@ -697,7 +654,7 @@ class Compact_container
static bool is_begin_or_end(const_pointer ptr)
{ return type(ptr)==START_END; }

void swap(Self &c)
void swap(Self &c) noexcept
{
std::swap(alloc, c.alloc);
std::swap(capacity_, c.capacity_);
Expand Down Expand Up @@ -803,23 +760,13 @@ void Compact_container<T, Allocator, Increment_policy, TimeStamper>::clear()
}

template < class T, class Allocator, class Increment_policy, class TimeStamper >
void Compact_container<T, Allocator, Increment_policy, TimeStamper>::allocate_new_block()
auto Compact_container<T, Allocator, Increment_policy, TimeStamper>::push_back_new_block()
-> std::pair<pointer, size_type>
{
typedef internal::Erase_counter_strategy<
internal::has_increment_erase_counter<T>::value> EraseCounterStrategy;

pointer new_block = alloc.allocate(block_size + 2);
std::pair<pointer, size_type> result{new_block, block_size};
all_items.push_back(std::make_pair(new_block, block_size + 2));
capacity_ += block_size;
// We don't touch the first and the last one.
// We mark them free in reverse order, so that the insertion order
// will correspond to the iterator order...
for (size_type i = block_size; i >= 1; --i)
{
EraseCounterStrategy::set_erase_counter(*(new_block + i), 0);
Time_stamper::initialize_time_stamp(new_block + i);
put_on_free_list(new_block + i);
}
// We insert this new block at the end.
if (last_item == nullptr) // First time
{
Expand All @@ -836,8 +783,33 @@ void Compact_container<T, Allocator, Increment_policy, TimeStamper>::allocate_ne
set_type(last_item, nullptr, START_END);
// Increase the block_size for the next time.
Increment_policy::increase_size(*this);
return result;
}

template < class T, class Allocator, class Increment_policy, class TimeStamper >
void Compact_container<T, Allocator, Increment_policy, TimeStamper>::
put_block_on_free_list(pointer new_block, size_type block_size)
{
// The block actually has a size==block_size+2.
// We don't touch the first and the last one.
// We mark them free in reverse order, so that the insertion order
// will correspond to the iterator order...
for (size_type i = block_size; i >= 1; --i)
{
EraseCounterStrategy<T>::set_erase_counter(*(new_block + i), 0);
Time_stamper::initialize_time_stamp(new_block + i);
put_on_free_list(new_block + i);
}
}

template < class T, class Allocator, class Increment_policy, class TimeStamper >
void Compact_container<T, Allocator, Increment_policy, TimeStamper>::allocate_new_block()
{
auto [new_block, block_size] = push_back_new_block();
put_block_on_free_list(new_block, block_size);
}


template < class T, class Allocator, class Increment_policy, class TimeStamper >
inline
bool operator==(const Compact_container<T, Allocator, Increment_policy, TimeStamper> &lhs,
Expand Down
Loading