本文整理汇总了C++中Obj::computeHash方法的典型用法代码示例。如果您正苦于以下问题:C++ Obj::computeHash方法的具体用法?C++ Obj::computeHash怎么用?C++ Obj::computeHash使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Obj
的用法示例。
在下文中一共展示了Obj::computeHash方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
case 4: {
// --------------------------------------------------------------------
// TESTING 'result_type' TYPEDEF
// Verify that the class offers the result_type typedef that needs to
// be exposed by all 'bslh' hashing algorithms
//
// Concerns:
//: 1 The typedef 'result_type' is publicly accessible and an alias for
//: 'bsls::Types::Uint64'.
//:
//: 2 'computeHash()' returns 'result_type'
//
// Plan:
//: 1 ASSERT the typedef is accessible and is the correct type using
//: 'bslmf::IsSame'. (C-1)
//:
//: 2 Declare the expected signature of 'computeHash()' and then assign
//: to it. If it compiles, the test passes. (C-2)
//
// Testing:
// typedef bsls::Types::Uint64 result_type;
// --------------------------------------------------------------------
if (verbose) printf("\nTESTING 'result_type' TYPEDEF"
"\n=============================\n");
if (verbose) printf("ASSERT the typedef is accessible and is the"
" correct type using 'bslmf::IsSame'. (C-1)\n");
{
ASSERT((bslmf::IsSame<bsls::Types::Uint64,
Obj::result_type>::VALUE));
}
if (verbose) printf("Declare the expected signature of 'computeHash()'"
" and then assign to it. If it compiles, the test"
" passes. (C-2)\n");
{
Obj::result_type (Obj::*expectedSignature) ();
expectedSignature = &Obj::computeHash;
(void)expectedSignature;
}
} break;
case 3: {
// --------------------------------------------------------------------
// TESTING TESTING 'operator()' AND 'computeHash()'
// Verify the class provides an overload for the function call
// operator that can be called with some bytes and a length. Verify
// that calling 'operator()' will permute the algorithm's internal
// state as specified by SpookyHash. Verify that 'computeHash()'
// returns the final value specified by the canonical spooky hash
// implementation.
//
// Concerns:
//: 1 The function call operator is callable.
//:
//: 2 Given the same bytes, the function call operator will permute the
//: internal state of the algorithm in the same way, regardless of
//: whether the bytes are passed in all at once or in pieces.
//:
//: 3 Byte sequences passed in to 'operator()' with a length of 0 will
//: not contribute to the final hash
//:
//: 4 'computeHash()' and returns the appropriate value
//: according to the SpookyHash specification.
示例2: main
int main(int argc, char *argv[])
{
int test = argc > 1 ? atoi(argv[1]) : 0;
bool verbose = argc > 2;
bool veryVerbose = argc > 3;
bool veryVeryVerbose = argc > 4;
// bool veryVeryVeryVerbose = argc > 5;
printf("TEST " __FILE__ " CASE %d\n", test);
switch (test) { case 0:
case 5: {
// --------------------------------------------------------------------
// USAGE EXAMPLE
// The hashing algorithm can be used to create more powerful
// components such as functors that can be used to power hash tables.
//
// Concerns:
//: 1 The usage example provided in the component header file compiles,
//: links, and runs as shown.
//
// Plan:
//: 1 Incorporate usage example from header into test driver (C-1)
//
// Testing:
// USAGE EXAMPLE
// --------------------------------------------------------------------
if (verbose) printf("USAGE EXAMPLE\n"
"=============\n");
// Then, we want to actually use our hash table on 'Future' objects. We
// create an array of 'Future's based on data that was originally from some
// external source:
Future futures[] = { Future("Swiss Franc", 'F', 2014),
Future("US Dollar", 'G', 2015),
Future("Canadian Dollar", 'Z', 2014),
Future("British Pound", 'M', 2015),
Future("Deutsche Mark", 'X', 2016),
Future("Eurodollar", 'Q', 2017)};
enum { NUM_FUTURES = sizeof futures / sizeof *futures };
// Next, we create our HashTable 'hashTable'. We pass the functor that we
// defined above as the second argument:
HashTable<Future, HashFuture> hashTable(futures, NUM_FUTURES);
// Now, we verify that each element in our array registers with count:
for ( int i = 0; i < 6; ++i) {
ASSERT(hashTable.contains(futures[i]));
}
// Finally, we verify that futures not in our original array are correctly
// identified as not being in the set:
ASSERT(!hashTable.contains(Future("French Franc", 'N', 2019)));
ASSERT(!hashTable.contains(Future("Swiss Franc", 'X', 2014)));
ASSERT(!hashTable.contains(Future("US Dollar", 'F', 2014)));
} break;
case 4: {
// --------------------------------------------------------------------
// TESTING 'result_type' TYPEDEF
// Verify that the class offers the result_type typedef that needs to
// be exposed by all 'bslh' hashing algorithms
//
// Concerns:
//: 1 The typedef 'result_type' is publicly accessible and an alias for
//: 'bslh::SpookyHashAlgorithm::result_type'.
//:
//: 2 'computeHash()' returns 'result_type'
//
// Plan:
//: 1 ASSERT the typedef is accessible and is the correct type using
//: 'bslmf::IsSame'. (C-1)
//:
//: 2 Declare the expected signature of 'computeHash()' and then assign
//: to it. If it compiles, the test passes. (C-2)
//
// Testing:
// typedef InternalHashAlgorithm::result_type result_type;
// --------------------------------------------------------------------
if (verbose) printf("\nTESTING 'result_type' TYPEDEF"
"\n=============================\n");
if (verbose) printf("ASSERT the typedef is accessible and is the"
" correct type using 'bslmf::IsSame'. (C-1)\n");
{
ASSERT((bslmf::IsSame<Obj::result_type,
SpookyHashAlgorithm::result_type>::VALUE));
}
if (verbose) printf("Declare the expected signature of 'computeHash()'"
" and then assign to it. If it compiles, the test"
" passes. (C-2)\n");
{
Obj::result_type (Obj::*expectedSignature) ();
//.........这里部分代码省略.........