MCPcopy Create free account
hub / github.com/danielaparker/jsoncons / query_json_lines_in_parallel

Function query_json_lines_in_parallel

examples/src/jmespath_examples.cpp:134–163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

132#include <concurrent_vector.h> // microsoft PPL library
133
134void query_json_lines_in_parallel()
135{
136
137 std::vector<std::string> lines = { {
138 R"({"name": "Seattle", "state" : "WA"})",
139 R"({ "name": "New York", "state" : "NY" })",
140 R"({ "name": "Bellevue", "state" : "WA" })",
141 R"({ "name": "Olympia", "state" : "WA" })"
142} };
143
144 auto expr = jsoncons::jmespath::make_expression<jsoncons::json>(
145 R"([@][?state=='WA'].name)");
146
147 concurrency::concurrent_vector<std::string> result;
148
149 auto f = [&](const std::string& line)
150 {
151 const auto j = jsoncons::json::parse(line);
152 const auto r = expr.evaluate(j);
153 if (!r.empty())
154 result.push_back(r.at(0).as<std::string>());
155 };
156
157 std::for_each(std::execution::par, lines.begin(), lines.end(), f);
158
159 for (const auto& s : result)
160 {
161 std::cout << s << "\n";
162 }
163}
164
165#endif
166

Callers 1

mainFunction · 0.85

Calls 7

parseFunction · 0.85
atMethod · 0.80
evaluateMethod · 0.45
emptyMethod · 0.45
push_backMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected