annotate DEPENDENCIES/generic/include/boost/heap/detail/ilog2.hpp @ 133:4acb5d8d80b6 tip

Don't fail environmental check if README.md exists (but .txt and no-suffix don't)
author Chris Cannam
date Tue, 30 Jul 2019 12:25:44 +0100
parents 2665513ce2d3
children
rev   line source
Chris@16 1 // boost heap: integer log2
Chris@16 2 //
Chris@16 3 // Copyright (C) 2010 Tim Blechmann
Chris@16 4 //
Chris@16 5 // Distributed under the Boost Software License, Version 1.0. (See
Chris@16 6 // accompanying file LICENSE_1_0.txt or copy at
Chris@16 7 // http://www.boost.org/LICENSE_1_0.txt)
Chris@16 8
Chris@16 9 #ifndef BOOST_HEAP_DETAIL_ILOG2_HPP
Chris@16 10 #define BOOST_HEAP_DETAIL_ILOG2_HPP
Chris@16 11
Chris@16 12 #include <string> // std::size_t
Chris@16 13
Chris@16 14 namespace boost {
Chris@16 15 namespace heap {
Chris@16 16 namespace detail {
Chris@16 17
Chris@16 18 template <typename IntType>
Chris@16 19 struct log2
Chris@16 20 {
Chris@16 21 IntType operator()(IntType value)
Chris@16 22 {
Chris@16 23 IntType l = 0;
Chris@16 24 while( (value >> l) > 1 )
Chris@16 25 ++l;
Chris@16 26 return l;
Chris@16 27 }
Chris@16 28 };
Chris@16 29
Chris@16 30 #ifdef __GNUC__
Chris@16 31 template<>
Chris@16 32 struct log2<unsigned int>
Chris@16 33 {
Chris@16 34 unsigned int operator()(unsigned int value)
Chris@16 35 {
Chris@16 36 return sizeof(unsigned int)*8 - __builtin_clz(value - 1);
Chris@16 37 }
Chris@16 38 };
Chris@16 39
Chris@16 40 template<>
Chris@16 41 struct log2<unsigned long>
Chris@16 42 {
Chris@16 43 unsigned long operator()(unsigned long value)
Chris@16 44 {
Chris@16 45 return sizeof(unsigned long)*8 - __builtin_clzl(value - 1);
Chris@16 46 }
Chris@16 47 };
Chris@16 48
Chris@16 49 #endif
Chris@16 50
Chris@16 51 } /* namespace detail */
Chris@16 52
Chris@16 53
Chris@16 54 template <typename IntType>
Chris@16 55 IntType log2(IntType value)
Chris@16 56 {
Chris@16 57 detail::log2<IntType> fn;
Chris@16 58 return fn(value);
Chris@16 59 }
Chris@16 60
Chris@16 61 } /* namespace heap */
Chris@16 62 } /* namespace boost */
Chris@16 63
Chris@16 64 #endif /* BOOST_HEAP_DETAIL_ILOG2_HPP */