bool canSubmit ( unsigned long h , long now , long maxAddUrlsPerIpDomPerDay ) { // . sometimes no limit // . 0 means no limit because if they don't want any submission they // can just turn off add url and we want to avoid excess // troubleshooting for why a url can't be added if ( maxAddUrlsPerIpDomPerDay <= 0 ) return true; // init the table if ( ! s_init ) { s_htable.set ( 50000 ); s_init = true; } // clean out table every 24 hours if ( now - s_lastTime > 24*60*60 ) { s_lastTime = now; s_htable.clear(); } // . if table almost full clean out ALL slots // . TODO: just clean out oldest slots if ( s_htable.getNumSlotsUsed() > 47000 ) s_htable.clear (); // . how many times has this IP domain submitted? // . allow 10 times per day long n = s_htable.getValue ( h ); // if over 24hr limit then bail if ( n >= maxAddUrlsPerIpDomPerDay ) return false; // otherwise, inc it n++; // add to table, will replace old values s_htable.addKey ( h , n ); return true; }
void collisionTest() { printf("test collision add/remove\n"); HashTable<int,collisionHash,intEqual> collisiontable; for(int i=0;i<100;i++) { collisiontable.add(i); } for(int i=0;i<100;i+=2) { collisiontable.remove(i); size_t count = 0; for (HashTable<int,collisionHash,intEqual>::iterator i = collisiontable.begin(); i != collisiontable.end();i++) { count++; } INVARIANT(count == collisiontable.size(), boost::format("?! %d %d") % count % collisiontable.size()); } // multiple adds of the same key are *supposed* to add multiple times. collisiontable.clear(); SINVARIANT(collisiontable.size() == 0); for(int i=0;i<100;i++) { collisiontable.add(i); collisiontable.add(i); } SINVARIANT(collisiontable.size() == 200); // remove the keys (each twice) for(int i=0;i<100;i++) { collisiontable.remove(i, true); collisiontable.remove(i, true); } SINVARIANT(collisiontable.size() == 0); // an efficient way to do add/replace collisiontable.clear(); SINVARIANT(collisiontable.size() == 0); for(int i=0;i<100;i++) { bool replaced; collisiontable.addOrReplace(i, replaced); SINVARIANT(replaced == false); collisiontable.addOrReplace(i, replaced); SINVARIANT(replaced == true); } SINVARIANT(collisiontable.size() == 100); // remove, add, remove the keys for(int i=0;i<100;i++) { collisiontable.remove(i, true); collisiontable.add(i); collisiontable.remove(i); } SINVARIANT(collisiontable.size() == 0); }
static bool dumpEngineDocs( const char *outputFile ) { // Create the output stream. FileStream stream; if ( !stream.open( outputFile, Torque::FS::File::Write ) ) { Con::errorf( "dumpEngineDocs - Failed to open output file." ); return false; } // First dump all global ConsoleDoc fragments. for( ConsoleDocFragment* fragment = ConsoleDocFragment::smFirst; fragment != NULL; fragment = fragment->mNext ) if( !fragment->mClass ) dumpFragment( stream, fragment ); // Clear the doc groups before continuing, smDocGroups.clear(); // Dump enumeration types. dumpEnums( stream ); // Dump all global variables. dumpVariables( stream ); // Now dump the global functions. Namespace *g = Namespace::find( NULL ); while( g ) { dumpNamespaceEntries( stream, g ); // Dump callbacks. dumpGroupStart( stream, "Callbacks" ); dumpNamespaceEntries( stream, g, true ); dumpGroupEnd( stream ); g = g->mParent; } // Now dump all the classes. dumpClasses( stream ); // Dump pre-declarations for any groups we encountered // so that we don't have to explicitly define them. HashTable<String,U32>::Iterator iter = smDocGroups.begin(); for ( ; iter != smDocGroups.end(); iter++ ) stream.writeText( String::ToString( "/*! @addtogroup %s */\r\n\r\n", iter->key.c_str() ) ); return true; }
void update() { cell temp = { 1 }; newGrid.clear(); for (temp.row = MINROW; temp.row <= MAXROW; temp.row++) for (temp.column = MINCOLUMN; temp.column <= MAXCOLUMN; temp.column++) switch (neighborCount(temp.row, temp.column)) { case 2: if (grid.retrieve(temp)) newGrid.insert(temp); break; case 3: newGrid.insert(temp); break; } grid = newGrid; };
void display_stats() { int i; // display HostStatistics printf("%-15.15s %9.9s %9.9s %9.9s %9.9s %9.9s %7.7s %6.6s\n", "Host/Job", "Wall Time", "Good Time", "CPU Usage", "Avg Alloc", "Avg Lost", "Goodput", "Util."); printf("\n"); HostStatistics *hs; HStats.startIterations(); while (HStats.iterate(hs) == 1) { printf("%-15.15s ", hs->host); printf("%9.9s ", format_time_nosecs(hs->wall_time)); printf("%9.9s ", format_time_nosecs(hs->good_time)); printf("%9.9s ", format_time_nosecs(hs->cpu_usage)); printf("%9.9s ", format_time_nosecs(hs->wall_time/hs->allocations)); printf("%9.9s ", hs->kills ? format_time_nosecs((hs->wall_time-hs->good_time)/hs->kills) : "0+00:00"); printf("%6.1f%% %5.1f%%\n", hs->wall_time ? float(hs->good_time)/float(hs->wall_time)*100 : 0.0, hs->good_time ? float(hs->cpu_usage)/float(hs->good_time)*100 : 0.0); delete hs; } HStats.clear(); printf("\n"); // display JobStatistics JobStatistics **statarray = new JobStatistics* [numJobStats]; JobStatistics *js; Stats.startIterations(); for (i=0; Stats.iterate(js) == 1; i++) { statarray[i] = js; } qsort(statarray, numJobStats, sizeof(JobStatistics *), statsort); int allocations=0, kills=0; int wall_time=0, good_time=0, cpu_usage=0; char job[40]; for (i=0; i < numJobStats; i++) { js = statarray[i]; sprintf(job, "%d.%d", js->cluster, js->proc); printf("%-15.15s ", job); printf("%9.9s ", format_time_nosecs(js->wall_time)); printf("%9.9s ", format_time_nosecs(js->good_time)); printf("%9.9s ", format_time_nosecs(js->cpu_usage)); printf("%9.9s ", format_time_nosecs(js->wall_time/js->allocations)); printf("%9.9s ", js->kills ? format_time_nosecs((js->wall_time-js->good_time)/js->kills) : "0+00:00"); printf("%6.1f%% %5.1f%%\n", js->wall_time ? float(js->good_time)/float(js->wall_time)*100 : 0.0, js->good_time ? float(js->cpu_usage)/float(js->good_time)*100 : 0.0); allocations += js->allocations; kills += js->kills; wall_time += js->wall_time; good_time += js->good_time; cpu_usage += js->cpu_usage; delete js; } printf("\n"); printf("%-15.15s ", "Total"); printf("%9.9s ", format_time_nosecs(wall_time)); printf("%9.9s ", format_time_nosecs(good_time)); printf("%9.9s ", format_time_nosecs(cpu_usage)); printf("%9.9s ", allocations ? format_time_nosecs(wall_time/allocations) : "0+00:00"); printf("%9.9s ", kills ? format_time_nosecs((wall_time-good_time)/kills) : "0+00:00"); printf("%6.1f%% %5.1f%%\n", wall_time ? float(good_time)/float(wall_time)*100 : 0.0, good_time ? float(cpu_usage)/float(good_time)*100 : 0.0); Stats.clear(); delete [] statarray; }
PosibErr<void> clear() {lookup_.clear(); buffer_.reset(); return no_err;}