492
993
StrictWeakOrdering comp);
494
996
/*! \addtogroup vectorized_binary_search Vectorized Searches
495
997
* \ingroup binary_search
499
1002
//////////////////////
500
1003
// Vector Functions //
501
1004
//////////////////////
503
/*! \p lower_bound is a vectorized version of binary search: for each
504
* iterator \c v in <tt>[values_first, values_last)</tt> it attempts to
505
* find the value <tt>*v</tt> in an ordered range <tt>[first, last)</tt>.
506
* Specifically, it returns the index of first position where value could
507
* be inserted without violating the ordering.
509
* \param first The beginning of the ordered sequence.
510
* \param last The end of the ordered sequence.
511
* \param values_first The beginning of the search values sequence.
512
* \param values_last The end of the search values sequence.
513
* \param output The beginning of the output sequence.
515
* \tparam ForwardIterator is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator">Forward Iterator</a>.
516
* \tparam InputIterator is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>.
517
* and \c InputIterator's \c value_type is <a href="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThanComparable</a>.
518
* \tparam OutputIterator is a model of <a href="http://www.sgi.com/tech/stl/OutputIterator.html">Output Iterator</a>.
519
* and \c ForwardIterator's difference_type is convertible to \c OutputIterator's \c value_type.
521
* The following code snippet demonstrates how to use \p lower_bound
522
* to search for multiple values in a ordered range.
525
* #include <thrust/binary_search.h>
526
* #include <thrust/device_vector.h>
528
* thrust::device_vector<int> input(5);
536
* thrust::device_vector<int> values(6);
544
* thrust::device_vector<unsigned int> output(6);
546
* thrust::lower_bound(input.begin(), input.end(),
547
* values.begin(), values.end(),
550
* // output is now [0, 1, 1, 2, 4, 5]
553
* \see http://www.sgi.com/tech/stl/lower_bound.html
554
* \see \p upper_bound
555
* \see \p equal_range
556
* \see \p binary_search
558
template <class ForwardIterator, class InputIterator, class OutputIterator>
559
OutputIterator lower_bound(ForwardIterator first,
560
ForwardIterator last,
561
InputIterator values_first,
562
InputIterator values_last,
563
OutputIterator output);
566
/*! \p lower_bound is a vectorized version of binary search: for each
567
* iterator \c v in <tt>[values_first, values_last)</tt> it attempts to
568
* find the value <tt>*v</tt> in an ordered range <tt>[first, last)</tt>.
569
* Specifically, it returns the index of first position where value could
570
* be inserted without violating the ordering. This version of
571
* \p lower_bound uses function object \c comp for comparison.
573
* \param first The beginning of the ordered sequence.
574
* \param last The end of the ordered sequence.
575
* \param values_first The beginning of the search values sequence.
576
* \param values_last The end of the search values sequence.
577
* \param output The beginning of the output sequence.
578
* \param comp The comparison operator.
580
* \tparam ForwardIterator is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator">Forward Iterator</a>.
581
* \tparam InputIterator is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>.
582
* and \c InputIterator's \c value_type is comparable to \p ForwardIterator's \c value_type.
583
* \tparam OutputIterator is a model of <a href="http://www.sgi.com/tech/stl/OutputIterator.html">Output Iterator</a>.
584
* and \c ForwardIterator's difference_type is convertible to \c OutputIterator's \c value_type.
585
* \tparam StrictWeakOrdering is a model of <a href="http://www.sgi.com/tech/stl/StrictWeakOrdering.html">Strict Weak Ordering</a>.
587
* The following code snippet demonstrates how to use \p lower_bound
588
* to search for multiple values in a ordered range.
591
* #include <thrust/binary_search.h>
592
* #include <thrust/device_vector.h>
593
* #include <thrust/functional.h>
595
* thrust::device_vector<int> input(5);
603
* thrust::device_vector<int> values(6);
611
* thrust::device_vector<unsigned int> output(6);
613
* thrust::lower_bound(input.begin(), input.end(),
614
* values.begin(), values.end(),
616
* thrust::less<int>());
618
* // output is now [0, 1, 1, 2, 4, 5]
621
* \see http://www.sgi.com/tech/stl/lower_bound.html
622
* \see \p upper_bound
623
* \see \p equal_range
624
* \see \p binary_search
626
template <class ForwardIterator, class InputIterator, class OutputIterator, class StrictWeakOrdering>
627
OutputIterator lower_bound(ForwardIterator first,
628
ForwardIterator last,
629
InputIterator values_first,
630
InputIterator values_last,
631
OutputIterator output,
632
StrictWeakOrdering comp);
635
/*! \p upper_bound is a vectorized version of binary search: for each
636
* iterator \c v in <tt>[values_first, values_last)</tt> it attempts to
637
* find the value <tt>*v</tt> in an ordered range <tt>[first, last)</tt>.
638
* Specifically, it returns the index of last position where value could
639
* be inserted without violating the ordering.
641
* \param first The beginning of the ordered sequence.
642
* \param last The end of the ordered sequence.
643
* \param values_first The beginning of the search values sequence.
644
* \param values_last The end of the search values sequence.
645
* \param output The beginning of the output sequence.
647
* \tparam ForwardIterator is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator">Forward Iterator</a>.
648
* \tparam InputIterator is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>.
649
* and \c InputIterator's \c value_type is <a href="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThanComparable</a>.
650
* \tparam OutputIterator is a model of <a href="http://www.sgi.com/tech/stl/OutputIterator.html">Output Iterator</a>.
651
* and \c ForwardIterator's difference_type is convertible to \c OutputIterator's \c value_type.
653
* The following code snippet demonstrates how to use \p lower_bound
654
* to search for multiple values in a ordered range.
657
* #include <thrust/binary_search.h>
658
* #include <thrust/device_vector.h>
660
* thrust::device_vector<int> input(5);
668
* thrust::device_vector<int> values(6);
676
* thrust::device_vector<unsigned int> output(6);
678
* thrust::upper_bound(input.begin(), input.end(),
679
* values.begin(), values.end(),
682
* // output is now [1, 1, 2, 2, 5, 5]
685
* \see http://www.sgi.com/tech/stl/upper_bound.html
686
* \see \p upper_bound
687
* \see \p equal_range
688
* \see \p binary_search
690
template <class ForwardIterator, class InputIterator, class OutputIterator>
691
OutputIterator upper_bound(ForwardIterator first,
692
ForwardIterator last,
693
InputIterator values_first,
694
InputIterator values_last,
695
OutputIterator output);
698
/*! \p upper_bound is a vectorized version of binary search: for each
699
* iterator \c v in <tt>[values_first, values_last)</tt> it attempts to
700
* find the value <tt>*v</tt> in an ordered range <tt>[first, last)</tt>.
701
* Specifically, it returns the index of first position where value could
702
* be inserted without violating the ordering. This version of
703
* \p upper_bound uses function object \c comp for comparison.
705
* \param first The beginning of the ordered sequence.
706
* \param last The end of the ordered sequence.
707
* \param values_first The beginning of the search values sequence.
708
* \param values_last The end of the search values sequence.
709
* \param output The beginning of the output sequence.
710
* \param comp The comparison operator.
712
* \tparam ForwardIterator is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator">Forward Iterator</a>.
713
* \tparam InputIterator is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>.
714
* and \c InputIterator's \c value_type is comparable to \p ForwardIterator's \c value_type.
715
* \tparam OutputIterator is a model of <a href="http://www.sgi.com/tech/stl/OutputIterator.html">Output Iterator</a>.
716
* and \c ForwardIterator's difference_type is convertible to \c OutputIterator's \c value_type.
717
* \tparam StrictWeakOrdering is a model of <a href="http://www.sgi.com/tech/stl/StrictWeakOrdering.html">Strict Weak Ordering</a>.
719
* The following code snippet demonstrates how to use \p lower_bound
720
* to search for multiple values in a ordered range.
723
* #include <thrust/binary_search.h>
724
* #include <thrust/device_vector.h>
725
* #include <thrust/functional.h>
727
* thrust::device_vector<int> input(5);
735
* thrust::device_vector<int> values(6);
743
* thrust::device_vector<unsigned int> output(6);
745
* thrust::upper_bound(input.begin(), input.end(),
746
* values.begin(), values.end(),
748
* thrust::less<int>());
750
* // output is now [1, 1, 2, 2, 5, 5]
753
* \see http://www.sgi.com/tech/stl/upper_bound.html
754
* \see \p lower_bound
755
* \see \p equal_range
756
* \see \p binary_search
758
template <class ForwardIterator, class InputIterator, class OutputIterator, class StrictWeakOrdering>
759
OutputIterator upper_bound(ForwardIterator first,
760
ForwardIterator last,
761
InputIterator values_first,
762
InputIterator values_last,
763
OutputIterator output,
764
StrictWeakOrdering comp);
767
/*! \p binary_search is a vectorized version of binary search: for each
768
* iterator \c v in <tt>[values_first, values_last)</tt> it attempts to
769
* find the value <tt>*v</tt> in an ordered range <tt>[first, last)</tt>.
770
* It returns \c true if an element that is equivalent to \c value
771
* is present in <tt>[first, last)</tt> and \c false if no such element
774
* \param first The beginning of the ordered sequence.
775
* \param last The end of the ordered sequence.
776
* \param values_first The beginning of the search values sequence.
777
* \param values_last The end of the search values sequence.
778
* \param output The beginning of the output sequence.
780
* \tparam ForwardIterator is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator">Forward Iterator</a>.
781
* \tparam InputIterator is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>.
782
* and \c InputIterator's \c value_type is <a href="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThanComparable</a>.
783
* \tparam OutputIterator is a model of <a href="http://www.sgi.com/tech/stl/OutputIterator.html">Output Iterator</a>.
784
* and bool is convertible to \c OutputIterator's \c value_type.
786
* The following code snippet demonstrates how to use \p binary_search
787
* to search for multiple values in a ordered range.
790
* #include <thrust/binary_search.h>
791
* #include <thrust/device_vector.h>
793
* thrust::device_vector<int> input(5);
801
* thrust::device_vector<int> values(6);
809
* thrust::device_vector<bool> output(6);
811
* thrust::binary_search(input.begin(), input.end(),
812
* values.begin(), values.end(),
815
* // output is now [true, false, true, false, true, false]
818
* \see http://www.sgi.com/tech/stl/binary_search.html
819
* \see \p lower_bound
820
* \see \p upper_bound
821
* \see \p equal_range
823
template <class ForwardIterator, class InputIterator, class OutputIterator>
824
OutputIterator binary_search(ForwardIterator first,
825
ForwardIterator last,
826
InputIterator values_first,
827
InputIterator values_last,
828
OutputIterator output);
831
/*! \p binary_search is a vectorized version of binary search: for each
832
* iterator \c v in <tt>[values_first, values_last)</tt> it attempts to
833
* find the value <tt>*v</tt> in an ordered range <tt>[first, last)</tt>.
834
* It returns \c true if an element that is equivalent to \c value
835
* is present in <tt>[first, last)</tt> and \c false if no such element
836
* exists. This version of \p binary_search uses function object
837
* \c comp for comparison.
839
* \param first The beginning of the ordered sequence.
840
* \param last The end of the ordered sequence.
841
* \param values_first The beginning of the search values sequence.
842
* \param values_last The end of the search values sequence.
843
* \param output The beginning of the output sequence.
844
* \param comp The comparison operator.
846
* \tparam ForwardIterator is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator">Forward Iterator</a>.
847
* \tparam InputIterator is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>.
848
* and \c InputIterator's \c value_type is <a href="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThanComparable</a>.
849
* \tparam OutputIterator is a model of <a href="http://www.sgi.com/tech/stl/OutputIterator.html">Output Iterator</a>.
850
* and bool is convertible to \c OutputIterator's \c value_type.
851
* \tparam StrictWeakOrdering is a model of <a href="http://www.sgi.com/tech/stl/StrictWeakOrdering.html">Strict Weak Ordering</a>.
853
* The following code snippet demonstrates how to use \p binary_search
854
* to search for multiple values in a ordered range.
857
* #include <thrust/binary_search.h>
858
* #include <thrust/device_vector.h>
859
* #include <thrust/functional.h>
861
* thrust::device_vector<int> input(5);
869
* thrust::device_vector<int> values(6);
877
* thrust::device_vector<bool> output(6);
879
* thrust::binary_search(input.begin(), input.end(),
880
* values.begin(), values.end(),
882
* thrust::less<T>());
884
* // output is now [true, false, true, false, true, false]
887
* \see http://www.sgi.com/tech/stl/binary_search.html
888
* \see \p lower_bound
889
* \see \p upper_bound
890
* \see \p equal_range
892
template <class ForwardIterator, class InputIterator, class OutputIterator, class StrictWeakOrdering>
893
OutputIterator binary_search(ForwardIterator first,
894
ForwardIterator last,
895
InputIterator values_first,
896
InputIterator values_last,
897
OutputIterator output,
898
StrictWeakOrdering comp);
1007
/*! \p lower_bound is a vectorized version of binary search: for each
1008
* iterator \c v in <tt>[values_first, values_last)</tt> it attempts to
1009
* find the value <tt>*v</tt> in an ordered range <tt>[first, last)</tt>.
1010
* Specifically, it returns the index of first position where value could
1011
* be inserted without violating the ordering.
1013
* The algorithm's execution is parallelized as determined by \p exec.
1015
* \param exec The execution policy to use for parallelization.
1016
* \param first The beginning of the ordered sequence.
1017
* \param last The end of the ordered sequence.
1018
* \param values_first The beginning of the search values sequence.
1019
* \param values_last The end of the search values sequence.
1020
* \param result The beginning of the output sequence.
1022
* \tparam DerivedPolicy The name of the derived execution policy.
1023
* \tparam ForwardIterator is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator">Forward Iterator</a>.
1024
* \tparam InputIterator is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>.
1025
* and \c InputIterator's \c value_type is <a href="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThanComparable</a>.
1026
* \tparam OutputIterator is a model of <a href="http://www.sgi.com/tech/stl/OutputIterator.html">Output Iterator</a>.
1027
* and \c ForwardIterator's difference_type is convertible to \c OutputIterator's \c value_type.
1029
* \pre The ranges <tt>[first,last)</tt> and <tt>[result, result + (last - first))</tt> shall not overlap.
1031
* The following code snippet demonstrates how to use \p lower_bound
1032
* to search for multiple values in a ordered range using the \p thrust::device execution policy for
1036
* #include <thrust/binary_search.h>
1037
* #include <thrust/device_vector.h>
1038
* #include <thrust/execution_policy.h>
1040
* thrust::device_vector<int> input(5);
1048
* thrust::device_vector<int> values(6);
1056
* thrust::device_vector<unsigned int> output(6);
1058
* thrust::lower_bound(thrust::device,
1059
* input.begin(), input.end(),
1060
* values.begin(), values.end(),
1063
* // output is now [0, 1, 1, 2, 4, 5]
1066
* \see http://www.sgi.com/tech/stl/lower_bound.html
1067
* \see \p upper_bound
1068
* \see \p equal_range
1069
* \see \p binary_search
1071
template <typename DerivedPolicy, typename ForwardIterator, typename InputIterator, typename OutputIterator>
1072
OutputIterator lower_bound(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
1073
ForwardIterator first,
1074
ForwardIterator last,
1075
InputIterator values_first,
1076
InputIterator values_last,
1077
OutputIterator result);
1080
/*! \p lower_bound is a vectorized version of binary search: for each
1081
* iterator \c v in <tt>[values_first, values_last)</tt> it attempts to
1082
* find the value <tt>*v</tt> in an ordered range <tt>[first, last)</tt>.
1083
* Specifically, it returns the index of first position where value could
1084
* be inserted without violating the ordering.
1086
* \param first The beginning of the ordered sequence.
1087
* \param last The end of the ordered sequence.
1088
* \param values_first The beginning of the search values sequence.
1089
* \param values_last The end of the search values sequence.
1090
* \param result The beginning of the output sequence.
1092
* \tparam ForwardIterator is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator">Forward Iterator</a>.
1093
* \tparam InputIterator is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>.
1094
* and \c InputIterator's \c value_type is <a href="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThanComparable</a>.
1095
* \tparam OutputIterator is a model of <a href="http://www.sgi.com/tech/stl/OutputIterator.html">Output Iterator</a>.
1096
* and \c ForwardIterator's difference_type is convertible to \c OutputIterator's \c value_type.
1098
* \pre The ranges <tt>[first,last)</tt> and <tt>[result, result + (last - first))</tt> shall not overlap.
1100
* The following code snippet demonstrates how to use \p lower_bound
1101
* to search for multiple values in a ordered range.
1104
* #include <thrust/binary_search.h>
1105
* #include <thrust/device_vector.h>
1107
* thrust::device_vector<int> input(5);
1115
* thrust::device_vector<int> values(6);
1123
* thrust::device_vector<unsigned int> output(6);
1125
* thrust::lower_bound(input.begin(), input.end(),
1126
* values.begin(), values.end(),
1129
* // output is now [0, 1, 1, 2, 4, 5]
1132
* \see http://www.sgi.com/tech/stl/lower_bound.html
1133
* \see \p upper_bound
1134
* \see \p equal_range
1135
* \see \p binary_search
1137
template <class ForwardIterator, class InputIterator, class OutputIterator>
1138
OutputIterator lower_bound(ForwardIterator first,
1139
ForwardIterator last,
1140
InputIterator values_first,
1141
InputIterator values_last,
1142
OutputIterator result);
1145
/*! \p lower_bound is a vectorized version of binary search: for each
1146
* iterator \c v in <tt>[values_first, values_last)</tt> it attempts to
1147
* find the value <tt>*v</tt> in an ordered range <tt>[first, last)</tt>.
1148
* Specifically, it returns the index of first position where value could
1149
* be inserted without violating the ordering. This version of
1150
* \p lower_bound uses function object \c comp for comparison.
1152
* The algorithm's execution is parallelized as determined by \p exec.
1154
* \param exec The execution policy to use for parallelization.
1155
* \param first The beginning of the ordered sequence.
1156
* \param last The end of the ordered sequence.
1157
* \param values_first The beginning of the search values sequence.
1158
* \param values_last The end of the search values sequence.
1159
* \param result The beginning of the output sequence.
1160
* \param comp The comparison operator.
1162
* \tparam DerivedPolicy The name of the derived execution policy.
1163
* \tparam ForwardIterator is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator">Forward Iterator</a>.
1164
* \tparam InputIterator is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>.
1165
* and \c InputIterator's \c value_type is comparable to \p ForwardIterator's \c value_type.
1166
* \tparam OutputIterator is a model of <a href="http://www.sgi.com/tech/stl/OutputIterator.html">Output Iterator</a>.
1167
* and \c ForwardIterator's difference_type is convertible to \c OutputIterator's \c value_type.
1168
* \tparam StrictWeakOrdering is a model of <a href="http://www.sgi.com/tech/stl/StrictWeakOrdering.html">Strict Weak Ordering</a>.
1170
* \pre The ranges <tt>[first,last)</tt> and <tt>[result, result + (last - first))</tt> shall not overlap.
1172
* The following code snippet demonstrates how to use \p lower_bound
1173
* to search for multiple values in a ordered range.
1176
* #include <thrust/binary_search.h>
1177
* #include <thrust/device_vector.h>
1178
* #include <thrust/functional.h>
1179
* #include <thrust/execution_policy.h>
1181
* thrust::device_vector<int> input(5);
1189
* thrust::device_vector<int> values(6);
1197
* thrust::device_vector<unsigned int> output(6);
1199
* thrust::lower_bound(input.begin(), input.end(),
1200
* values.begin(), values.end(),
1202
* thrust::less<int>());
1204
* // output is now [0, 1, 1, 2, 4, 5]
1207
* \see http://www.sgi.com/tech/stl/lower_bound.html
1208
* \see \p upper_bound
1209
* \see \p equal_range
1210
* \see \p binary_search
1212
template <typename DerivedPolicy, typename ForwardIterator, typename InputIterator, typename OutputIterator, typename StrictWeakOrdering>
1213
OutputIterator lower_bound(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
1214
ForwardIterator first,
1215
ForwardIterator last,
1216
InputIterator values_first,
1217
InputIterator values_last,
1218
OutputIterator result,
1219
StrictWeakOrdering comp);
1222
/*! \p lower_bound is a vectorized version of binary search: for each
1223
* iterator \c v in <tt>[values_first, values_last)</tt> it attempts to
1224
* find the value <tt>*v</tt> in an ordered range <tt>[first, last)</tt>.
1225
* Specifically, it returns the index of first position where value could
1226
* be inserted without violating the ordering. This version of
1227
* \p lower_bound uses function object \c comp for comparison.
1229
* \param first The beginning of the ordered sequence.
1230
* \param last The end of the ordered sequence.
1231
* \param values_first The beginning of the search values sequence.
1232
* \param values_last The end of the search values sequence.
1233
* \param result The beginning of the output sequence.
1234
* \param comp The comparison operator.
1236
* \tparam ForwardIterator is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator">Forward Iterator</a>.
1237
* \tparam InputIterator is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>.
1238
* and \c InputIterator's \c value_type is comparable to \p ForwardIterator's \c value_type.
1239
* \tparam OutputIterator is a model of <a href="http://www.sgi.com/tech/stl/OutputIterator.html">Output Iterator</a>.
1240
* and \c ForwardIterator's difference_type is convertible to \c OutputIterator's \c value_type.
1241
* \tparam StrictWeakOrdering is a model of <a href="http://www.sgi.com/tech/stl/StrictWeakOrdering.html">Strict Weak Ordering</a>.
1243
* \pre The ranges <tt>[first,last)</tt> and <tt>[result, result + (last - first))</tt> shall not overlap.
1245
* The following code snippet demonstrates how to use \p lower_bound
1246
* to search for multiple values in a ordered range.
1249
* #include <thrust/binary_search.h>
1250
* #include <thrust/device_vector.h>
1251
* #include <thrust/functional.h>
1253
* thrust::device_vector<int> input(5);
1261
* thrust::device_vector<int> values(6);
1269
* thrust::device_vector<unsigned int> output(6);
1271
* thrust::lower_bound(input.begin(), input.end(),
1272
* values.begin(), values.end(),
1274
* thrust::less<int>());
1276
* // output is now [0, 1, 1, 2, 4, 5]
1279
* \see http://www.sgi.com/tech/stl/lower_bound.html
1280
* \see \p upper_bound
1281
* \see \p equal_range
1282
* \see \p binary_search
1284
template <class ForwardIterator, class InputIterator, class OutputIterator, class StrictWeakOrdering>
1285
OutputIterator lower_bound(ForwardIterator first,
1286
ForwardIterator last,
1287
InputIterator values_first,
1288
InputIterator values_last,
1289
OutputIterator result,
1290
StrictWeakOrdering comp);
1293
/*! \p upper_bound is a vectorized version of binary search: for each
1294
* iterator \c v in <tt>[values_first, values_last)</tt> it attempts to
1295
* find the value <tt>*v</tt> in an ordered range <tt>[first, last)</tt>.
1296
* Specifically, it returns the index of last position where value could
1297
* be inserted without violating the ordering.
1299
* The algorithm's execution is parallelized as determined by \p exec.
1301
* \param exec The execution policy to use for parallelization.
1302
* \param first The beginning of the ordered sequence.
1303
* \param last The end of the ordered sequence.
1304
* \param values_first The beginning of the search values sequence.
1305
* \param values_last The end of the search values sequence.
1306
* \param result The beginning of the output sequence.
1308
* \tparam DerivedPolicy The name of the derived execution policy.
1309
* \tparam ForwardIterator is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator">Forward Iterator</a>.
1310
* \tparam InputIterator is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>.
1311
* and \c InputIterator's \c value_type is <a href="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThanComparable</a>.
1312
* \tparam OutputIterator is a model of <a href="http://www.sgi.com/tech/stl/OutputIterator.html">Output Iterator</a>.
1313
* and \c ForwardIterator's difference_type is convertible to \c OutputIterator's \c value_type.
1315
* \pre The ranges <tt>[first,last)</tt> and <tt>[result, result + (last - first))</tt> shall not overlap.
1317
* The following code snippet demonstrates how to use \p lower_bound
1318
* to search for multiple values in a ordered range using the \p thrust::device execution policy for
1322
* #include <thrust/binary_search.h>
1323
* #include <thrust/device_vector.h>
1324
* #include <thrust/execution_policy.h>
1326
* thrust::device_vector<int> input(5);
1334
* thrust::device_vector<int> values(6);
1342
* thrust::device_vector<unsigned int> output(6);
1344
* thrust::upper_bound(thrust::device,
1345
* input.begin(), input.end(),
1346
* values.begin(), values.end(),
1349
* // output is now [1, 1, 2, 2, 5, 5]
1352
* \see http://www.sgi.com/tech/stl/upper_bound.html
1353
* \see \p upper_bound
1354
* \see \p equal_range
1355
* \see \p binary_search
1357
template <typename DerivedPolicy, typename ForwardIterator, typename InputIterator, typename OutputIterator>
1358
OutputIterator upper_bound(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
1359
ForwardIterator first,
1360
ForwardIterator last,
1361
InputIterator values_first,
1362
InputIterator values_last,
1363
OutputIterator result);
1366
/*! \p upper_bound is a vectorized version of binary search: for each
1367
* iterator \c v in <tt>[values_first, values_last)</tt> it attempts to
1368
* find the value <tt>*v</tt> in an ordered range <tt>[first, last)</tt>.
1369
* Specifically, it returns the index of last position where value could
1370
* be inserted without violating the ordering.
1372
* \param first The beginning of the ordered sequence.
1373
* \param last The end of the ordered sequence.
1374
* \param values_first The beginning of the search values sequence.
1375
* \param values_last The end of the search values sequence.
1376
* \param result The beginning of the output sequence.
1378
* \tparam ForwardIterator is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator">Forward Iterator</a>.
1379
* \tparam InputIterator is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>.
1380
* and \c InputIterator's \c value_type is <a href="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThanComparable</a>.
1381
* \tparam OutputIterator is a model of <a href="http://www.sgi.com/tech/stl/OutputIterator.html">Output Iterator</a>.
1382
* and \c ForwardIterator's difference_type is convertible to \c OutputIterator's \c value_type.
1384
* \pre The ranges <tt>[first,last)</tt> and <tt>[result, result + (last - first))</tt> shall not overlap.
1386
* The following code snippet demonstrates how to use \p lower_bound
1387
* to search for multiple values in a ordered range.
1390
* #include <thrust/binary_search.h>
1391
* #include <thrust/device_vector.h>
1393
* thrust::device_vector<int> input(5);
1401
* thrust::device_vector<int> values(6);
1409
* thrust::device_vector<unsigned int> output(6);
1411
* thrust::upper_bound(input.begin(), input.end(),
1412
* values.begin(), values.end(),
1415
* // output is now [1, 1, 2, 2, 5, 5]
1418
* \see http://www.sgi.com/tech/stl/upper_bound.html
1419
* \see \p upper_bound
1420
* \see \p equal_range
1421
* \see \p binary_search
1423
template <class ForwardIterator, class InputIterator, class OutputIterator>
1424
OutputIterator upper_bound(ForwardIterator first,
1425
ForwardIterator last,
1426
InputIterator values_first,
1427
InputIterator values_last,
1428
OutputIterator result);
1431
/*! \p upper_bound is a vectorized version of binary search: for each
1432
* iterator \c v in <tt>[values_first, values_last)</tt> it attempts to
1433
* find the value <tt>*v</tt> in an ordered range <tt>[first, last)</tt>.
1434
* Specifically, it returns the index of first position where value could
1435
* be inserted without violating the ordering. This version of
1436
* \p upper_bound uses function object \c comp for comparison.
1438
* The algorithm's execution is parallelized as determined by \p exec.
1440
* \param exec The execution policy to use for parallelization.
1441
* \param first The beginning of the ordered sequence.
1442
* \param last The end of the ordered sequence.
1443
* \param values_first The beginning of the search values sequence.
1444
* \param values_last The end of the search values sequence.
1445
* \param result The beginning of the output sequence.
1446
* \param comp The comparison operator.
1448
* \tparam DerivedPolicy The name of the derived execution policy.
1449
* \tparam ForwardIterator is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator">Forward Iterator</a>.
1450
* \tparam InputIterator is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>.
1451
* and \c InputIterator's \c value_type is comparable to \p ForwardIterator's \c value_type.
1452
* \tparam OutputIterator is a model of <a href="http://www.sgi.com/tech/stl/OutputIterator.html">Output Iterator</a>.
1453
* and \c ForwardIterator's difference_type is convertible to \c OutputIterator's \c value_type.
1454
* \tparam StrictWeakOrdering is a model of <a href="http://www.sgi.com/tech/stl/StrictWeakOrdering.html">Strict Weak Ordering</a>.
1456
* \pre The ranges <tt>[first,last)</tt> and <tt>[result, result + (last - first))</tt> shall not overlap.
1458
* The following code snippet demonstrates how to use \p lower_bound
1459
* to search for multiple values in a ordered range using the \p thrust::device execution policy for
1463
* #include <thrust/binary_search.h>
1464
* #include <thrust/device_vector.h>
1465
* #include <thrust/functional.h>
1466
* #include <thrust/execution_policy.h>
1468
* thrust::device_vector<int> input(5);
1476
* thrust::device_vector<int> values(6);
1484
* thrust::device_vector<unsigned int> output(6);
1486
* thrust::upper_bound(thrust::device,
1487
* input.begin(), input.end(),
1488
* values.begin(), values.end(),
1490
* thrust::less<int>());
1492
* // output is now [1, 1, 2, 2, 5, 5]
1495
* \see http://www.sgi.com/tech/stl/upper_bound.html
1496
* \see \p lower_bound
1497
* \see \p equal_range
1498
* \see \p binary_search
1500
template <typename DerivedPolicy, typename ForwardIterator, typename InputIterator, typename OutputIterator, typename StrictWeakOrdering>
1501
OutputIterator upper_bound(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
1502
ForwardIterator first,
1503
ForwardIterator last,
1504
InputIterator values_first,
1505
InputIterator values_last,
1506
OutputIterator result,
1507
StrictWeakOrdering comp);
1510
/*! \p upper_bound is a vectorized version of binary search: for each
1511
* iterator \c v in <tt>[values_first, values_last)</tt> it attempts to
1512
* find the value <tt>*v</tt> in an ordered range <tt>[first, last)</tt>.
1513
* Specifically, it returns the index of first position where value could
1514
* be inserted without violating the ordering. This version of
1515
* \p upper_bound uses function object \c comp for comparison.
1517
* \param first The beginning of the ordered sequence.
1518
* \param last The end of the ordered sequence.
1519
* \param values_first The beginning of the search values sequence.
1520
* \param values_last The end of the search values sequence.
1521
* \param result The beginning of the output sequence.
1522
* \param comp The comparison operator.
1524
* \tparam ForwardIterator is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator">Forward Iterator</a>.
1525
* \tparam InputIterator is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>.
1526
* and \c InputIterator's \c value_type is comparable to \p ForwardIterator's \c value_type.
1527
* \tparam OutputIterator is a model of <a href="http://www.sgi.com/tech/stl/OutputIterator.html">Output Iterator</a>.
1528
* and \c ForwardIterator's difference_type is convertible to \c OutputIterator's \c value_type.
1529
* \tparam StrictWeakOrdering is a model of <a href="http://www.sgi.com/tech/stl/StrictWeakOrdering.html">Strict Weak Ordering</a>.
1531
* \pre The ranges <tt>[first,last)</tt> and <tt>[result, result + (last - first))</tt> shall not overlap.
1533
* The following code snippet demonstrates how to use \p lower_bound
1534
* to search for multiple values in a ordered range.
1537
* #include <thrust/binary_search.h>
1538
* #include <thrust/device_vector.h>
1539
* #include <thrust/functional.h>
1541
* thrust::device_vector<int> input(5);
1549
* thrust::device_vector<int> values(6);
1557
* thrust::device_vector<unsigned int> output(6);
1559
* thrust::upper_bound(input.begin(), input.end(),
1560
* values.begin(), values.end(),
1562
* thrust::less<int>());
1564
* // output is now [1, 1, 2, 2, 5, 5]
1567
* \see http://www.sgi.com/tech/stl/upper_bound.html
1568
* \see \p lower_bound
1569
* \see \p equal_range
1570
* \see \p binary_search
1572
template <class ForwardIterator, class InputIterator, class OutputIterator, class StrictWeakOrdering>
1573
OutputIterator upper_bound(ForwardIterator first,
1574
ForwardIterator last,
1575
InputIterator values_first,
1576
InputIterator values_last,
1577
OutputIterator result,
1578
StrictWeakOrdering comp);
1581
/*! \p binary_search is a vectorized version of binary search: for each
1582
* iterator \c v in <tt>[values_first, values_last)</tt> it attempts to
1583
* find the value <tt>*v</tt> in an ordered range <tt>[first, last)</tt>.
1584
* It returns \c true if an element that is equivalent to \c value
1585
* is present in <tt>[first, last)</tt> and \c false if no such element
1588
* The algorithm's execution is parallelized as determined by \p exec.
1590
* \param exec The execution policy to use for parallelization.
1591
* \param first The beginning of the ordered sequence.
1592
* \param last The end of the ordered sequence.
1593
* \param values_first The beginning of the search values sequence.
1594
* \param values_last The end of the search values sequence.
1595
* \param result The beginning of the output sequence.
1597
* \tparam DerivedPolicy The name of the derived execution policy.
1598
* \tparam ForwardIterator is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator">Forward Iterator</a>.
1599
* \tparam InputIterator is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>.
1600
* and \c InputIterator's \c value_type is <a href="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThanComparable</a>.
1601
* \tparam OutputIterator is a model of <a href="http://www.sgi.com/tech/stl/OutputIterator.html">Output Iterator</a>.
1602
* and bool is convertible to \c OutputIterator's \c value_type.
1604
* \pre The ranges <tt>[first,last)</tt> and <tt>[result, result + (last - first))</tt> shall not overlap.
1606
* The following code snippet demonstrates how to use \p binary_search
1607
* to search for multiple values in a ordered range using the \p thrust::device execution policy for
1611
* #include <thrust/binary_search.h>
1612
* #include <thrust/device_vector.h>
1613
* #include <thrust/execution_policy.h>
1615
* thrust::device_vector<int> input(5);
1623
* thrust::device_vector<int> values(6);
1631
* thrust::device_vector<bool> output(6);
1633
* thrust::binary_search(thrust::device,
1634
* input.begin(), input.end(),
1635
* values.begin(), values.end(),
1638
* // output is now [true, false, true, false, true, false]
1641
* \see http://www.sgi.com/tech/stl/binary_search.html
1642
* \see \p lower_bound
1643
* \see \p upper_bound
1644
* \see \p equal_range
1646
template <typename DerivedPolicy, typename ForwardIterator, typename InputIterator, typename OutputIterator>
1647
OutputIterator binary_search(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
1648
ForwardIterator first,
1649
ForwardIterator last,
1650
InputIterator values_first,
1651
InputIterator values_last,
1652
OutputIterator result);
1655
/*! \p binary_search is a vectorized version of binary search: for each
1656
* iterator \c v in <tt>[values_first, values_last)</tt> it attempts to
1657
* find the value <tt>*v</tt> in an ordered range <tt>[first, last)</tt>.
1658
* It returns \c true if an element that is equivalent to \c value
1659
* is present in <tt>[first, last)</tt> and \c false if no such element
1662
* \param first The beginning of the ordered sequence.
1663
* \param last The end of the ordered sequence.
1664
* \param values_first The beginning of the search values sequence.
1665
* \param values_last The end of the search values sequence.
1666
* \param result The beginning of the output sequence.
1668
* \tparam ForwardIterator is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator">Forward Iterator</a>.
1669
* \tparam InputIterator is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>.
1670
* and \c InputIterator's \c value_type is <a href="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThanComparable</a>.
1671
* \tparam OutputIterator is a model of <a href="http://www.sgi.com/tech/stl/OutputIterator.html">Output Iterator</a>.
1672
* and bool is convertible to \c OutputIterator's \c value_type.
1674
* \pre The ranges <tt>[first,last)</tt> and <tt>[result, result + (last - first))</tt> shall not overlap.
1676
* The following code snippet demonstrates how to use \p binary_search
1677
* to search for multiple values in a ordered range.
1680
* #include <thrust/binary_search.h>
1681
* #include <thrust/device_vector.h>
1683
* thrust::device_vector<int> input(5);
1691
* thrust::device_vector<int> values(6);
1699
* thrust::device_vector<bool> output(6);
1701
* thrust::binary_search(input.begin(), input.end(),
1702
* values.begin(), values.end(),
1705
* // output is now [true, false, true, false, true, false]
1708
* \see http://www.sgi.com/tech/stl/binary_search.html
1709
* \see \p lower_bound
1710
* \see \p upper_bound
1711
* \see \p equal_range
1713
template <class ForwardIterator, class InputIterator, class OutputIterator>
1714
OutputIterator binary_search(ForwardIterator first,
1715
ForwardIterator last,
1716
InputIterator values_first,
1717
InputIterator values_last,
1718
OutputIterator result);
1721
/*! \p binary_search is a vectorized version of binary search: for each
1722
* iterator \c v in <tt>[values_first, values_last)</tt> it attempts to
1723
* find the value <tt>*v</tt> in an ordered range <tt>[first, last)</tt>.
1724
* It returns \c true if an element that is equivalent to \c value
1725
* is present in <tt>[first, last)</tt> and \c false if no such element
1726
* exists. This version of \p binary_search uses function object
1727
* \c comp for comparison.
1729
* The algorithm's execution is parallelized as determined by \p exec.
1731
* \param exec The execution policy to use for parallelization.
1732
* \param first The beginning of the ordered sequence.
1733
* \param last The end of the ordered sequence.
1734
* \param values_first The beginning of the search values sequence.
1735
* \param values_last The end of the search values sequence.
1736
* \param result The beginning of the output sequence.
1737
* \param comp The comparison operator.
1739
* \tparam DerivedPolicy The name of the derived execution policy.
1740
* \tparam ForwardIterator is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator">Forward Iterator</a>.
1741
* \tparam InputIterator is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>.
1742
* and \c InputIterator's \c value_type is <a href="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThanComparable</a>.
1743
* \tparam OutputIterator is a model of <a href="http://www.sgi.com/tech/stl/OutputIterator.html">Output Iterator</a>.
1744
* and bool is convertible to \c OutputIterator's \c value_type.
1745
* \tparam StrictWeakOrdering is a model of <a href="http://www.sgi.com/tech/stl/StrictWeakOrdering.html">Strict Weak Ordering</a>.
1747
* \pre The ranges <tt>[first,last)</tt> and <tt>[result, result + (last - first))</tt> shall not overlap.
1749
* The following code snippet demonstrates how to use \p binary_search
1750
* to search for multiple values in a ordered range using the \p thrust::device execution policy for
1754
* #include <thrust/binary_search.h>
1755
* #include <thrust/device_vector.h>
1756
* #include <thrust/functional.h>
1757
* #include <thrust/execution_policy.h>
1759
* thrust::device_vector<int> input(5);
1767
* thrust::device_vector<int> values(6);
1775
* thrust::device_vector<bool> output(6);
1777
* thrust::binary_search(thrust::device,
1778
* input.begin(), input.end(),
1779
* values.begin(), values.end(),
1781
* thrust::less<T>());
1783
* // output is now [true, false, true, false, true, false]
1786
* \see http://www.sgi.com/tech/stl/binary_search.html
1787
* \see \p lower_bound
1788
* \see \p upper_bound
1789
* \see \p equal_range
1791
template <typename DerivedPolicy, typename ForwardIterator, typename InputIterator, typename OutputIterator, typename StrictWeakOrdering>
1792
OutputIterator binary_search(const thrust::detail::execution_policy_base<DerivedPolicy> &exec,
1793
ForwardIterator first,
1794
ForwardIterator last,
1795
InputIterator values_first,
1796
InputIterator values_last,
1797
OutputIterator result,
1798
StrictWeakOrdering comp);
1801
/*! \p binary_search is a vectorized version of binary search: for each
1802
* iterator \c v in <tt>[values_first, values_last)</tt> it attempts to
1803
* find the value <tt>*v</tt> in an ordered range <tt>[first, last)</tt>.
1804
* It returns \c true if an element that is equivalent to \c value
1805
* is present in <tt>[first, last)</tt> and \c false if no such element
1806
* exists. This version of \p binary_search uses function object
1807
* \c comp for comparison.
1809
* \param first The beginning of the ordered sequence.
1810
* \param last The end of the ordered sequence.
1811
* \param values_first The beginning of the search values sequence.
1812
* \param values_last The end of the search values sequence.
1813
* \param result The beginning of the output sequence.
1814
* \param comp The comparison operator.
1816
* \tparam ForwardIterator is a model of <a href="http://www.sgi.com/tech/stl/ForwardIterator">Forward Iterator</a>.
1817
* \tparam InputIterator is a model of <a href="http://www.sgi.com/tech/stl/InputIterator.html">Input Iterator</a>.
1818
* and \c InputIterator's \c value_type is <a href="http://www.sgi.com/tech/stl/LessThanComparable.html">LessThanComparable</a>.
1819
* \tparam OutputIterator is a model of <a href="http://www.sgi.com/tech/stl/OutputIterator.html">Output Iterator</a>.
1820
* and bool is convertible to \c OutputIterator's \c value_type.
1821
* \tparam StrictWeakOrdering is a model of <a href="http://www.sgi.com/tech/stl/StrictWeakOrdering.html">Strict Weak Ordering</a>.
1823
* \pre The ranges <tt>[first,last)</tt> and <tt>[result, result + (last - first))</tt> shall not overlap.
1825
* The following code snippet demonstrates how to use \p binary_search
1826
* to search for multiple values in a ordered range.
1829
* #include <thrust/binary_search.h>
1830
* #include <thrust/device_vector.h>
1831
* #include <thrust/functional.h>
1833
* thrust::device_vector<int> input(5);
1841
* thrust::device_vector<int> values(6);
1849
* thrust::device_vector<bool> output(6);
1851
* thrust::binary_search(input.begin(), input.end(),
1852
* values.begin(), values.end(),
1854
* thrust::less<T>());
1856
* // output is now [true, false, true, false, true, false]
1859
* \see http://www.sgi.com/tech/stl/binary_search.html
1860
* \see \p lower_bound
1861
* \see \p upper_bound
1862
* \see \p equal_range
1864
template <class ForwardIterator, class InputIterator, class OutputIterator, class StrictWeakOrdering>
1865
OutputIterator binary_search(ForwardIterator first,
1866
ForwardIterator last,
1867
InputIterator values_first,
1868
InputIterator values_last,
1869
OutputIterator result,
1870
StrictWeakOrdering comp);
900
1873
/*! \} // end vectorized_binary_search
903
1877
/*! \} // end binary_search
906
1881
/*! \} // end searching
909
1885
} // end namespace thrust
911
1887
#include <thrust/detail/binary_search.inl>