diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-03-21 17:19:04 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-03-21 17:19:04 +0000 |
commit | 310edf444908b09ea6d00c03baceb7925f3bb7a2 (patch) | |
tree | 7064577c7fa7a851e2e930beb606ea8237b0bbd2 /ml/dlib/dlib/static_set | |
parent | Releasing debian version 1.44.3-2. (diff) | |
download | netdata-310edf444908b09ea6d00c03baceb7925f3bb7a2.tar.xz netdata-310edf444908b09ea6d00c03baceb7925f3bb7a2.zip |
Merging upstream version 1.45.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ml/dlib/dlib/static_set')
-rw-r--r-- | ml/dlib/dlib/static_set/static_set_compare_1.h | 122 | ||||
-rw-r--r-- | ml/dlib/dlib/static_set/static_set_compare_abstract.h | 93 | ||||
-rw-r--r-- | ml/dlib/dlib/static_set/static_set_kernel_1.h | 446 | ||||
-rw-r--r-- | ml/dlib/dlib/static_set/static_set_kernel_abstract.h | 154 | ||||
-rw-r--r-- | ml/dlib/dlib/static_set/static_set_kernel_c.h | 88 |
5 files changed, 0 insertions, 903 deletions
diff --git a/ml/dlib/dlib/static_set/static_set_compare_1.h b/ml/dlib/dlib/static_set/static_set_compare_1.h deleted file mode 100644 index b5271e1d4..000000000 --- a/ml/dlib/dlib/static_set/static_set_compare_1.h +++ /dev/null @@ -1,122 +0,0 @@ -// Copyright (C) 2005 Davis E. King (davis@dlib.net) -// License: Boost Software License See LICENSE.txt for the full license. -#ifndef DLIB_STATIC_SET_COMPARe_1_ -#define DLIB_STATIC_SET_COMPARe_1_ - -#include "static_set_compare_abstract.h" - -#include "../algs.h" - - - -namespace dlib -{ - - template < - typename static_set_base - > - class static_set_compare_1 : public static_set_base - { - - public: - - bool operator< ( - const static_set_compare_1& rhs - ) const; - - bool operator== ( - const static_set_compare_1& rhs - ) const; - - }; - - - template < - typename static_set_base - > - inline void swap ( - static_set_compare_1<static_set_base>& a, - static_set_compare_1<static_set_base>& b - ) { a.swap(b); } - -// ---------------------------------------------------------------------------------------- -// ---------------------------------------------------------------------------------------- - // member function definitions -// ---------------------------------------------------------------------------------------- -// ---------------------------------------------------------------------------------------- - - template < - typename static_set_base - > - bool static_set_compare_1<static_set_base>:: - operator< ( - const static_set_compare_1<static_set_base>& rhs - ) const - { - bool result = false; - if (static_set_base::size() < rhs.size()) - result = true; - - if (static_set_base::size() == rhs.size()) - { - rhs.reset(); - static_set_base::reset(); - while (rhs.move_next()) - { - static_set_base::move_next(); - if (static_set_base::element() < rhs.element()) - { - result = true; - break; - } - else if (rhs.element() < static_set_base::element()) - { - break; - } - } - } - - static_set_base::reset(); - rhs.reset(); - - return result; - } - -// ---------------------------------------------------------------------------------------- - - template < - typename static_set_base - > - bool static_set_compare_1<static_set_base>:: - operator== ( - const static_set_compare_1<static_set_base>& rhs - ) const - { - bool result = true; - if (static_set_base::size() != rhs.size()) - result = false; - - - rhs.reset(); - static_set_base::reset(); - while (rhs.move_next() && static_set_base::move_next()) - { - if (!(rhs.element() == static_set_base::element())) - { - result = false; - break; - } - } - - static_set_base::reset(); - rhs.reset(); - - return result; - } - -// ---------------------------------------------------------------------------------------- - -} - -#endif // DLIB_STATIC_SET_COMPARe_1_ - diff --git a/ml/dlib/dlib/static_set/static_set_compare_abstract.h b/ml/dlib/dlib/static_set/static_set_compare_abstract.h deleted file mode 100644 index 356354e69..000000000 --- a/ml/dlib/dlib/static_set/static_set_compare_abstract.h +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright (C) 2005 Davis E. King (davis@dlib.net) -// License: Boost Software License See LICENSE.txt for the full license. -#undef DLIB_STATIC_SET_COMPARe_ABSTRACT_ -#ifdef DLIB_STATIC_SET_COMPARe_ABSTRACT_ - -#include "static_set_kernel_abstract.h" - -#include "../algs.h" - - -namespace dlib -{ - - template < - typename static_set_base - > - class static_set_compare : public static_set_base - { - - /*! - REQUIREMENTS ON static_set_base - must an implementation of static_set/static_set_kernel_abstract.h - - POINTERS AND REFERENCES TO INTERNAL DATA - operator== and operator< invalidate pointers or references to - data members. - - WHAT THIS EXTENSION DOES FOR static_set - This gives a static_set the ability to compare itself to other - static_sets using the < and == operators. - - The < operator is conceptually weird for sets. It is useful - though because it allows you to make sets of sets since - sets require that their containing type implement operator<. - - Also note that it is the case that for any two sets a and b - if (a<b) == false and (b<a) == false then a == b. - - - NOTATION - For the purposes of defining what these operators do I will - use the operator[] to reference the elements of the static_sets. - operator[] is defined to access the elements of the static_set in - the same order they would be enumerated by the enumerable - interface. - !*/ - - public: - - bool operator< ( - const static_set_compare& rhs - ) const; - /*! - ensures - - #at_start() == true - - if (size() < rhs.size()) then - - returns true - - else if (size() > rhs.size()) then - - returns false - - else - - returns true if there exists an integer j such that 0 <= j < size() - and for all integers i such that 0 <= i < j where it is true that - (*this)[i] == rhs[i] and (*this)[j] < rhs[j] - - returns false if there is no j that will satisfy the above conditions. - !*/ - - bool operator== ( - const static_set_compare& rhs - ) const; - /*! - ensures - - #at_start() == true - - returns true if *this and rhs contain the same elements. - returns false otherwise. - !*/ - }; - - - template < - typename static_set_base - > - inline void swap ( - static_set_compare<static_set_base>& a, - static_set_compare<static_set_base>& b - ) { a.swap(b); } - /*! - provides a global swap function - !*/ - -} - -#endif // DLIB_STATIC_SET_COMPARe_ABSTRACT_ - diff --git a/ml/dlib/dlib/static_set/static_set_kernel_1.h b/ml/dlib/dlib/static_set/static_set_kernel_1.h deleted file mode 100644 index 7a1f166fc..000000000 --- a/ml/dlib/dlib/static_set/static_set_kernel_1.h +++ /dev/null @@ -1,446 +0,0 @@ -// Copyright (C) 2005 Davis E. King (davis@dlib.net) -// License: Boost Software License See LICENSE.txt for the full license. -#ifndef DLIB_STATIC_SET_KERNEl_1_ -#define DLIB_STATIC_SET_KERNEl_1_ - -#include "static_set_kernel_abstract.h" -#include "../interfaces/enumerable.h" -#include "../interfaces/remover.h" -#include "../algs.h" -#include "../sort.h" -#include "../serialize.h" -#include <functional> - -namespace dlib -{ - - template < - typename T, - typename compare = std::less<T> - > - class static_set_kernel_1 : public enumerable<const T> - { - - /*! - INITIAL VALUE - - set_size == 0 - - d == 0 - - at_start_ == true - - cur == 0 - - CONVENTION - - size() == set_size - - if (set_size > 0) then - - d == pointer to an array containing all the elements of the set - - d is sorted according to operator< - - else - - d == 0 - - - current_element_valid() == (cur != 0) - - at_start() == (at_start_) - - if (current_element_valid()) then - - element() == *cur - !*/ - - // I would define this outside the class but Borland 5.5 has some problems - // with non-inline templated friend functions. - friend void deserialize ( - static_set_kernel_1& item, - std::istream& in - ) - { - try - { - item.clear(); - size_t size; - deserialize(size,in); - item.set_size = size; - item.d = new T[size]; - for (size_t i = 0; i < size; ++i) - { - deserialize(item.d[i],in); - } - } - catch (serialization_error e) - { - item.set_size = 0; - if (item.d) - { - delete [] item.d; - item.d = 0; - } - - throw serialization_error(e.info + "\n while deserializing object of type static_set_kernel_1"); - } - catch (...) - { - item.set_size = 0; - if (item.d) - { - delete [] item.d; - item.d = 0; - } - - throw; - } - } - - public: - - typedef T type; - typedef compare compare_type; - - static_set_kernel_1( - ); - - virtual ~static_set_kernel_1( - ); - - void clear ( - ); - - void load ( - remover<T>& source - ); - - void load ( - asc_remover<T,compare>& source - ); - - bool is_member ( - const T& item - ) const; - - inline void swap ( - static_set_kernel_1& item - ); - - // functions from the enumerable interface - inline size_t size ( - ) const; - - inline bool at_start ( - ) const; - - inline void reset ( - ) const; - - inline bool current_element_valid ( - ) const; - - inline const T& element ( - ) const; - - inline const T& element ( - ); - - inline bool move_next ( - ) const; - - - private: - - - // data members - size_t set_size; - T* d; - mutable T* cur; - mutable bool at_start_; - - // restricted functions - static_set_kernel_1(static_set_kernel_1&); // copy constructor - static_set_kernel_1& operator=(static_set_kernel_1&); // assignment operator - }; - - template < - typename T, - typename compare - > - inline void swap ( - static_set_kernel_1<T,compare>& a, - static_set_kernel_1<T,compare>& b - ) { a.swap(b); } - -// ---------------------------------------------------------------------------------------- -// ---------------------------------------------------------------------------------------- - // member function definitions -// ---------------------------------------------------------------------------------------- -// ---------------------------------------------------------------------------------------- - - template < - typename T, - typename compare - > - static_set_kernel_1<T,compare>:: - static_set_kernel_1( - ) : - set_size(0), - d(0), - cur(0), - at_start_(true) - { - } - -// ---------------------------------------------------------------------------------------- - - template < - typename T, - typename compare - > - static_set_kernel_1<T,compare>:: - ~static_set_kernel_1( - ) - { - if (set_size > 0) - delete [] d; - } - -// ---------------------------------------------------------------------------------------- - - template < - typename T, - typename compare - > - void static_set_kernel_1<T,compare>:: - clear( - ) - { - if (set_size > 0) - { - set_size = 0; - delete [] d; - d = 0; - } - reset(); - } - -// ---------------------------------------------------------------------------------------- - - template < - typename T, - typename compare - > - void static_set_kernel_1<T,compare>:: - load ( - remover<T>& source - ) - { - if (source.size() > 0) - { - d = new T[source.size()]; - - set_size = source.size(); - - for (size_t i = 0; source.size() > 0; ++i) - source.remove_any(d[i]); - - compare comp; - qsort_array(d,0,set_size-1,comp); - } - else - { - clear(); - } - reset(); - } - -// ---------------------------------------------------------------------------------------- - - template < - typename T, - typename compare - > - void static_set_kernel_1<T,compare>:: - load ( - asc_remover<T,compare>& source - ) - { - if (source.size() > 0) - { - d = new T[source.size()]; - - set_size = source.size(); - - for (size_t i = 0; source.size() > 0; ++i) - source.remove_any(d[i]); - } - else - { - clear(); - } - reset(); - } - -// ---------------------------------------------------------------------------------------- - - template < - typename T, - typename compare - > - bool static_set_kernel_1<T,compare>:: - is_member ( - const T& item - ) const - { - size_t high = set_size; - size_t low = 0; - size_t p = set_size; - size_t idx; - while (p > 0) - { - p = (high-low)>>1; - idx = p+low; - if (item < d[idx]) - high = idx; - else if (d[idx] < item) - low = idx; - else - return true; - } - return false; - } - -// ---------------------------------------------------------------------------------------- - - template < - typename T, - typename compare - > - size_t static_set_kernel_1<T,compare>:: - size ( - ) const - { - return set_size; - } - -// ---------------------------------------------------------------------------------------- - - template < - typename T, - typename compare - > - void static_set_kernel_1<T,compare>:: - swap ( - static_set_kernel_1<T,compare>& item - ) - { - exchange(set_size,item.set_size); - exchange(d,item.d); - exchange(cur,item.cur); - exchange(at_start_,item.at_start_); - } - -// ---------------------------------------------------------------------------------------- -// ---------------------------------------------------------------------------------------- - // enumerable function definitions -// ---------------------------------------------------------------------------------------- -// ---------------------------------------------------------------------------------------- - - template < - typename T, - typename compare - > - bool static_set_kernel_1<T,compare>:: - at_start ( - ) const - { - return at_start_; - } - -// ---------------------------------------------------------------------------------------- - - template < - typename T, - typename compare - > - void static_set_kernel_1<T,compare>:: - reset ( - ) const - { - at_start_ = true; - cur = 0; - } - -// ---------------------------------------------------------------------------------------- - - template < - typename T, - typename compare - > - bool static_set_kernel_1<T,compare>:: - current_element_valid ( - ) const - { - return (cur != 0); - } - -// ---------------------------------------------------------------------------------------- - - template < - typename T, - typename compare - > - const T& static_set_kernel_1<T,compare>:: - element ( - ) const - { - return *cur; - } - -// ---------------------------------------------------------------------------------------- - - template < - typename T, - typename compare - > - const T& static_set_kernel_1<T,compare>:: - element ( - ) - { - return *cur; - } - -// ---------------------------------------------------------------------------------------- - - template < - typename T, - typename compare - > - bool static_set_kernel_1<T,compare>:: - move_next ( - ) const - { - // if at_start() && size() > 0 - if (at_start_ && set_size > 0) - { - at_start_ = false; - cur = d; - return true; - } - // else if current_element_valid() - else if (cur != 0) - { - ++cur; - if (static_cast<size_t>(cur - d) < set_size) - { - return true; - } - else - { - cur = 0; - return false; - } - } - else - { - at_start_ = false; - return false; - } - } - -// ---------------------------------------------------------------------------------------- - -} - -#endif // DLIB_STATIC_SET_KERNEl_1_ - diff --git a/ml/dlib/dlib/static_set/static_set_kernel_abstract.h b/ml/dlib/dlib/static_set/static_set_kernel_abstract.h deleted file mode 100644 index a2efd1aaa..000000000 --- a/ml/dlib/dlib/static_set/static_set_kernel_abstract.h +++ /dev/null @@ -1,154 +0,0 @@ -// Copyright (C) 2005 Davis E. King (davis@dlib.net) -// License: Boost Software License See LICENSE.txt for the full license. -#undef DLIB_STATIC_SET_KERNEl_ABSTRACT_ -#ifdef DLIB_STATIC_SET_KERNEl_ABSTRACT_ - -#include "../interfaces/enumerable.h" -#include "../interfaces/remover.h" -#include "../serialize.h" -#include <functional> - -namespace dlib -{ - - template < - typename T, - typename compare = std::less<T> - > - class static_set : public enumerable<const T> - { - - /*! - REQUIREMENTS ON T - T must be comparable by compare where compare is a functor compatible with std::less and - T is swappable by a global swap() and - T must have a default constructor - - POINTERS AND REFERENCES TO INTERNAL DATA - Only the destructor will invalidate pointers or references - to internal data. - - INITIAL VALUE - size() == 0 - - ENUMERATION ORDER - The enumerator will iterate over the elements in the set in - ascending order according to the compare functor. - (i.e. the elements are enumerated in sorted order) - - WHAT THIS OBJECT REPRESENTS - static_set contains items of type T - - This object represents an unaddressed collection of items. - - Also note that unless specified otherwise, no member functions - of this object throw exceptions. - - NOTE - definition of equivalent: - a is equivalent to b if - a < b == false and - b < a == false - !*/ - - public: - - typedef T type; - typedef compare compare_type; - - static_set ( - ); - /*! - ensures - - #*this is properly initialized - throws - - std::bad_alloc or any exception thrown by T's constructor. - !*/ - - virtual ~static_set( - ); - /*! - ensures - - all memory associated with *this has been released - !*/ - - void clear( - ); - /*! - ensures - - #*this has its initial value - throws - - std::bad_alloc or any exception thrown by T's constructor. - If this exception is thrown then #*this is unusable - until clear() is called and succeeds. - !*/ - - void load ( - remover<T>& source - ); - /*! - ensures - - #size() == source.size() - - #source.size() == 0 - - all the elements in source are removed and placed into #*this - - #at_start() == true - throws - - std::bad_alloc or any exception thrown by T's constructor. - If this exception is thrown then the call to load() will have - no effect on #*this. - !*/ - - bool is_member ( - const T& item - ) const; - /*! - ensures - - if (there is an item in *this equivalent to item) then - - returns true - - else - - returns false - !*/ - - void swap ( - static_set& item - ); - /*! - ensures - - swaps *this and item - !*/ - - private: - - // restricted functions - static_set(static_set&); // copy constructor - static_set& operator=(static_set&); // assignment operator - }; - - template < - typename T, - typename compare - > - inline void swap ( - static_set<T,compare>& a, - static_set<T,compare>& b - ) { a.swap(b); } - /*! - provides a global swap function - !*/ - - template < - typename T, - typename compare - > - void deserialize ( - static_set<T,compare>& item, - std::istream& in - ); - /*! - provides deserialization support - !*/ - -} - -#endif // DLIB_STATIC_SET_KERNEl_ABSTRACT_ - diff --git a/ml/dlib/dlib/static_set/static_set_kernel_c.h b/ml/dlib/dlib/static_set/static_set_kernel_c.h deleted file mode 100644 index 1280c9c89..000000000 --- a/ml/dlib/dlib/static_set/static_set_kernel_c.h +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright (C) 2005 Davis E. King (davis@dlib.net) -// License: Boost Software License See LICENSE.txt for the full license. -#ifndef DLIB_STATIC_SET_KERNEl_C_ -#define DLIB_STATIC_SET_KERNEl_C_ - -#include "static_set_kernel_abstract.h" -#include "../algs.h" -#include "../assert.h" -#include "../interfaces/remover.h" - -namespace dlib -{ - - template < - typename set_base - > - class static_set_kernel_c : public set_base - { - typedef typename set_base::type T; - public: - - const T& element ( - ); - - const T& element ( - ) const; - }; - - - template < - typename set_base - > - inline void swap ( - static_set_kernel_c<set_base>& a, - static_set_kernel_c<set_base>& b - ) { a.swap(b); } - -// ---------------------------------------------------------------------------------------- -// ---------------------------------------------------------------------------------------- - // member function definitions -// ---------------------------------------------------------------------------------------- -// ---------------------------------------------------------------------------------------- - - template < - typename set_base - > - const typename set_base::type& static_set_kernel_c<set_base>:: - element ( - ) const - { - // make sure requires clause is not broken - DLIB_CASSERT(this->current_element_valid() == true, - "\tconst T& static_set::element() const" - << "\n\tyou can't access the current element if it doesn't exist" - << "\n\tthis: " << this - ); - - // call the real function - return set_base::element(); - } - -// ---------------------------------------------------------------------------------------- - - template < - typename set_base - > - const typename set_base::type& static_set_kernel_c<set_base>:: - element ( - ) - { - // make sure requires clause is not broken - DLIB_CASSERT(this->current_element_valid() == true, - "\tconst T& static_set::element" - << "\n\tyou can't access the current element if it doesn't exist" - << "\n\tthis: " << this - ); - - // call the real function - return set_base::element(); - } - -// ---------------------------------------------------------------------------------------- - - -} - -#endif // DLIB_STATIC_SET_KERNEl_C_ - |