首页 > 编程语言 > 详细

C++算法实源码分析

时间:2015-12-07 20:42:28      阅读:380      评论:0      收藏:0      [点我收藏+]

includes:

// TEMPLATE FUNCTION includes WITH PRED
template<class _InIt1,
    class _InIt2,
    class _Pr> inline
    bool _Includes(_InIt1 _First1, _InIt1 _Last1,
        _InIt2 _First2, _InIt2 _Last2, _Pr _Pred)
    {    // test if set [_First1, _Last1) in [_First2, _Last2), using _Pred
    for (; _First1 != _Last1 && _First2 != _Last2; )
        if (_DEBUG_LT_PRED(_Pred, *_First2, *_First1))
            return (false);
        else if (_Pred(*_First1, *_First2))
            ++_First1;
        else
            {    // advance both
            ++_First1;
            ++_First2;
            }
    return (_First2 == _Last2);
    }

template<class _InIt1,
    class _InIt2,
    class _Pr> inline
    bool includes(_InIt1 _First1, _InIt1 _Last1,
        _InIt2 _First2, _InIt2 _Last2, _Pr _Pred)
    {    // test if set [_First1, _Last1) in [_First2, _Last2), using _Pred
    _DEBUG_ORDER_PRED(_First1, _Last1, _Pred);
    _DEBUG_ORDER_PRED(_First2, _Last2, _Pred);
    return (_Includes(_Unchecked(_First1), _Unchecked(_Last1),
        _Unchecked(_First2), _Unchecked(_Last2), _Pred));
    }

        // TEMPLATE FUNCTION includes
template<class _InIt1,
    class _InIt2> inline
    bool includes(_InIt1 _First1, _InIt1 _Last1,
        _InIt2 _First2, _InIt2 _Last2)
    {    // test if all [_First1, _Last1) in [_First2, _Last2), using operator<
    return (_STD includes(_First1, _Last1, _First2, _Last2,
        less<>()));
    }

在The C++ Standard Library (second edition, 3rd print)中指出这个算法的复杂度最多是2*(numElems+numSearchElems)-1comparisons。

C++算法实源码分析

原文:http://www.cnblogs.com/ptolemaeus/p/5027147.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!