bitquill - Spiros Papadimitriou
Warning: Can't synchronize with the repository (Unsupported version control system "svn": "libdb3.so.3: cannot open shared object file: No such file or directory" ). Look in the Trac log for more information.

PCC/Start: histogram.cc

File histogram.cc, 0.8 kB (added by spapadim, 3 years ago)

Simple hand-coded histogram benchmark

Line 
1#include <iostream>
2#include <ext/hash_map>
3#include <boost/regex.hpp>
4
5using namespace std;
6using namespace __gnu_cxx;
7using namespace boost;
8
9namespace __gnu_cxx {
10    template<> struct hash< std::string > {
11        size_t operator()( const std::string& x ) const {
12            return hash< const char* >()( x.c_str() );
13        }
14    };
15}
16
17int main (int argc, char **argv) {
18    char *pattern = "(?:R|SP|AP)\\|SensorName=(.*?)\\|[lDBS]";
19    regex re(pattern);
20
21    hash_map<string,int> hist;
22
23    string line;
24    while (!cin.eof()) {
25        getline(cin, line);
26        smatch mat;
27        if (regex_search(line, mat, re)) {
28            ++hist[mat.str(1)];
29        }
30    }
31
32    for (hash_map<string,int>::const_iterator p = hist.begin(); p != hist.end();  p++) {
33        cout << p->first << "\t" << p->second << endl;
34    }
35
36    return 0;
37}