From: khizmax Date: Thu, 18 Sep 2014 15:38:50 +0000 (+0400) Subject: Move cds/int_algo.h to cds/algo/int_algo.h X-Git-Tag: v2.0.0~342 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=b4d744c2117d36ad8c51afdd2f53eb19fc608435;p=libcds.git Move cds/int_algo.h to cds/algo/int_algo.h --- diff --git a/cds/algo/flat_combining.h b/cds/algo/flat_combining.h index 4499dc03..4c707816 100644 --- a/cds/algo/flat_combining.h +++ b/cds/algo/flat_combining.h @@ -9,7 +9,7 @@ #include #include // lock_guard #include -#include +#include #include // thread_specific_ptr namespace cds { namespace algo { diff --git a/cds/algo/int_algo.h b/cds/algo/int_algo.h new file mode 100644 index 00000000..b4db2b82 --- /dev/null +++ b/cds/algo/int_algo.h @@ -0,0 +1,74 @@ +//$$CDS-header$$ + +#ifndef __CDS_INT_ALGO_H +#define __CDS_INT_ALGO_H + +#include + +namespace cds { namespace beans { + + /// Returns largest previous integer for log2( n ) + static inline size_t log2floor( size_t n ) + { + return n ? cds::bitop::MSBnz( n ) : 0; + } + + /// Returns smallest following integer for log2( n ) + static inline size_t log2ceil( size_t n ) + { + size_t i = log2floor( n ); + return size_t( 1 << i ) < n ? i + 1 : i; + } + + /// Returns largest previous power of 2 for \p n + /** + Examples: + \code + floor2(0) == 1 // !!! + floor2(1) == 1 + floor2(2) == 2 + floor2(3) == 2 + floor2(4) == 4 + floor2(15) == 8 + floor2(16) == 16 + floor2(17) == 16 + \endcode + */ + static inline size_t floor2( size_t n ) + { + return size_t(1) << log2floor( n ); + } + + /// Returns smallest following power of 2 for \p n + /** + Examples: + \code + ceil2(0) == 1 // !!! + ceil2(1) == 1 + ceil2(2) == 2 + ceil2(3) == 4 + ceil2(4) == 4 + ceil2(15) == 16 + ceil2(16) == 16 + ceil2(17) == 32 + \endcode + */ + static inline size_t ceil2( size_t n ) + { + return size_t(1) << log2ceil( n ); + } + + /// Checks if \p n is power of 2 + CDS_CONSTEXPR static inline bool is_power2( size_t n ) CDS_NOEXCEPT + { + return (n & (n - 1)) == 0 && n; + } + + /// Returns binary logarithm of \p n if \p n is power of two, otherwise returns 0 + static inline size_t log2( size_t n ) + { + return is_power2(n) ? log2floor(n) : 0; + } +}} // namespace cds::beans + +#endif // #ifndef __CDS_INT_ALGO_H diff --git a/cds/int_algo.h b/cds/int_algo.h deleted file mode 100644 index b4db2b82..00000000 --- a/cds/int_algo.h +++ /dev/null @@ -1,74 +0,0 @@ -//$$CDS-header$$ - -#ifndef __CDS_INT_ALGO_H -#define __CDS_INT_ALGO_H - -#include - -namespace cds { namespace beans { - - /// Returns largest previous integer for log2( n ) - static inline size_t log2floor( size_t n ) - { - return n ? cds::bitop::MSBnz( n ) : 0; - } - - /// Returns smallest following integer for log2( n ) - static inline size_t log2ceil( size_t n ) - { - size_t i = log2floor( n ); - return size_t( 1 << i ) < n ? i + 1 : i; - } - - /// Returns largest previous power of 2 for \p n - /** - Examples: - \code - floor2(0) == 1 // !!! - floor2(1) == 1 - floor2(2) == 2 - floor2(3) == 2 - floor2(4) == 4 - floor2(15) == 8 - floor2(16) == 16 - floor2(17) == 16 - \endcode - */ - static inline size_t floor2( size_t n ) - { - return size_t(1) << log2floor( n ); - } - - /// Returns smallest following power of 2 for \p n - /** - Examples: - \code - ceil2(0) == 1 // !!! - ceil2(1) == 1 - ceil2(2) == 2 - ceil2(3) == 4 - ceil2(4) == 4 - ceil2(15) == 16 - ceil2(16) == 16 - ceil2(17) == 32 - \endcode - */ - static inline size_t ceil2( size_t n ) - { - return size_t(1) << log2ceil( n ); - } - - /// Checks if \p n is power of 2 - CDS_CONSTEXPR static inline bool is_power2( size_t n ) CDS_NOEXCEPT - { - return (n & (n - 1)) == 0 && n; - } - - /// Returns binary logarithm of \p n if \p n is power of two, otherwise returns 0 - static inline size_t log2( size_t n ) - { - return is_power2(n) ? log2floor(n) : 0; - } -}} // namespace cds::beans - -#endif // #ifndef __CDS_INT_ALGO_H diff --git a/cds/intrusive/segmented_queue.h b/cds/intrusive/segmented_queue.h index 2fb03952..18a9d45a 100644 --- a/cds/intrusive/segmented_queue.h +++ b/cds/intrusive/segmented_queue.h @@ -5,7 +5,7 @@ #include #include -#include +#include #include #include #include diff --git a/cds/intrusive/split_list_base.h b/cds/intrusive/split_list_base.h index a5365535..a7bc10ab 100644 --- a/cds/intrusive/split_list_base.h +++ b/cds/intrusive/split_list_base.h @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include diff --git a/cds/numtraits.h b/cds/numtraits.h index 89f5aa76..df262a0a 100644 --- a/cds/numtraits.h +++ b/cds/numtraits.h @@ -55,31 +55,6 @@ namespace cds { }; //@endcond - //TODO - deprecated. Use is_power2 from int_algo.h - /// A tricky runtime algorithm to ensure that @p n is power of 2 - static inline bool isExp2( size_t n ) - { - return(n & (n - 1)) == 0 && n; - } - - //TODO: deprecated. Use log2 from int_algo.h - /// Runtime algorithm to compute log2( @p nTest ). If @p nTest is not power of two then -1 returns - static inline int exponent2( size_t nTest ) - { - int nExp = -1; - size_t nMask = 1; - for ( size_t n = 0; n < CDS_BUILD_BITS; n++ ) { - if ( nTest & nMask ) { - if ( nExp == -1 ) - nExp = (int) n; - else - return -1 ; // nTest íå ÿâëÿåòñÿ ñòåïåíüþ äâîéêè - } - nMask = nMask << 1; - } - return nExp; - } - /// Returns @a N: 2**N is nearest to @p nNumber, 2**N < nNumber static inline size_t exp2Ceil( size_t nNumber ) { diff --git a/cds/opt/buffer.h b/cds/opt/buffer.h index fe1d0815..71af760d 100644 --- a/cds/opt/buffer.h +++ b/cds/opt/buffer.h @@ -6,7 +6,7 @@ #include #include #include -#include +#include namespace cds { namespace opt { diff --git a/projects/Win/vc12/cds.vcxproj b/projects/Win/vc12/cds.vcxproj index 90d9b8c9..2ef5e971 100644 --- a/projects/Win/vc12/cds.vcxproj +++ b/projects/Win/vc12/cds.vcxproj @@ -810,7 +810,6 @@ - diff --git a/projects/Win/vc12/cds.vcxproj.filters b/projects/Win/vc12/cds.vcxproj.filters index 9a573f08..3f678be6 100644 --- a/projects/Win/vc12/cds.vcxproj.filters +++ b/projects/Win/vc12/cds.vcxproj.filters @@ -197,9 +197,6 @@ Header Files\cds - - Header Files\cds - Header Files\cds diff --git a/src/ptb_gc.cpp b/src/ptb_gc.cpp index 12ceb7f9..9a11b0bf 100644 --- a/src/ptb_gc.cpp +++ b/src/ptb_gc.cpp @@ -3,7 +3,7 @@ // Pass The Buck (PTB) Memory manager implementation #include -#include +#include #include #include // std::fill diff --git a/tests/test-hdr/misc/bitop_st.cpp b/tests/test-hdr/misc/bitop_st.cpp index 01d4de77..391a2a70 100644 --- a/tests/test-hdr/misc/bitop_st.cpp +++ b/tests/test-hdr/misc/bitop_st.cpp @@ -2,7 +2,7 @@ #include "cppunit/cppunit_proxy.h" -#include +#include #include class bitop_ST : public CppUnitMini::TestCase