本文整理汇总了C++中HashTable::capacity方法的典型用法代码示例。如果您正苦于以下问题:C++ HashTable::capacity方法的具体用法?C++ HashTable::capacity怎么用?C++ HashTable::capacity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HashTable
的用法示例。
在下文中一共展示了HashTable::capacity方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
HashTable ht;
ht_elem pe;
string str = "abcdef";
const char* cstr = str.c_str();
string str1 = "1233";
const char* cstr1 = str1.c_str();
string str3 = "abcdef";
const char* cstr3 = str3.c_str();
string str4 = "str4~";
const char* cstr4 = str4.c_str();
pe.key = (void*)cstr;
pe.data = (void*)cstr1;
cout << "Before insert, Hash Table Size: " << ht.capacity() << endl;
ht.insert(pe);
pe.key = (void*)cstr4;
ht.insert(pe);
cout << "After insert, Hash Table Size: " << ht.capacity() << endl;
ht_data p = ht.search((void*)cstr3);
cout << "HashTable::search: " << (char*)(p) << endl;
ht.remove(pe.key);
cout << "After remove, Hash Table Size: " << ht.capacity() << '\n'
<< " number of elements : " << ht.size() << endl;
// ht.insert(pe);
if( ! ht.search(pe.key) )
cout << "Delete Key: " << (char*) pe.key << endl;
return 0;
}
示例2: Stream
TEST(HashTableTest, NonTrivialValueType) {
HashTable<FooBar> Table;
uint32_t Cap = Table.capacity();
for (uint32_t I = 0; I < Cap; ++I) {
FooBar F;
F.X = I;
F.Y = I + 1;
Table.set_as(utostr(I), F);
}
std::vector<uint8_t> Buffer(Table.calculateSerializedLength());
MutableBinaryByteStream Stream(Buffer, little);
BinaryStreamWriter Writer(Stream);
EXPECT_THAT_ERROR(Table.commit(Writer), Succeeded());
// We should have written precisely the number of bytes we calculated earlier.
EXPECT_EQ(Buffer.size(), Writer.getOffset());
HashTable<FooBar> Table2;
BinaryStreamReader Reader(Stream);
EXPECT_THAT_ERROR(Table2.load(Reader), Succeeded());
// We should have read precisely the number of bytes we calculated earlier.
EXPECT_EQ(Buffer.size(), Reader.getOffset());
EXPECT_EQ(Table.size(), Table2.size());
EXPECT_EQ(Table.capacity(), Table2.capacity());
// EXPECT_EQ(Table.Buckets, Table2.Buckets);
// EXPECT_EQ(Table.Present, Table2.Present);
// EXPECT_EQ(Table.Deleted, Table2.Deleted);
}
示例3: dumpHashTable
void dumpHashTable(const HashTable<T> &ht) {
psln(ht.size());
psln(ht.capacity());
}
示例4: main
int main()
{
// print my name and this assignment's title
cout << "LAB 10: Write, Test, and Apply The HashTable Class Template\n";
cout << "Programmer: Jacky Chow\n";
cout << "Editor(s) used: Notepad++\n";
cout << "Compiler(s) used: Visual C++\n";
cout << "File: " << __FILE__ << endl;
cout << "Complied: " << __DATE__ << " at " << __TIME__ << endl << endl;
int n = 100;
int arraySize;
HashTable<string, TermSection, 1009> a(hashCode);
cout << "Created HashTable<string, TermSection, 1009> a(hashCode)\n";
cout << "a.capacity returns: " << a.capacity() << endl;
assert(807 == a.capacity());
cout << "Size should be 0. a.size returns: " << a.size() << endl << endl;
assert(0 == a.size());
char* token;
char buf[1000];
const char* const tab = "\t";
int counter = 0;
ifstream fin;
fin.open("dvc-schedule.txt");
if (!fin.good()) throw "I/O error";
while (fin.good())
{
//progress bar
if(counter == n) break;
// read the line
string line;
getline(fin, line);
strcpy(buf, line.c_str());
if (buf[0] == 0) continue;
// parse the line
const string term(token = strtok(buf, tab));
const string section(token = strtok(0, tab));
const string course((token = strtok(0, tab)) ? token : "");
const string instructor((token = strtok(0, tab)) ? token : "");
const string whenWhere((token = strtok(0, tab)) ? token : "");
if (course.find('-') == string::npos) continue; // invalid line
const string subjectCode(course.begin(), course.begin() + course.find('-'));
counter++;
TermSection x = {term, section};
a[x] = course;
}
fin.close();
vector<TermSection> k = a.keys();
cout << "Capacity of a should now be 807. a.capacity returns: " << a.capacity() << endl;
assert(807 == a.capacity());
cout << "Size should also be 99. a.size returns: " << a.size() << endl;
assert(99 == a.size());
cout << "keys vector size should be equal to a.size: " << k.size() << endl;
arraySize = k.size();
assert(arraySize == a.size());
counter = 0;
// object copy testing
{
const HashTable<string, TermSection, 1009> copy = a;
cout << endl;
k = copy.keys();
cout << "Capacity of copy1 should be 807. copy.capacity returns: " << copy.capacity() << endl;
assert(807 == copy.capacity());
cout << "Size of copy1 should also be 99. copy.size returns: " << copy.size() << endl;
assert(99 == copy.size());
cout << "keys vector size of copy1 should be equal to copy.size: " << k.size() << endl;
arraySize = k.size();
assert(arraySize == copy.size());
cout << "Printing out course from copy1 using element 4 in vector k: " << copy[k[4]] << endl;
cout << "Now testing that copy.containsKey() will return true with that parameter.\n";
if(copy.containsKey(k[4])) cout << "copy.containsKey(k[4]) returned True.\n";
else cout << "Error! a.containsKey(k[4]) returned False.\n";
assert(copy.containsKey(k[4]));
TermSection y = {"Horch 2036", "9999"};
cout << "Printing out course with fake y parameter(should be a dummy): " << copy[y] << endl;
cout << "Now testing that copy.containsKey() will return false with fake y parameter.\n";
if(!copy.containsKey(y)) cout << "copy.containsKey(y) returned False.\n";
else cout << "Error! copy.containsKey(y) returned True.\n";
assert(!copy.containsKey(y));
}
// object assignment testing
{
cout << endl;
HashTable<string, TermSection, 1009> copy(hashCode);
cout << "Created copy 2 with a capacity 807.\nIt returns " << copy.capacity() << endl;
assert(807 == copy.capacity());
cout << "Copy 2 should have a size of 0. It returns: " << copy.size() << endl;
cout << "Assigning copy 2 to equal a.\n";
copy = a;
k = copy.keys();
cout << "Capacity of copy2 should now be 160. copy.capacity returns: " << copy.capacity() << endl;
assert(807 == copy.capacity());
//.........这里部分代码省略.........