内容纲要

二分查找

    /**
     * Performs binary search, resulting in position of the first element >= Value using predicate
     *
     * @param Range Range to search through, must be already sorted by SortPredicate
     * @param Value Value to look for
     * @param SortPredicate Predicate for sort comparison, defaults to <
     *
     * @returns Position of the first element >= Value, may be position after last element in range
     */
    template <typename RangeType, typename ValueType, typename SortPredicateType>
    FORCEINLINE auto LowerBound(RangeType& Range, const ValueType& Value, SortPredicateType SortPredicate) -> decltype(GetNum(Range))
    {
        return AlgoImpl::LowerBoundInternal(GetData(Range), GetNum(Range), Value, FIdentityFunctor(), SortPredicate);
    }
    template <typename RangeType, typename ValueType>
    FORCEINLINE auto LowerBound(RangeType& Range, const ValueType& Value) -> decltype(GetNum(Range))
    {
        return AlgoImpl::LowerBoundInternal(GetData(Range), GetNum(Range), Value, FIdentityFunctor(), TLess<>());
    }

    /**
     * Performs binary search, resulting in position of the first element with projected value >= Value using predicate
     *
     * @param Range Range to search through, must be already sorted by SortPredicate
     * @param Value Value to look for
     * @param Projection Functor or data member pointer, called via Invoke to compare to Value
     * @param SortPredicate Predicate for sort comparison, defaults to <
     *
     * @returns Position of the first element >= Value, may be position after last element in range
     */
    template <typename RangeType, typename ValueType, typename ProjectionType, typename SortPredicateType>
    FORCEINLINE auto LowerBoundBy(RangeType& Range, const ValueType& Value, ProjectionType Projection, SortPredicateType SortPredicate) -> decltype(GetNum(Range))
    {
        return AlgoImpl::LowerBoundInternal(GetData(Range), GetNum(Range), Value, Projection, SortPredicate);
    }
    template <typename RangeType, typename ValueType, typename ProjectionType>
    FORCEINLINE auto LowerBoundBy(RangeType& Range, const ValueType& Value, ProjectionType Projection) -> decltype(GetNum(Range))
    {
        return AlgoImpl::LowerBoundInternal(GetData(Range), GetNum(Range), Value, Projection, TLess<>());
    }
最后修改日期: 2022年11月6日

作者