tests/hashtable_unittests.cc
TEST(HashtableCommonTest, HashMunging) {
  const Hasher hasher;

  // We don't munge the hash value on non-pointer template types.
  {
    const sparsehash_internal::sh_hashtable_settings<int, Hasher, size_t, 1>
        settings(hasher, 0.0, 0.0);
    const int v = 1000;
    EXPECT_EQ(hasher(v), settings.hash(v));
  }

  {
    // We do munge the hash value on pointer template types.
    const sparsehash_internal::sh_hashtable_settings<int*, Hasher, size_t, 1>
        settings(hasher, 0.0, 0.0);
    int* v = NULL;
    v += 0x10000;  // get a non-trivial pointer value
    EXPECT_NE(hasher(v), settings.hash(v));
  }
  {
    const sparsehash_internal::sh_hashtable_settings<const int*, Hasher, size_t,
                                                     1> settings(hasher, 0.0,
                                                                 0.0);
    const int* v = NULL;
    v += 0x10000;  // get a non-trivial pointer value
    EXPECT_NE(hasher(v), settings.hash(v));
  }
}
// ------------------------------------------------------------------------
// First, some testing of the underlying infrastructure.
First, some testing of the underlying infrastructure.
First some testing of the underlying infrastructure .
TEST(HashtableCommonTest, HashMunging) {
  const Hasher hasher;
  {
    const sparsehash_internal::sh_hashtable_settings<int, Hasher, size_t, 1>
        settings(hasher, 0.0, 0.0);
    const int v = 1000;
    EXPECT_EQ(hasher(v), settings.hash(v));
  }
  {
    const sparsehash_internal::sh_hashtable_settings<int*, Hasher, size_t, 1>
        settings(hasher, 0.0, 0.0);
    int* v = NULL;
    v += 0x10000;  
    EXPECT_NE(hasher(v), settings.hash(v));
  }
  {
    const sparsehash_internal::sh_hashtable_settings<const int*, Hasher, size_t,
                                                     1> settings(hasher, 0.0,
                                                                 0.0);
    const int* v = NULL;
    v += 0x10000;  
    EXPECT_NE(hasher(v), settings.hash(v));
  }
}
TEST ( HashtableCommonTest , HashMunging ) { const Hasher hasher ; { const sparsehash_internal :: sh_hashtable_settings < int , Hasher , size_t , 1 > settings ( hasher , 0.0 , 0.0 ) ; const int v = 1000 ; EXPECT_EQ ( hasher ( v ) , settings . hash ( v ) ) ; } { const sparsehash_internal :: sh_hashtable_settings < int * , Hasher , size_t , 1 > settings ( hasher , 0.0 , 0.0 ) ; int * v = NULL ; v += 0x10000 ; EXPECT_NE ( hasher ( v ) , settings . hash ( v ) ) ; } { const sparsehash_internal :: sh_hashtable_settings < const int * , Hasher , size_t , 1 > settings ( hasher , 0.0 , 0.0 ) ; const int * v = NULL ; v += 0x10000 ; EXPECT_NE ( hasher ( v ) , settings . hash ( v ) ) ; } }
First, some testing of the underlying infrastructure.
First some testing of the underlying infrastructure .
// We don't munge the hash value on non-pointer template types. // We do munge the hash value on pointer template types. // get a non-trivial pointer value // get a non-trivial pointer value