google_hash 0.8.1 → 0.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. data/ChangeLog.txt +2 -0
  2. data/VERSION +1 -1
  3. data/ext/clean.bat +0 -0
  4. data/ext/clean.sh +4 -0
  5. data/ext/extconf.rb +4 -5
  6. data/ext/go.bat +0 -0
  7. data/ext/sparsehash-2.0.2/AUTHORS +2 -0
  8. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/COPYING +0 -0
  9. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/ChangeLog +60 -0
  10. data/ext/sparsehash-2.0.2/INSTALL +365 -0
  11. data/ext/sparsehash-2.0.2/Makefile +1336 -0
  12. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/Makefile.am +97 -40
  13. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/Makefile.in +538 -256
  14. data/ext/sparsehash-2.0.2/NEWS +188 -0
  15. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/README +4 -10
  16. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/README_windows.txt +3 -3
  17. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/TODO +0 -0
  18. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/aclocal.m4 +266 -166
  19. data/ext/sparsehash-2.0.2/allocator.patch +31 -0
  20. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/config.guess +235 -234
  21. data/ext/sparsehash-2.0.2/config.status +1238 -0
  22. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/config.sub +198 -64
  23. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/configure +1118 -1000
  24. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/configure.ac +4 -5
  25. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/depcomp +136 -36
  26. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/doc/dense_hash_map.html +182 -67
  27. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/doc/dense_hash_set.html +173 -74
  28. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/doc/designstyle.css +0 -6
  29. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/doc/implementation.html +0 -0
  30. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/doc/index.html +4 -5
  31. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/doc/performance.html +1 -1
  32. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/doc/sparse_hash_map.html +190 -58
  33. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/doc/sparse_hash_set.html +180 -65
  34. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/doc/sparsetable.html +1 -1
  35. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/experimental/Makefile +0 -0
  36. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/experimental/README +0 -0
  37. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/experimental/example.c +1 -0
  38. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/experimental/libchash.c +1 -0
  39. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/experimental/libchash.h +1 -0
  40. data/ext/sparsehash-2.0.2/install-sh +520 -0
  41. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/m4/acx_pthread.m4 +34 -0
  42. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/m4/google_namespace.m4 +0 -0
  43. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/m4/namespaces.m4 +0 -0
  44. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/m4/stl_hash.m4 +0 -0
  45. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/m4/stl_hash_fun.m4 +0 -0
  46. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/missing +60 -44
  47. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/packages/deb.sh +0 -0
  48. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/packages/deb/README +0 -0
  49. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/packages/deb/changelog +42 -0
  50. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/packages/deb/compat +0 -0
  51. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/packages/deb/control +1 -1
  52. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/packages/deb/copyright +5 -4
  53. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/packages/deb/docs +0 -0
  54. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/packages/deb/rules +0 -0
  55. data/ext/sparsehash-2.0.2/packages/deb/sparsehash.dirs +5 -0
  56. data/ext/sparsehash-2.0.2/packages/deb/sparsehash.install +6 -0
  57. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/packages/rpm.sh +1 -1
  58. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/packages/rpm/rpm.spec +5 -3
  59. data/ext/{sparsehash-1.8.1/google-sparsehash.sln → sparsehash-2.0.2/sparsehash.sln} +0 -0
  60. data/ext/sparsehash-2.0.2/src/config.h +132 -0
  61. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/config.h.in +0 -3
  62. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/config.h.include +0 -1
  63. data/ext/sparsehash-2.0.2/src/google/dense_hash_map +34 -0
  64. data/ext/sparsehash-2.0.2/src/google/dense_hash_set +34 -0
  65. data/ext/sparsehash-2.0.2/src/google/sparse_hash_map +34 -0
  66. data/ext/sparsehash-2.0.2/src/google/sparse_hash_set +34 -0
  67. data/ext/sparsehash-2.0.2/src/google/sparsehash/densehashtable.h +34 -0
  68. data/ext/sparsehash-2.0.2/src/google/sparsehash/hashtable-common.h +34 -0
  69. data/ext/sparsehash-2.0.2/src/google/sparsehash/libc_allocator_with_realloc.h +34 -0
  70. data/ext/sparsehash-2.0.2/src/google/sparsehash/sparsehashtable.h +34 -0
  71. data/ext/sparsehash-2.0.2/src/google/sparsetable +34 -0
  72. data/ext/sparsehash-2.0.2/src/google/template_util.h +34 -0
  73. data/ext/sparsehash-2.0.2/src/google/type_traits.h +34 -0
  74. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/hash_test_interface.h +64 -37
  75. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/hashtable_test.cc +415 -141
  76. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/libc_allocator_with_realloc_test.cc +16 -23
  77. data/ext/sparsehash-2.0.2/src/simple_compat_test.cc +106 -0
  78. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/simple_test.cc +8 -5
  79. data/ext/{sparsehash-1.8.1/src/google → sparsehash-2.0.2/src/sparsehash}/dense_hash_map +80 -37
  80. data/ext/{sparsehash-1.8.1/src/google → sparsehash-2.0.2/src/sparsehash}/dense_hash_set +64 -34
  81. data/ext/{sparsehash-1.8.1/src/google/sparsehash → sparsehash-2.0.2/src/sparsehash/internal}/densehashtable.h +247 -173
  82. data/ext/sparsehash-2.0.2/src/sparsehash/internal/hashtable-common.h +381 -0
  83. data/ext/{sparsehash-1.8.1/src/google/sparsehash → sparsehash-2.0.2/src/sparsehash/internal}/libc_allocator_with_realloc.h +5 -7
  84. data/ext/{sparsehash-1.8.1/src/google/sparsehash → sparsehash-2.0.2/src/sparsehash/internal}/sparsehashtable.h +154 -93
  85. data/ext/{sparsehash-1.8.1/src/google → sparsehash-2.0.2/src/sparsehash}/sparse_hash_map +96 -36
  86. data/ext/{sparsehash-1.8.1/src/google → sparsehash-2.0.2/src/sparsehash}/sparse_hash_set +85 -32
  87. data/ext/{sparsehash-1.8.1/src/google → sparsehash-2.0.2/src/sparsehash}/sparsetable +520 -258
  88. data/ext/sparsehash-2.0.2/src/sparsehash/template_util.h +134 -0
  89. data/ext/{sparsehash-1.8.1/src/google → sparsehash-2.0.2/src/sparsehash}/type_traits.h +153 -35
  90. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/sparsetable_unittest.cc +108 -22
  91. data/ext/sparsehash-2.0.2/src/stamp-h1 +1 -0
  92. data/ext/sparsehash-2.0.2/src/template_util_unittest.cc +134 -0
  93. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/testutil.h +16 -1
  94. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/time_hash_map.cc +259 -94
  95. data/ext/sparsehash-2.0.2/src/type_traits_unittest.cc +636 -0
  96. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/windows/config.h +4 -4
  97. data/ext/sparsehash-2.0.2/src/windows/google/sparsehash/sparseconfig.h +49 -0
  98. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/windows/port.cc +1 -0
  99. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/windows/port.h +4 -13
  100. data/ext/sparsehash-2.0.2/src/windows/sparsehash/internal/sparseconfig.h +49 -0
  101. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/vsprojects/hashtable_test/hashtable_test.vcproj +11 -11
  102. data/ext/sparsehash-2.0.2/vsprojects/libc_allocator_with_realloc_test/libc_allocator_with_realloc_test.vcproj +161 -0
  103. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/vsprojects/simple_test/simple_test.vcproj +10 -10
  104. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/vsprojects/sparsetable_unittest/sparsetable_unittest.vcproj +4 -4
  105. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/vsprojects/time_hash_map/time_hash_map.vcproj +10 -10
  106. data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/vsprojects/type_traits_unittest/type_traits_unittest.vcproj +3 -3
  107. data/ext/spec.bat +0 -0
  108. data/ext/template/google_hash.cpp.erb +6 -5
  109. metadata +106 -86
  110. data/ext/sparsehash-1.8.1/AUTHORS +0 -2
  111. data/ext/sparsehash-1.8.1/INSTALL +0 -236
  112. data/ext/sparsehash-1.8.1/NEWS +0 -71
  113. data/ext/sparsehash-1.8.1/compile +0 -99
  114. data/ext/sparsehash-1.8.1/install-sh +0 -323
  115. data/ext/sparsehash-1.8.1/m4/stl_namespace.m4 +0 -25
  116. data/ext/sparsehash-1.8.1/mkinstalldirs +0 -158
  117. data/ext/sparsehash-1.8.1/packages/deb/sparsehash.dirs +0 -2
  118. data/ext/sparsehash-1.8.1/packages/deb/sparsehash.install +0 -2
  119. data/ext/sparsehash-1.8.1/src/google/sparsehash/hashtable-common.h +0 -178
  120. data/ext/sparsehash-1.8.1/src/type_traits_unittest.cc +0 -502
  121. data/ext/sparsehash-1.8.1/src/windows/google/sparsehash/sparseconfig.h +0 -32
