forked from OSchip/llvm-project
Fix several bugs in find/count specialized for bits.
llvm-svn: 156546
This commit is contained in:
parent
ff15ef0c50
commit
423a8d7733
|
@ -146,11 +146,11 @@ private:
|
|||
|
||||
// find
|
||||
|
||||
template <class _Cp>
|
||||
__bit_iterator<_Cp, false>
|
||||
__find_bool_true(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n)
|
||||
template <class _Cp, bool _IsConst>
|
||||
__bit_iterator<_Cp, _IsConst>
|
||||
__find_bool_true(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n)
|
||||
{
|
||||
typedef __bit_iterator<_Cp, false> _It;
|
||||
typedef __bit_iterator<_Cp, _IsConst> _It;
|
||||
typedef typename _It::__storage_type __storage_type;
|
||||
static const unsigned __bits_per_word = _It::__bits_per_word;
|
||||
// do first partial word
|
||||
|
@ -180,11 +180,11 @@ __find_bool_true(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n
|
|||
return _It(__first.__seg_, static_cast<unsigned>(__n));
|
||||
}
|
||||
|
||||
template <class _Cp>
|
||||
__bit_iterator<_Cp, false>
|
||||
__find_bool_false(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n)
|
||||
template <class _Cp, bool _IsConst>
|
||||
__bit_iterator<_Cp, _IsConst>
|
||||
__find_bool_false(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n)
|
||||
{
|
||||
typedef __bit_iterator<_Cp, false> _It;
|
||||
typedef __bit_iterator<_Cp, _IsConst> _It;
|
||||
typedef typename _It::__storage_type __storage_type;
|
||||
static const unsigned __bits_per_word = _It::__bits_per_word;
|
||||
// do first partial word
|
||||
|
@ -193,7 +193,7 @@ __find_bool_false(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __
|
|||
__storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
|
||||
__storage_type __dn = _VSTD::min(__clz_f, __n);
|
||||
__storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
|
||||
__storage_type __b = ~(*__first.__seg_ & __m);
|
||||
__storage_type __b = ~*__first.__seg_ & __m;
|
||||
if (__b)
|
||||
return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(__b)));
|
||||
__n -= __dn;
|
||||
|
@ -210,17 +210,17 @@ __find_bool_false(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __
|
|||
if (__n > 0)
|
||||
{
|
||||
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
|
||||
__storage_type __b = ~(*__first.__seg_ & __m);
|
||||
__storage_type __b = ~*__first.__seg_ & __m;
|
||||
if (__b)
|
||||
return _It(__first.__seg_, static_cast<unsigned>(_VSTD::__ctz(__b)));
|
||||
}
|
||||
return _It(__first.__seg_, static_cast<unsigned>(__n));
|
||||
}
|
||||
|
||||
template <class _Cp, class _Tp>
|
||||
template <class _Cp, bool _IsConst, class _Tp>
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
__bit_iterator<_Cp, false>
|
||||
find(__bit_iterator<_Cp, false> __first, __bit_iterator<_Cp, false> __last, const _Tp& __value_)
|
||||
__bit_iterator<_Cp, _IsConst>
|
||||
find(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value_)
|
||||
{
|
||||
if (static_cast<bool>(__value_))
|
||||
return __find_bool_true(__first, static_cast<typename _Cp::size_type>(__last - __first));
|
||||
|
@ -229,11 +229,11 @@ find(__bit_iterator<_Cp, false> __first, __bit_iterator<_Cp, false> __last, cons
|
|||
|
||||
// count
|
||||
|
||||
template <class _Cp>
|
||||
typename __bit_iterator<_Cp, false>::difference_type
|
||||
__count_bool_true(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n)
|
||||
template <class _Cp, bool _IsConst>
|
||||
typename __bit_iterator<_Cp, _IsConst>::difference_type
|
||||
__count_bool_true(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n)
|
||||
{
|
||||
typedef __bit_iterator<_Cp, false> _It;
|
||||
typedef __bit_iterator<_Cp, _IsConst> _It;
|
||||
typedef typename _It::__storage_type __storage_type;
|
||||
typedef typename _It::difference_type difference_type;
|
||||
static const unsigned __bits_per_word = _It::__bits_per_word;
|
||||
|
@ -260,11 +260,11 @@ __count_bool_true(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __
|
|||
return __r;
|
||||
}
|
||||
|
||||
template <class _Cp>
|
||||
typename __bit_iterator<_Cp, false>::difference_type
|
||||
__count_bool_false(__bit_iterator<_Cp, false> __first, typename _Cp::size_type __n)
|
||||
template <class _Cp, bool _IsConst>
|
||||
typename __bit_iterator<_Cp, _IsConst>::difference_type
|
||||
__count_bool_false(__bit_iterator<_Cp, _IsConst> __first, typename _Cp::size_type __n)
|
||||
{
|
||||
typedef __bit_iterator<_Cp, false> _It;
|
||||
typedef __bit_iterator<_Cp, _IsConst> _It;
|
||||
typedef typename _It::__storage_type __storage_type;
|
||||
typedef typename _It::difference_type difference_type;
|
||||
static const unsigned __bits_per_word = _It::__bits_per_word;
|
||||
|
@ -275,7 +275,7 @@ __count_bool_false(__bit_iterator<_Cp, false> __first, typename _Cp::size_type _
|
|||
__storage_type __clz_f = static_cast<__storage_type>(__bits_per_word - __first.__ctz_);
|
||||
__storage_type __dn = _VSTD::min(__clz_f, __n);
|
||||
__storage_type __m = (~__storage_type(0) << __first.__ctz_) & (~__storage_type(0) >> (__clz_f - __dn));
|
||||
__r = _VSTD::__pop_count(~(*__first.__seg_ & __m));
|
||||
__r = _VSTD::__pop_count(~*__first.__seg_ & __m);
|
||||
__n -= __dn;
|
||||
++__first.__seg_;
|
||||
}
|
||||
|
@ -286,15 +286,15 @@ __count_bool_false(__bit_iterator<_Cp, false> __first, typename _Cp::size_type _
|
|||
if (__n > 0)
|
||||
{
|
||||
__storage_type __m = ~__storage_type(0) >> (__bits_per_word - __n);
|
||||
__r += _VSTD::__pop_count(~(*__first.__seg_ & __m));
|
||||
__r += _VSTD::__pop_count(~*__first.__seg_ & __m);
|
||||
}
|
||||
return __r;
|
||||
}
|
||||
|
||||
template <class _Cp, class _Tp>
|
||||
template <class _Cp, bool _IsConst, class _Tp>
|
||||
inline _LIBCPP_INLINE_VISIBILITY
|
||||
typename __bit_iterator<_Cp, false>::difference_type
|
||||
count(__bit_iterator<_Cp, false> __first, __bit_iterator<_Cp, false> __last, const _Tp& __value_)
|
||||
typename __bit_iterator<_Cp, _IsConst>::difference_type
|
||||
count(__bit_iterator<_Cp, _IsConst> __first, __bit_iterator<_Cp, _IsConst> __last, const _Tp& __value_)
|
||||
{
|
||||
if (static_cast<bool>(__value_))
|
||||
return __count_bool_true(__first, static_cast<typename _Cp::size_type>(__last - __first));
|
||||
|
@ -1238,14 +1238,14 @@ private:
|
|||
template <class _Dp, bool _IC1, bool _IC2> friend bool equal(__bit_iterator<_Dp, _IC1>,
|
||||
__bit_iterator<_Dp, _IC1>,
|
||||
__bit_iterator<_Dp, _IC2>);
|
||||
template <class _Dp> friend __bit_iterator<_Dp, false> __find_bool_true(__bit_iterator<_Dp, false>,
|
||||
template <class _Dp, bool _IC> friend __bit_iterator<_Dp, _IC> __find_bool_true(__bit_iterator<_Dp, _IC>,
|
||||
typename _Dp::size_type);
|
||||
template <class _Dp> friend __bit_iterator<_Dp, false> __find_bool_false(__bit_iterator<_Dp, false>,
|
||||
template <class _Dp, bool _IC> friend __bit_iterator<_Dp, _IC> __find_bool_false(__bit_iterator<_Dp, _IC>,
|
||||
typename _Dp::size_type);
|
||||
template <class _Dp> friend typename __bit_iterator<_Dp, false>::difference_type
|
||||
__count_bool_true(__bit_iterator<_Dp, false>, typename _Dp::size_type);
|
||||
template <class _Dp> friend typename __bit_iterator<_Dp, false>::difference_type
|
||||
__count_bool_false(__bit_iterator<_Dp, false>, typename _Dp::size_type);
|
||||
template <class _Dp, bool _IC> friend typename __bit_iterator<_Dp, _IC>::difference_type
|
||||
__count_bool_true(__bit_iterator<_Dp, _IC>, typename _Dp::size_type);
|
||||
template <class _Dp, bool _IC> friend typename __bit_iterator<_Dp, _IC>::difference_type
|
||||
__count_bool_false(__bit_iterator<_Dp, _IC>, typename _Dp::size_type);
|
||||
};
|
||||
|
||||
_LIBCPP_END_NAMESPACE_STD
|
||||
|
|
Loading…
Reference in New Issue