From dc542232e8e2e89573aca824c59efdeafdbbbb2f Mon Sep 17 00:00:00 2001 From: Igor Zarzycki Date: Wed, 28 Aug 2024 20:25:05 +0200 Subject: [PATCH] Optimise upperBound function acting on values. --- include/crap/algorithm.d/upperboundvalue.h | 32 +++++++++++++++++----- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/include/crap/algorithm.d/upperboundvalue.h b/include/crap/algorithm.d/upperboundvalue.h index d23658c..4092f07 100644 --- a/include/crap/algorithm.d/upperboundvalue.h +++ b/include/crap/algorithm.d/upperboundvalue.h @@ -1,7 +1,7 @@ #ifndef CRAP_ALGORITHM_UPPERBOUNDVALUE #define CRAP_ALGORITHM_UPPERBOUNDVALUE -#include "../utility.d/valuelist.h" +#include "../utility.d/bisectvalue.h" #include "../version.d/libintegralconstantcallable.h" namespace crap @@ -33,20 +33,38 @@ namespace crap template class Operator, Type ... Values> struct upperBoundValue { private: - using values = valueList; - constexpr const static std :: size_t half = (values :: size) / 2u; + using values = bisectValue; template using This = upperBoundValue; - using lower = typename values :: template till; - using upper = typename values :: template since; + using lower = typename values :: template lower; + template struct upper; + template struct upper; public: - constexpr const static std :: size_t value = (((lower :: value) != (lower :: npos)) ? (lower :: value) : ((lower :: npos) + (upper :: value))); - constexpr const static std :: size_t npos = (lower :: npos) + (upper :: npos); + constexpr const static std :: size_t value = upper :: value; + constexpr const static std :: size_t npos = sizeof...(Values); using value_type = decltype(value); constexpr operator value_type () const noexcept; #if (crap_lib_integral_constant_callable >= 201304L) constexpr value_type operator () () const noexcept; #endif }; + + template class Operator, Type ... Values> + template + struct upperBoundValue :: upper + { + constexpr const static std :: size_t value = LowerValue; + }; + + template class Operator, Type ... Values> + template + struct upperBoundValue :: upper + { + private: + using values = bisectValue; + template using This = upperBoundValue; + public: + constexpr const static std :: size_t value = LowerNpos + values :: template upper :: value; + }; } template class Operator>