@@ -1,10 +1,10 @@
1
1
  // Copyright (c) 2010, Google Inc.
2
2
  // All rights reserved.
3
- //
3
+ //
4
4
  // Redistribution and use in source and binary forms, with or without
5
5
  // modification, are permitted provided that the following conditions are
6
6
  // met:
7
- //
7
+ //
8
8
  // * Redistributions of source code must retain the above copyright
9
9
  // notice, this list of conditions and the following disclaimer.
10
10
  // * Redistributions in binary form must reproduce the above
@@ -14,7 +14,7 @@
14
14
  // * Neither the name of Google Inc. nor the names of its
15
15
  // contributors may be used to endorse or promote products derived from
16
16
  // this software without specific prior written permission.
17
- //
17
+ //
18
18
  // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
19
  // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
20
  // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@@ -28,16 +28,18 @@
28
28
  // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
29
 
30
30
  // ---
31
- // Author: Guilin Chen
32
31
 
33
- #include "config.h"
34
- #include <google/sparsehash/libc_allocator_with_realloc.h>
32
+ #include <sparsehash/internal/sparseconfig.h>
33
+ #include <config.h>
34
+ #include <sparsehash/internal/libc_allocator_with_realloc.h>
35
35
  #include <stdlib.h>
36
- #include <iostream>
37
36
  #include <string>
