本文整理汇总了C++中HashTable::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ HashTable::clear方法的具体用法?C++ HashTable::clear怎么用?C++ HashTable::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HashTable
的用法示例。
在下文中一共展示了HashTable::clear方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: canSubmit
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;
}
示例2: collisionTest
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);
}
示例3: dumpEngineDocs
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;
}
示例4: update
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;
};
示例5: clear
PosibErr<void> clear() {lookup_.clear(); buffer_.reset(); return no_err;}