File: boostjson.h

package info (click to toggle)
simdjson 4.2.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 27,936 kB
  • sloc: cpp: 171,612; ansic: 19,122; sh: 1,126; python: 842; makefile: 47; ruby: 25; javascript: 13
file content (37 lines) | stat: -rw-r--r-- 1,005 bytes parent folder | download | duplicates (2)
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
28
29
30
31
32
33
34
35
36
37
#pragma once

#if SIMDJSON_COMPETITION_BOOSTJSON

#include "top_tweet.h"

namespace top_tweet {

using namespace simdjson;

struct boostjson {
  using StringType=std::string;

  bool run(simdjson::padded_string &json, int64_t max_retweet_count, top_tweet_result<StringType> &result) {
    result.retweet_count = -1;
    boost::json::value top_tweet{};

    auto root = boost::json::parse(json);
    for (const auto &tweet : root.at("statuses").as_array()) {
      int64_t retweet_count = tweet.at("retweet_count").as_int64();
      if (retweet_count <= max_retweet_count && retweet_count >= result.retweet_count) {
        result.retweet_count = retweet_count;
        top_tweet = tweet;
      }
    }

    result.text = top_tweet.at("text").as_string();
    result.screen_name = top_tweet.at("user").at("screen_name").as_string();
    return result.retweet_count != -1;
  }
};

BENCHMARK_TEMPLATE(top_tweet, boostjson)->UseManualTime();

} // namespace top_tweet

#endif // SIMDJSON_COMPETITION_BOOSTJSON