38
37
  #include <vector>
38
+ #include <iostream>
39
+ #include "testutil.h"
39
40
 
40
41
  using std::cerr;
42
+ using std::cout;
41
43
  using std::string;
42
44
  using std::basic_string;
43
45
  using std::char_traits;
@@ -46,14 +48,6 @@ using GOOGLE_NAMESPACE::libc_allocator_with_realloc;
46
48
 
47
49
  #define arraysize(a) ( sizeof(a) / sizeof(*(a)) )
48
50
 
49
- #define EXPECT_EQ(a, b) do { \
50
- if ((a) != (b)) { \
51
- cerr << "Check failed: EXPECTED: " << #a << " == " << #b << ", " \
52
- << "ACTUAL: " << a << " != " << b << "\n"; \
53
- exit(1); \
54
- } \
55
- } while (0)
56
-
57
51
  namespace {
58
52
 
59
53
  typedef libc_allocator_with_realloc<int> int_alloc;
@@ -64,8 +58,7 @@ typedef basic_string<char, char_traits<char>,
64
58
  libc_allocator_with_realloc<char> > cstring;
65
59
  typedef vector<cstring, libc_allocator_with_realloc<cstring> > cstring_vector;
66
60
 
67
-
68
- void TestAllocate() {
61
+ TEST(LibcAllocatorWithReallocTest, Allocate) {
69
62
  int_alloc alloc;
70
63
  intp_alloc palloc;
71
64
 
@@ -92,7 +85,7 @@ void TestAllocate() {
92
85
  alloc.deallocate(p, 1024);
93
86
  }
94
87
 
95
- void TestSTL() {
88
+ TEST(LibcAllocatorWithReallocTest, TestSTL) {
96
89
  // Test strings copied from base/arena_unittest.cc
97
90
  static const char* test_strings[] = {
98
91
  "aback", "abaft", "abandon", "abandoned", "abandoning",
@@ -120,10 +113,10 @@ void TestSTL() {
120
113
 
121
114
  } // namespace
122
115
 
123
- int main() {
124
- TestAllocate();
125
- TestSTL();
126
-
127
- cerr << "PASS\n";
116
+ int main(int, char **) {
117
+ // All the work is done in the static constructors. If they don't
118
+ // die, the tests have all passed.
119
+ cout << "PASS\n";
128
120
  return 0;
129
121
  }
122
+
@@ -0,0 +1,106 @@
1
+ // Copyright (c) 2007, Google Inc.
2
+ // All rights reserved.
3
+ //
4
+ // Redistribution and use in source and binary forms, with or without
5
+ // modification, are permitted provided that the following conditions are
6
+ // met:
7
+ //
8
+ // * Redistributions of source code must retain the above copyright
9
+ // notice, this list of conditions and the following disclaimer.
10
+ // * Redistributions in binary form must reproduce the above
11
+ // copyright notice, this list of conditions and the following disclaimer
12
+ // in the documentation and/or other materials provided with the
13
+ // distribution.
14
+ // * Neither the name of Google Inc. nor the names of its
15
+ // contributors may be used to endorse or promote products derived from
16
+ // this software without specific prior written permission.
17
+ //
18
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
+ // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
+ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21
+ // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22
+ // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24
+ // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25
+ // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26
+ // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27
+ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
+
30
+ // ---
31
+ //
32
+ // This tests mostly that we can #include the files correctly
33
+ // and have them work. It is like simple_test.cc but uses the
34
+ // compatibility #include directory (google/) rather than the
35
+ // canonical one (sparsehash/). This unittest purposefully does
36
+ // not #include <config.h>; it's meant to emulate what a 'regular
37
+ // install' of sparsehash would be able to see.
38
+
39
+ #include <stdio.h>
40
+ #include <google/sparse_hash_set>
41
+ #include <google/sparse_hash_map>
42
+ #include <google/dense_hash_set>
43
+ #include <google/dense_hash_map>
44
+ #include <google/template_util.h>
45
+ #include <google/type_traits.h>
46
+
47
+ #define CHECK_IFF(cond, when) do { \
48
+ if (when) { \
49
+ if (!(cond)) { \
50
+ puts("ERROR: " #cond " failed when " #when " is true\n"); \
51
+ exit(1); \
52
+ } \
53
+ } else { \
54
+ if (cond) { \
55
+ puts("ERROR: " #cond " succeeded when " #when " is false\n"); \
56
+ exit(1); \
57
+ } \
58
+ } \
59
+ } while (0)
60
+
61
+ int main(int argc, char**) {
62
+ // Run with an argument to get verbose output
63
+ const bool verbose = argc > 1;
64
+
65
+ google::sparse_hash_set<int> sset;
66
+ google::sparse_hash_map<int, int> smap;
67
+ google::dense_hash_set<int> dset;
68
+ google::dense_hash_map<int, int> dmap;
69
+ dset.set_empty_key(-1);
70
+ dmap.set_empty_key(-1);
71
+
72
+ for (int i = 0; i < 100; i += 10) { // go by tens
73
+ sset.insert(i);
74
+ smap[i] = i+1;
75
+ dset.insert(i + 5);
76
+ dmap[i+5] = i+6;
77
+ }
78
+
79
+ if (verbose) {
80
+ for (google::sparse_hash_set<int>::const_iterator it = sset.begin();
81
+ it != sset.end(); ++it)
82
+ printf("sset: %d\n", *it);
83
+ for (google::sparse_hash_map<int,int>::const_iterator it = smap.begin();
84
+ it != smap.end(); ++it)
85
+ printf("smap: %d -> %d\n", it->first, it->second);
86
+ for (google::dense_hash_set<int>::const_iterator it = dset.begin();
87
+ it != dset.end(); ++it)
88
+ printf("dset: %d\n", *it);
89
+ for (google::dense_hash_map<int,int>::const_iterator it = dmap.begin();
90
+ it != dmap.end(); ++it)
91
+ printf("dmap: %d -> %d\n", it->first, it->second);
92
+ }
93
+
94
+ for (int i = 0; i < 100; i++) {
95
+ CHECK_IFF(sset.find(i) != sset.end(), (i % 10) == 0);
96
+ CHECK_IFF(smap.find(i) != smap.end(), (i % 10) == 0);
97
+ CHECK_IFF(smap.find(i) != smap.end() && smap.find(i)->second == i+1,
98
+ (i % 10) == 0);
99
+ CHECK_IFF(dset.find(i) != dset.end(), (i % 10) == 5);
100
+ CHECK_IFF(dmap.find(i) != dmap.end(), (i % 10) == 5);
101
+ CHECK_IFF(dmap.find(i) != dmap.end() && dmap.find(i)->second == i+1,
102
+ (i % 10) == 5);
103
+ }
104
+ printf("PASS\n");
105
+ return 0;
106
+ }
@@ -28,18 +28,21 @@
28
28
  // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
29
 
30
30
  // ---
31
- // Author: Craig Silverstein
32
31
  //
33
32
  // This tests mostly that we can #include the files correctly
34
33
  // and have them work. This unittest purposefully does not
35
34
  // #include <config.h>; it's meant to emulate what a 'regular
36
35
  // install' of sparsehash would be able to see.
37
36
 
37
+ #include <sparsehash/internal/sparseconfig.h>
38
+ #include <config.h>
38
39
  #include <stdio.h>
39
- #include <google/sparse_hash_set>
40
- #include <google/sparse_hash_map>
41
- #include <google/dense_hash_set>
42
- #include <google/dense_hash_map>
40
+ #include <sparsehash/sparse_hash_set>
41
+ #include <sparsehash/sparse_hash_map>
42
+ #include <sparsehash/dense_hash_set>
43
+ #include <sparsehash/dense_hash_map>
44
+ #include <sparsehash/template_util.h>
45
+ #include <sparsehash/type_traits.h>
43
46
 
44
47
  #define CHECK_IFF(cond, when) do { \
45
48
  if (when) { \
@@ -1,10 +1,10 @@
1
1
  // Copyright (c) 2005, Google Inc.
2
2
  // All rights reserved.
3
- //
3
+ //
4
4
  // Redistribution and use in source and binary forms, with or without
5
5
  // modification, are permitted provided that the following conditions are
6
6
  // met:
7
- //
7
+ //
8
8
  // * Redistributions of source code must retain the above copyright
9
9
  // notice, this list of conditions and the following disclaimer.
10
10
  // * Redistributions in binary form must reproduce the above
@@ -14,7 +14,7 @@
14
14
  // * Neither the name of Google Inc. nor the names of its
15
15
  // contributors may be used to endorse or promote products derived from
16
16
  // this software without specific prior written permission.
17
- //
17
+ //
18
18
  // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
19
  // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
20
  // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@@ -28,7 +28,6 @@
28
28
  // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
29
 
30
30
  // ----
31
- // Author: Craig Silverstein
32
31
  //
33
32
  // This is just a very thin wrapper over densehashtable.h, just
34
33
  // like sgi stl's stl_hash_map is a very thin wrapper over
@@ -97,35 +96,31 @@
97
96
  #ifndef _DENSE_HASH_MAP_H_
98
97
  #define _DENSE_HASH_MAP_H_
99
98
 
100
- #include <google/sparsehash/sparseconfig.h>
101
- #include <stdio.h> // for FILE * in read()/write()
102
- #include <algorithm> // for the default template args
103
- #include <functional> // for equal_to
104
- #include <memory> // for alloc<>
105
- #include <utility> // for pair<>
106
- #include HASH_FUN_H // defined in config.h
107
- #include <google/sparsehash/libc_allocator_with_realloc.h>
108
- #include <google/sparsehash/densehashtable.h>
109
-
110
-
99
+ #include <sparsehash/internal/sparseconfig.h>
100
+ #include <algorithm> // needed by stl_alloc
101
+ #include <functional> // for equal_to<>, select1st<>, etc
102
+ #include <memory> // for alloc
103
+ #include <utility> // for pair<>
104
+ #include <sparsehash/internal/densehashtable.h> // IWYU pragma: export
105
+ #include <sparsehash/internal/libc_allocator_with_realloc.h>
106
+ #include HASH_FUN_H // for hash<>
111
107
  _START_GOOGLE_NAMESPACE_
112
108
 
113
- using STL_NAMESPACE::pair;
114
-
115
109
  template <class Key, class T,
116
110
  class HashFcn = SPARSEHASH_HASH<Key>, // defined in sparseconfig.h
117
- class EqualKey = STL_NAMESPACE::equal_to<Key>,
118
- class Alloc = libc_allocator_with_realloc<pair<const Key, T> > >
111
+ class EqualKey = std::equal_to<Key>,
112
+ class Alloc = libc_allocator_with_realloc<std::pair<const Key, T> > >
119
113
  class dense_hash_map {
120
114
  private:
121
115
  // Apparently select1st is not stl-standard, so we define our own
122
116
  struct SelectKey {
123
- const Key& operator()(const pair<const Key, T>& p) const {
117
+ typedef const Key& result_type;
118
+ const Key& operator()(const std::pair<const Key, T>& p) const {
124
119
  return p.first;
125
120
  }
126
121
  };
127
122
  struct SetKey {
128
- void operator()(pair<const Key, T>* value, const Key& new_key) const {
123
+ void operator()(std::pair<const Key, T>* value, const Key& new_key) const {
129
124
  *const_cast<Key*>(&value->first) = new_key;
130
125
  // It would be nice to clear the rest of value here as well, in
131
126
  // case it's taking up a lot of memory. We do this by clearing
@@ -133,9 +128,15 @@ class dense_hash_map {
133
128
  value->second = T();
134
129
  }
135
130
  };
131
+ // For operator[].
132
+ struct DefaultValue {
133
+ std::pair<const Key, T> operator()(const Key& key) {
134
+ return std::make_pair(key, T());
135
+ }
136
+ };
136
137
 
137
138
  // The actual data
138
- typedef dense_hashtable<pair<const Key, T>, Key, HashFcn, SelectKey,
139
+ typedef dense_hashtable<std::pair<const Key, T>, Key, HashFcn, SelectKey,
139
140
  SetKey, EqualKey, Alloc> ht;
140
141
  ht rep;
141
142
 
@@ -260,26 +261,34 @@ class dense_hash_map {
260
261
  // If key is in the hashtable, returns find(key)->second,
261
262
  // otherwise returns insert(value_type(key, T()).first->second.
262
263
  // Note it does not create an empty T unless the find fails.
263
- return rep.template find_or_insert<T>(key);
264
+ return rep.template find_or_insert<DefaultValue>(key).second;
264
265
  }
265
266
 
266
267
  size_type count(const key_type& key) const { return rep.count(key); }
267
268
 
268
- pair<iterator, iterator> equal_range(const key_type& key) {
269
+ std::pair<iterator, iterator> equal_range(const key_type& key) {
269
270
  return rep.equal_range(key);
270
271
  }
271
- pair<const_iterator, const_iterator> equal_range(const key_type& key) const {
272
+ std::pair<const_iterator, const_iterator> equal_range(const key_type& key)
273
+ const {
272
274
  return rep.equal_range(key);
273
275
  }
274
276
 
275
- // Insertion routines
276
- pair<iterator, bool> insert(const value_type& obj) { return rep.insert(obj); }
277
- template <class InputIterator>
278
- void insert(InputIterator f, InputIterator l) { rep.insert(f, l); }
279
- void insert(const_iterator f, const_iterator l) { rep.insert(f, l); }
280
- // required for std::insert_iterator; the passed-in iterator is ignored
281
- iterator insert(iterator, const value_type& obj) { return insert(obj).first; }
282
277
 
278
+ // Insertion routines
279
+ std::pair<iterator, bool> insert(const value_type& obj) {
280
+ return rep.insert(obj);
281
+ }
282
+ template <class InputIterator> void insert(InputIterator f, InputIterator l) {
283
+ rep.insert(f, l);
284
+ }
285
+ void insert(const_iterator f, const_iterator l) {
286
+ rep.insert(f, l);
287
+ }
288
+ // Required for std::insert_iterator; the passed-in iterator is ignored.
289
+ iterator insert(iterator, const value_type& obj) {
290
+ return insert(obj).first;
291
+ }
283
292
 
284
293
  // Deletion and empty routines
285
294
  // THESE ARE NON-STANDARD! I make you specify an "impossible" key
@@ -307,11 +316,45 @@ class dense_hash_map {
307
316
  bool operator!=(const dense_hash_map& hs) const { return rep != hs.rep; }
308
317
 
309
318
 
310
- // I/O -- this is an add-on for writing metainformation to disk
311
- bool write_metadata(FILE *fp) { return rep.write_metadata(fp); }
312
- bool read_metadata(FILE *fp) { return rep.read_metadata(fp); }
313
- bool write_nopointer_data(FILE *fp) { return rep.write_nopointer_data(fp); }
314
- bool read_nopointer_data(FILE *fp) { return rep.read_nopointer_data(fp); }
319
+ // I/O -- this is an add-on for writing hash map to disk
320
+ //
321
+ // For maximum flexibility, this does not assume a particular
322
+ // file type (though it will probably be a FILE *). We just pass
323
+ // the fp through to rep.
324
+
325
+ // If your keys and values are simple enough, you can pass this
326
+ // serializer to serialize()/unserialize(). "Simple enough" means
327
+ // value_type is a POD type that contains no pointers. Note,
328
+ // however, we don't try to normalize endianness.
329
+ typedef typename ht::NopointerSerializer NopointerSerializer;
330
+
331
+ // serializer: a class providing operator()(OUTPUT*, const value_type&)
332
+ // (writing value_type to OUTPUT). You can specify a
333
+ // NopointerSerializer object if appropriate (see above).
334
+ // fp: either a FILE*, OR an ostream*/subclass_of_ostream*, OR a
335
+ // pointer to a class providing size_t Write(const void*, size_t),
336
+ // which writes a buffer into a stream (which fp presumably
337
+ // owns) and returns the number of bytes successfully written.
338
+ // Note basic_ostream<not_char> is not currently supported.
339
+ template <typename ValueSerializer, typename OUTPUT>
340
+ bool serialize(ValueSerializer serializer, OUTPUT* fp) {
341
+ return rep.serialize(serializer, fp);
342
+ }
343
+
344
+ // serializer: a functor providing operator()(INPUT*, value_type*)
345
+ // (reading from INPUT and into value_type). You can specify a
346
+ // NopointerSerializer object if appropriate (see above).
347
+ // fp: either a FILE*, OR an istream*/subclass_of_istream*, OR a
348
+ // pointer to a class providing size_t Read(void*, size_t),
349
+ // which reads into a buffer from a stream (which fp presumably
350
+ // owns) and returns the number of bytes successfully read.
351
+ // Note basic_istream<not_char> is not currently supported.
352
+ // NOTE: Since value_type is std::pair<const Key, T>, ValueSerializer
353
+ // may need to do a const cast in order to fill in the key.
354
+ template <typename ValueSerializer, typename INPUT>
355
+ bool unserialize(ValueSerializer serializer, INPUT* fp) {
356
+ return rep.unserialize(serializer, fp);
357
+ }
315
358
  };
316
359
 
317
360
  // We need a global swap as well
@@ -1,10 +1,10 @@
1
1
  // Copyright (c) 2005, Google Inc.
2
2
  // All rights reserved.
3
- //
3
+ //
4
4
  // Redistribution and use in source and binary forms, with or without
5
5
  // modification, are permitted provided that the following conditions are
6
6
  // met:
7
- //
7
+ //
8
8
  // * Redistributions of source code must retain the above copyright
9
9
  // notice, this list of conditions and the following disclaimer.
10
10
  // * Redistributions in binary form must reproduce the above
@@ -14,7 +14,7 @@
14
14
  // * Neither the name of Google Inc. nor the names of its
15
15
  // contributors may be used to endorse or promote products derived from
16
16
  // this software without specific prior written permission.
17
- //
17
+ //
18
18
  // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19
19
  // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20
20
  // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@@ -28,7 +28,6 @@
28
28
  // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
29
 
30
30
  // ---
31
- // Author: Craig Silverstein
32
31
  //
33
32
  // This is just a very thin wrapper over densehashtable.h, just
34
33
  // like sgi stl's stl_hash_set is a very thin wrapper over
@@ -101,30 +100,25 @@
101
100
  #ifndef _DENSE_HASH_SET_H_
102
101
  #define _DENSE_HASH_SET_H_
103
102
 
104
- #include <google/sparsehash/sparseconfig.h>
105
- #include <stdio.h> // for FILE * in read()/write()
106
- #include <algorithm> // for the default template args
107
- #include <functional> // for equal_to
108
- #include <memory> // for alloc<>
109
- #include <utility> // for pair<>
110
- #include HASH_FUN_H // defined in config.h
111
- #include <google/sparsehash/libc_allocator_with_realloc.h>
112
- #include <google/sparsehash/densehashtable.h>
113
-
114
-
103
+ #include <sparsehash/internal/sparseconfig.h>
104
+ #include <algorithm> // needed by stl_alloc
105
+ #include <functional> // for equal_to<>, select1st<>, etc
106
+ #include <memory> // for alloc
107
+ #include <utility> // for pair<>
108
+ #include <sparsehash/internal/densehashtable.h> // IWYU pragma: export
109
+ #include <sparsehash/internal/libc_allocator_with_realloc.h>
110
+ #include HASH_FUN_H // for hash<>
115
111
  _START_GOOGLE_NAMESPACE_
116
112
 
117
- using STL_NAMESPACE::pair;
118
-
119
113
  template <class Value,
120
- class HashFcn = SPARSEHASH_HASH<Value>, // defined in sparseconfig.h
121
- class EqualKey = STL_NAMESPACE::equal_to<Value>,
114
+ class HashFcn = SPARSEHASH_HASH<Value>, // defined in sparseconfig.h
115
+ class EqualKey = std::equal_to<Value>,
122
116
  class Alloc = libc_allocator_with_realloc<Value> >
123
117
  class dense_hash_set {
124
118
  private:
125
119
  // Apparently identity is not stl-standard, so we define our own
126
120
  struct Identity {
127
- Value& operator()(Value& v) const { return v; }
121
+ typedef const Value& result_type;
128
122
  const Value& operator()(const Value& v) const { return v; }
129
123
  };
130
124
  struct SetKey {
@@ -251,22 +245,26 @@ class dense_hash_set {
251
245
 
252
246
  size_type count(const key_type& key) const { return rep.count(key); }
253
247
 
254
- pair<iterator, iterator> equal_range(const key_type& key) const {
248
+ std::pair<iterator, iterator> equal_range(const key_type& key) const {
255
249
  return rep.equal_range(key);
256
250
  }
257
251
 
258
252
 
259
253
  // Insertion routines
260
- pair<iterator, bool> insert(const value_type& obj) {
261
- pair<typename ht::iterator, bool> p = rep.insert(obj);
262
- return pair<iterator, bool>(p.first, p.second); // const to non-const
254
+ std::pair<iterator, bool> insert(const value_type& obj) {
255
+ std::pair<typename ht::iterator, bool> p = rep.insert(obj);
256
+ return std::pair<iterator, bool>(p.first, p.second); // const to non-const
257
+ }
258
+ template <class InputIterator> void insert(InputIterator f, InputIterator l) {
259
+ rep.insert(f, l);
260
+ }
261
+ void insert(const_iterator f, const_iterator l) {
262
+ rep.insert(f, l);
263
+ }
264
+ // Required for std::insert_iterator; the passed-in iterator is ignored.
265
+ iterator insert(iterator, const value_type& obj) {
266
+ return insert(obj).first;
263
267
  }
264
- template <class InputIterator>
265
- void insert(InputIterator f, InputIterator l) { rep.insert(f, l); }
266
- void insert(const_iterator f, const_iterator l) { rep.insert(f, l); }
267
- // required for std::insert_iterator; the passed-in iterator is ignored
268
- iterator insert(iterator, const value_type& obj) { return insert(obj).first; }
269
-
270
268
 
271
269
  // Deletion and empty routines
272
270
  // THESE ARE NON-STANDARD! I make you specify an "impossible" key
@@ -291,10 +289,42 @@ class dense_hash_set {
291
289
 
292
290
 
293
291
  // I/O -- this is an add-on for writing metainformation to disk
294
- bool write_metadata(FILE *fp) { return rep.write_metadata(fp); }
295
- bool read_metadata(FILE *fp) { return rep.read_metadata(fp); }
296
- bool write_nopointer_data(FILE *fp) { return rep.write_nopointer_data(fp); }
297
- bool read_nopointer_data(FILE *fp) { return rep.read_nopointer_data(fp); }
292
+ //
293
+ // For maximum flexibility, this does not assume a particular
294
+ // file type (though it will probably be a FILE *). We just pass
295
+ // the fp through to rep.
296
+
297
+ // If your keys and values are simple enough, you can pass this
298
+ // serializer to serialize()/unserialize(). "Simple enough" means
299
+ // value_type is a POD type that contains no pointers. Note,
300
+ // however, we don't try to normalize endianness.
301
+ typedef typename ht::NopointerSerializer NopointerSerializer;
302
+
303
+ // serializer: a class providing operator()(OUTPUT*, const value_type&)
304
+ // (writing value_type to OUTPUT). You can specify a
305
+ // NopointerSerializer object if appropriate (see above).
306
+ // fp: either a FILE*, OR an ostream*/subclass_of_ostream*, OR a
307
+ // pointer to a class providing size_t Write(const void*, size_t),
308
+ // which writes a buffer into a stream (which fp presumably
309
+ // owns) and returns the number of bytes successfully written.
310
+ // Note basic_ostream<not_char> is not currently supported.
311
+ template <typename ValueSerializer, typename OUTPUT>
312
+ bool serialize(ValueSerializer serializer, OUTPUT* fp) {
313
+ return rep.serialize(serializer, fp);
314
+ }
315
+
316
+ // serializer: a functor providing operator()(INPUT*, value_type*)
317
+ // (reading from INPUT and into value_type). You can specify a
318
+ // NopointerSerializer object if appropriate (see above).
319
+ // fp: either a FILE*, OR an istream*/subclass_of_istream*, OR a
320
+ // pointer to a class providing size_t Read(void*, size_t),
321
+ // which reads into a buffer from a stream (which fp presumably
322
+ // owns) and returns the number of bytes successfully read.
323
+ // Note basic_istream<not_char> is not currently supported.
324
+ template <typename ValueSerializer, typename INPUT>
325
+ bool unserialize(ValueSerializer serializer, INPUT* fp) {
326
+ return rep.unserialize(serializer, fp);
327
+ }
298
328
  };
299
329
 
300
330
  template <class Val, class HashFcn, class EqualKey, class Alloc>