Fixed the most obvious issues with StatusSeT<> and its derivatives. Improved slightly the formatting and added a few lines documentation.

This commit is contained in:
Martin Marinov
2015-10-23 17:19:06 +01:00
parent f5d2560656
commit 552598141c

View File

@@ -573,9 +573,19 @@ public:
/// --- StatusSet API --- /// --- StatusSet API ---
template <class Handle> /*!
Implements a set of connectivity entities (vertex, edge, face, halfedge)
using the available bits in the corresponding mesh status field.
Status-based sets are much faster using std::set<> and equivalent
in performance to std::vector<bool>, but much more convenient.
*/
template <class HandleT>
class StatusSetT class StatusSetT
{ {
public:
typedef HandleT Handle;
protected: protected:
ArrayKernel& kernel_; ArrayKernel& kernel_;
@@ -583,7 +593,7 @@ public:
const unsigned int bit_mask_; const unsigned int bit_mask_;
public: public:
StatusSetT(ArrayKernel& _kernel, unsigned int _bit_mask) StatusSetT(ArrayKernel& _kernel, const unsigned int _bit_mask)
: kernel_(_kernel), bit_mask_(_bit_mask) : kernel_(_kernel), bit_mask_(_bit_mask)
{} {}
@@ -599,29 +609,27 @@ public:
inline void erase(Handle _hnd) inline void erase(Handle _hnd)
{ kernel_.status(_hnd).unset_bit(bit_mask_); } { kernel_.status(_hnd).unset_bit(bit_mask_); }
/// Note: 0(n) complexity //! Note: 0(n) complexity
unsigned int size() const size_t size() const
{ {
unsigned int n_elements = kernel_.status_pph(Handle()).is_valid() ? const int n = kernel_.status_pph(Handle()).is_valid() ?
kernel_.property(kernel_.status_pph(Handle())).n_elements() : 0; (int)kernel_.property(kernel_.status_pph(Handle())).n_elements() : 0;
unsigned int sz = 0;
for (unsigned int i = 0; i < n_elements; ++i) size_t sz = 0;
{ for (int i = 0; i < n; ++i)
sz += (unsigned int)is_in(Handle(i)); sz += (size_t)is_in(Handle(i));
}
return sz; return sz;
} }
/// Note: O(n) complexity //! Note: O(n) complexity
void clear() void clear()
{ {
unsigned int n_elements = kernel_.status_pph(Handle()).is_valid() ? const int n = kernel_.status_pph(Handle()).is_valid() ?
kernel_.property(kernel_.status_pph(Handle())).n_elements() : 0; (int)kernel_.property(kernel_.status_pph(Handle())).n_elements() : 0;
for (unsigned int i = 0; i < n_elements; ++i)
{ for (int i = 0; i < n; ++i)
erase(Handle(i)); erase(Handle(i));
} }
}
}; };
friend class StatusSetT<VertexHandle>; friend class StatusSetT<VertexHandle>;
@@ -629,13 +637,14 @@ public:
friend class StatusSetT<FaceHandle>; friend class StatusSetT<FaceHandle>;
friend class StatusSetT<HalfedgeHandle>; friend class StatusSetT<HalfedgeHandle>;
/// --- AutoStatusSet API --- //! AutoStatusSetT: A status set that automatically picks a free bit to use
template <class HandleT>
template <class Handle> class AutoStatusSetT : public StatusSetT<HandleT>
class AutoStatusSetT : public StatusSetT<Handle>
{ {
private: private:
typedef StatusSetT<Handle> Base; typedef StatusSetT<Handle> Base;
typedef HandleT Handle;
public: public:
AutoStatusSetT(ArrayKernel& _kernel) AutoStatusSetT(ArrayKernel& _kernel)
: StatusSetT<Handle>(_kernel, _kernel.pop_bit_mask(Handle())) : StatusSetT<Handle>(_kernel, _kernel.pop_bit_mask(Handle()))
@@ -658,12 +667,12 @@ public:
typedef AutoStatusSetT<FaceHandle> FaceStatusSet; typedef AutoStatusSetT<FaceHandle> FaceStatusSet;
typedef AutoStatusSetT<HalfedgeHandle> HalfedgeStatusSet; typedef AutoStatusSetT<HalfedgeHandle> HalfedgeStatusSet;
/// --- ExtStatusSet API --- (hybrid between a set and an array) //! ExtStatusSet: A status set augmented with an array
template <class HandleT>
template <class Handle> class ExtStatusSetT : public AutoStatusSetT<HandleT>
class ExtStatusSetT : public AutoStatusSetT<Handle>
{ {
public: public:
typedef HandleT Handle;
typedef AutoStatusSetT<Handle> Base; typedef AutoStatusSetT<Handle> Base;
protected: protected:
@@ -683,7 +692,6 @@ public:
~ExtStatusSetT() ~ExtStatusSetT()
{ clear(); } { clear(); }
//set API
// Complexity: O(1) // Complexity: O(1)
inline void insert(Handle _hnd) inline void insert(Handle _hnd)
{ {
@@ -694,7 +702,7 @@ public:
} }
} }
// Complexity: O(k), (k - number of the elements in the set) //! Complexity: O(k), (k - number of the elements in the set)
inline void erase(Handle _hnd) inline void erase(Handle _hnd)
{ {
if (is_in(_hnd)) if (is_in(_hnd))
@@ -704,11 +712,11 @@ public:
} }
} }
// Complexity: O(1) //! Complexity: O(1)
inline void erase(iterator _it) inline void erase(iterator _it)
{ {
assert(_it != end() && is_in(*_it)); assert(_it != end() && is_in(*_it));
clear(*_it); Base::erase(*_it);
*_it = handles_.back(); *_it = handles_.back();
_it.pop_back(); _it.pop_back();
} }