本文整理汇总了C++中Hashtable::ShrinkToFit方法的典型用法代码示例。如果您正苦于以下问题:C++ Hashtable::ShrinkToFit方法的具体用法?C++ Hashtable::ShrinkToFit怎么用?C++ Hashtable::ShrinkToFit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hashtable
的用法示例。
在下文中一共展示了Hashtable::ShrinkToFit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
// This program exercises the Hashtable class.
int main(int argc, char ** argv)
{
CompleteSetupSystem css;
Message temp; if (ParseArgs(argc, argv, temp) == B_NO_ERROR) HandleStandardDaemonArgs(temp);
if (temp.HasName("inter")) return DoInteractiveTest();
// Make sure that setting equal to an empty Hashtable clears the buffer (FogBugz #10274)
{
Hashtable<String,String> table;
for (int32 i=0; i<1000; i++) table.Put(String("xxx%1").Arg(i), "foo");
printf("After population of " UINT32_FORMAT_SPEC " items, table size is " UINT32_FORMAT_SPEC "\n", table.GetNumItems(), table.GetNumAllocatedItemSlots());
if (table.ShrinkToFit() == B_NO_ERROR) printf("After shrink-to-fit, table allocation is " UINT32_FORMAT_SPEC " for " UINT32_FORMAT_SPEC " items\n", table.GetNumAllocatedItemSlots(), table.GetNumItems());
else printf("Shrink-to-fit failed!?\n");
printf("Before copy-from-empty, table allocation is " UINT32_FORMAT_SPEC "\n", table.GetNumAllocatedItemSlots());
table = GetDefaultObjectForType< Hashtable<String,String> > ();
printf(" After copy-from-empty, table allocation is " UINT32_FORMAT_SPEC "\n", table.GetNumAllocatedItemSlots());
}
// Test C++11 move semantics to make sure they aren't stealing
{
String key = "key";
String value = "value";
Hashtable<String,String> table;
table.Put(key, value);
if (key != "key") {printf("ERROR, Hashtable stole my key!\n"); exit(10);}
if (value != "value") {printf("ERROR, Hashtable stole my value!\n"); exit(10);}
}
// Test muscleSwap()
TestMuscleSwap<Hashtable<String,String> >("Hashtable");
TestMuscleSwap<OrderedKeysHashtable<String,String> >("OrderedKeysHashtable");
TestMuscleSwap<OrderedValuesHashtable<String,String> >("OrderedValuesHashtable");
// Test iterator behaviour when deleting keys
TestIteratorSanityOnRemoval(false);
TestIteratorSanityOnRemoval(true);
{
LogTime(MUSCLE_LOG_INFO, "Testing a keys-only Hashtable value...\n");
Hashtable<int, Void> keysOnly;
printf("sizeof(keysOnly)=%u\n", (unsigned int) sizeof(keysOnly));
keysOnly.PutWithDefault(1);
keysOnly.PutWithDefault(2);
keysOnly.PutWithDefault(5);
keysOnly.PutWithDefault(10);
for (HashtableIterator<int, Void> iter(keysOnly); iter.HasData(); iter++) printf("key=%i\n", iter.GetKey());
}
{
LogTime(MUSCLE_LOG_INFO, "Testing Tuple as a Hashtable key...\n");
// A quick test of the Tuple class as a Hashtable key
typedef Tuple<2,int> MyType;
Hashtable<MyType, int> tupleTable;
MyType a; a[0] = 5; a[1] = 6;
MyType b; b[0] = 7; b[1] = 8;
tupleTable.Put(a, 1);
tupleTable.Put(b, 2);
for (HashtableIterator<MyType, int> iter(tupleTable); iter.HasData(); iter++)
{
const MyType & key = iter.GetKey();
printf("key=%i,%i val=%i\n", key[0], key[1], iter.GetValue());
}
int * ra = tupleTable.Get(a);
int * rb = tupleTable.Get(b);
printf("tuple: ra=[%i] rb=[%i]\n", ra?*ra:666, rb?*rb:666);
}
{
LogTime(MUSCLE_LOG_INFO, "Testing Rect as a Hashtable key...\n");
// A quick test of the Tuple class as a Hashtable key
Hashtable<Rect, int> tupleTable;
Rect a(1,2,3,4);
Rect b(5,6,7,8);
tupleTable.Put(a, 1);
tupleTable.Put(b, 2);
for (HashtableIterator<Rect, int> iter(tupleTable); iter.HasData(); iter++)
{
const Rect & key = iter.GetKey();
printf("key=%f,%f,%f,%f val=%i\n", key.left(), key.top(), key.right(), key.bottom(), iter.GetValue());
}
int * ra = tupleTable.Get(a);
int * rb = tupleTable.Get(b);
printf("Rect: ra=[%p] rb=[%p]\n", ra, rb);
}
{
LogTime(MUSCLE_LOG_INFO, "Testing Point as a Hashtable key...\n");
// A quick test of the Tuple class as a Hashtable key
Hashtable<Point, int> tupleTable;
//.........这里部分代码省略.........