SEXP _plot_overlap(SEXP e, SEXP c, SEXP full) { // Load data and sort int n = nrows(e); bool full_bool = *LOGICAL(full); Endpoints ep ( REAL(e), LOGICAL(c), n, false, full_bool ); // Set sorting order, then sort Endpoint::set_state_array( reduce_order ); sort( ep.begin(), ep.end() ); // Process int i; int active_count = 0; std::set<int> free_interior; std::vector<int> y (n); Endpoints::const_iterator it; // Initialize to NA for ( i = 0; i < n; i++ ) y[i] = R_NaInt; for ( it = ep.begin(); it < ep.end(); it++ ) { if ( it->left ) { // Opening an interval if ( free_interior.size() > 0 ) { y[ it->index ] = *free_interior.begin(); free_interior.erase( free_interior.begin() ); } else y[ it->index ] = active_count; active_count++; } else{ // Closing an interval active_count--; if ( y[ it->index ] < active_count + free_interior.size() ) free_interior.insert( y[ it->index ] ); } } // Prepare and return result. SEXP result; PROTECT( result = allocVector( INTSXP, n ) ); copy( y.begin(), y.end(), std::vector<int>::iterator ( INTEGER( result ) ) ); UNPROTECT(1); return( result ); }
void Discovery::HandleMessage() { std::istream r(&message_); std::string line; r >> line; //skip version r >> line; //code if(line != "200") { std::string comment; std::getline(r, comment); throw std::runtime_error("Bad reply code: " + line + " " + comment); } while(std::getline(r, line) && line != "\r") /* =) */ ; typedef std::map<Ip::Endpoint, uint> Endpoints; typedef std::map<std::string, uint> WebCaches; Endpoints hubs; WebCaches webcaches; bool g2support = false; uint32 period = 0; while(std::getline(r, line)) { boost::replace_all(line, "|", " "); std::stringstream s(line); char prefix; s >> prefix; switch(prefix) { case 'I': case'i': { std::string tag; std::string val; if(s >> tag >> val) { if(boost::iequals(tag, "support") && boost::iequals(val, "gnutella2")) g2support = true; else if(boost::iequals(tag, "access") && boost::iequals(val, "period")) s >> period; } break; } case 'H': case 'h': { std::string address; std::time_t seen = 0; if(s >> address) { s >> seen; seen = seen <= System::Now() ? seen : System::Now(); Ip::Endpoint ep; if(ep.FromString(address)) hubs[ep] = System::Since(seen); } break; } case 'U': case 'u': { std::string address; uint seen = 0; if(s >> address) { s >> seen; webcaches[address] = System::Now() - seen; } } } } if(g2support) { System::LogBas() << "Discovered " << hubs.size() << " hub(s) and " << webcaches.size() << " web cache(s)" << std::endl; for(Endpoints::iterator i = hubs.begin(); i != hubs.end(); ++i) System::GetHubCache()->Touch(i->first, i->second); for(WebCaches::iterator i = webcaches.begin(); i != webcaches.end(); ++i) AddCache(i->first); } else caches_[address_].banned = true; }