forked from cmuparlay/parlaylib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilter.cpp
27 lines (23 loc) · 798 Bytes
/
filter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <string>
#include <parlay/primitives.h>
#include <parlay/sequence.h>
// **************************************************************
// Driver code
// **************************************************************
int main(int argc, char* argv[]) {
auto usage = "Usage: filter <n>";
if (argc != 2) std::cout << usage << std::endl;
else {
long n;
try { n = std::stol(argv[1]); }
catch (...) { std::cout << usage << std::endl; return 1; }
parlay::internal::timer t("Time");
parlay::sequence<long> result;
for (int i=0; i < 5; i++) {
result = filter(parlay::iota<long>(n+1), [] (long i) { return i%2 == 0; });
t.next("filter");
}
std::cout << "number of even integers up to n: " << result.size() << std::endl;
}
}