File: simdjson_dom.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 (39 lines) | stat: -rw-r--r-- 937 bytes parent folder | download | duplicates (3)
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
38
39
#pragma once

#if SIMDJSON_EXCEPTIONS

#include "top_tweet.h"

namespace top_tweet {

using namespace simdjson;

struct simdjson_dom {
  using StringType=std::string_view;

  dom::parser parser{};

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

    auto doc = parser.parse(json);
    for (auto tweet : doc["statuses"]) {
      int64_t retweet_count = tweet["retweet_count"];
      if (retweet_count <= max_retweet_count && retweet_count >= result.retweet_count) {
        result.retweet_count = retweet_count;
        top_tweet = tweet;
      }
    }

    result.text = top_tweet["text"];
    result.screen_name = top_tweet["user"]["screen_name"];
    return result.retweet_count != -1;
  }
};

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

} // namespace top_tweet

#endif // SIMDJSON_EXCEPTIONS