google_hash 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -87,7 +87,7 @@ details.)
87
87
 
88
88
  <pre>
89
89
  #include &lt;iostream&gt;
90
- #include &lt;google/sparse_hash_set&gt;
90
+ #include &lt;sparsehash/sparse_hash_set&gt;
91
91
 
92
92
  using google::sparse_hash_set; // namespace where class lives by default
93
93
  using std::cout;
@@ -588,7 +588,7 @@ None.
588
588
  <tt>Unordered Associative Container</tt> (tr1)
589
589
  </TD>
590
590
  <TD VAlign=top>
591
- If the key exists in the map, returns the index of the bucket
591
+ If the key exists in the set, returns the index of the bucket
592
592
  containing the given key, otherwise, return the bucket the key
593
593
  would be inserted into.
594
594
  This value may be passed to <tt>begin(size_type)</tt> and
@@ -1120,7 +1120,8 @@ key_type&amp; k) const</pre>
1120
1120
 
1121
1121
  <TR>
1122
1122
  <TD VAlign=top>
1123
- <tt>bool write_metadata(FILE *fp)</tt>
1123
+ <tt>template &lt;ValueSerializer, OUTPUT&gt;
1124
+ bool serialize(ValueSerializer serializer, OUTPUT *fp)</tt>
1124
1125
  </TD>
1125
1126
  <TD VAlign=top>
1126
1127
  <tt>sparse_hash_set</tt>
@@ -1132,7 +1133,8 @@ key_type&amp; k) const</pre>
1132
1133
 
1133
1134
  <TR>
1134
1135
  <TD VAlign=top>
1135
- <tt>bool read_metadata(FILE *fp)</tt>
1136
+ <tt>template &lt;ValueSerializer, INPUT&gt;
1137
+ bool unserialize(ValueSerializer serializer, INPUT *fp)</tt>
1136
1138
  </TD>
1137
1139
  <TD VAlign=top>
1138
1140
  <tt>sparse_hash_set</tt>
@@ -1144,7 +1146,7 @@ key_type&amp; k) const</pre>
1144
1146
 
1145
1147
  <TR>
1146
1148
  <TD VAlign=top>
1147
- <tt>bool write_nopointer_data(FILE *fp)</tt>
1149
+ <tt>NopointerSerializer</tt>
1148
1150
  </TD>
1149
1151
  <TD VAlign=top>
1150
1152
  <tt>sparse_hash_set</tt>
@@ -1154,6 +1156,42 @@ key_type&amp; k) const</pre>
1154
1156
  </TD>
1155
1157
  </TR>
1156
1158
 
1159
+ <TR>
1160
+ <TD VAlign=top>
1161
+ <tt>bool write_metadata(FILE *fp)</tt>
1162
+ </TD>
1163
+ <TD VAlign=top>
1164
+ <tt>sparse_hash_set</tt>
1165
+ </TD>
1166
+ <TD VAlign=top>
1167
+ DEPRECATED. <A HREF="#new">See below</A>.
1168
+ </TD>
1169
+ </TR>
1170
+
1171
+ <TR>
1172
+ <TD VAlign=top>
1173
+ <tt>bool read_metadata(FILE *fp)</tt>
1174
+ </TD>
1175
+ <TD VAlign=top>
1176
+ <tt>sparse_hash_set</tt>
1177
+ </TD>
1178
+ <TD VAlign=top>
1179
+ DEPRECATED. <A HREF="#new">See below</A>.
1180
+ </TD>
1181
+ </TR>
1182
+
1183
+ <TR>
1184
+ <TD VAlign=top>
1185
+ <tt>bool write_nopointer_data(FILE *fp)</tt>
1186
+ </TD>
1187
+ <TD VAlign=top>
1188
+ <tt>sparse_hash_set</tt>
1189
+ </TD>
1190
+ <TD VAlign=top>
1191
+ DEPRECATED. <A HREF="#new">See below</A>.
1192
+ </TD>
1193
+ </TR>
1194
+
1157
1195
  <TR>
1158
1196
  <TD VAlign=top>
1159
1197
  <tt>bool read_nopointer_data(FILE *fp)</tt>
@@ -1162,7 +1200,7 @@ key_type&amp; k) const</pre>
1162
1200
  <tt>sparse_hash_set</tt>
1163
1201
  </TD>
1164
1202
  <TD VAlign=top>
1165
- <A HREF="#new">See below</A>.
1203
+ DEPRECATED. <A HREF="#new">See below</A>.
1166
1204
  </TD>
1167
1205
  </TR>
1168
1206
 
@@ -1228,12 +1266,35 @@ Container</tt> requirements, but are specific to
1228
1266
  </TD>
1229
1267
  </TR>
1230
1268
 
1269
+ <TR>
1270
+ <TD VAlign=top>
1271
+ <tt>template &lt;ValueSerializer, OUTPUT&gt;
1272
+ bool serialize(ValueSerializer serializer, OUTPUT *fp)</tt>
1273
+ </TD>
1274
+ <TD VAlign=top>
1275
+ Emit a serialization of the hash_set to a stream.
1276
+ See <A HREF="#io">below</A>.
1277
+ </TD>
1278
+ </TR>
1279
+
1280
+ <TR>
1281
+ <TD VAlign=top>
1282
+ <tt>template &lt;ValueSerializer, INPUT&gt;
1283
+ bool unserialize(ValueSerializer serializer, INPUT *fp)</tt>
1284
+ </TD>
1285
+ <TD VAlign=top>
1286
+ Read in a serialization of a hash_set from a stream, replacing the
1287
+ existing hash_set contents with the serialized contents.
1288
+ See <A HREF="#io">below</A>.
1289
+ </TD>
1290
+ </TR>
1291
+
1231
1292
  <TR>
1232
1293
  <TD VAlign=top>
1233
1294
  <tt>bool write_metadata(FILE *fp)</tt>
1234
1295
  </TD>
1235
1296
  <TD VAlign=top>
1236
- Write hashtable metadata to <tt>fp</tt>. See <A HREF="#io">below</A>.
1297
+ This function is DEPRECATED. See <A HREF="#io">below</A>.
1237
1298
  </TD>
1238
1299
  </TR>
1239
1300
 
@@ -1242,7 +1303,7 @@ Container</tt> requirements, but are specific to
1242
1303
  <tt>bool read_metadata(FILE *fp)</tt>
1243
1304
  </TD>
1244
1305
  <TD VAlign=top>
1245
- Read hashtable metadata from <tt>fp</tt>. See <A HREF="#io">below</A>.
1306
+ This function is DEPRECATED. See <A HREF="#io">below</A>.
1246
1307
  </TD>
1247
1308
  </TR>
1248
1309
 
@@ -1251,8 +1312,7 @@ Container</tt> requirements, but are specific to
1251
1312
  <tt>bool write_nopointer_data(FILE *fp)</tt>
1252
1313
  </TD>
1253
1314
  <TD VAlign=top>
1254
- Write hashtable contents to <tt>fp</tt>. This is valid only if the
1255
- hashtable key and value are "plain" data. See <A HREF="#io">below</A>.
1315
+ This function is DEPRECATED. See <A HREF="#io">below</A>.
1256
1316
  </TD>
1257
1317
  </TR>
1258
1318
 
@@ -1261,8 +1321,7 @@ Container</tt> requirements, but are specific to
1261
1321
  <tt>bool read_nopointer_data(FILE *fp)</tt>
1262
1322
  </TD>
1263
1323
  <TD VAlign=top>
1264
- Read hashtable contents to <tt>fp</tt>. This is valid only if the
1265
- hashtable key and value are "plain" data. See <A HREF="#io">below</A>.
1324
+ This function is DEPRECATED. See <A HREF="#io">below</A>.
1266
1325
  </TD>
1267
1326
  </TR>
1268
1327
 
@@ -1330,65 +1389,121 @@ insertion but no hashtable entries can be deleted until
1330
1389
  <h3><A NAME=io>Input/Output</A></h3>
1331
1390
 
1332
1391
  <p>It is possible to save and restore <tt>sparse_hash_set</tt> objects
1333
- to disk. Storage takes place in two steps. The first writes the
1334
- hashtable metadata. The second writes the actual data.</p>
1335
-
1336
- <p>To write a hashtable to disk, first call <tt>write_metadata()</tt>
1337
- on an open file pointer. This saves the hashtable information in a
1338
- byte-order-independent format.</p>
1339
-
1340
- <p>After the metadata has been written to disk, you must write the
1341
- actual data stored in the hash-set to disk. If both the key and data
1342
- are "simple" enough, you can do this by calling
1343
- <tt>write_nopointer_data()</tt>. "Simple" data is data that can be
1344
- safely copied to disk via <tt>fwrite()</tt>. Native C data types fall
1345
- into this category, as do structs of native C data types. Pointers
1346
- and STL objects do not.</p>
1347
-
1348
- <p>Note that <tt>write_nopointer_data()</tt> does not do any endian
1349
- conversion. Thus, it is only appropriate when you intend to read the
1350
- data on the same endian architecture as you write the data.</p>
1392
+ to an arbitrary stream (such as a disk file) using the
1393
+ <tt>serialize()</tt> and <tt>unserialize()</tt> methods.</p>
1394
+
1395
+ <p>Each of these methods takes two arguments: a <i>serializer</i>,
1396
+ which says how to write hashtable items to disk, and a <i>stream</i>,
1397
+ which can be a C++ stream (<tt>istream</tt> or its subclasses for
1398
+ input, <tt>ostream</tt> or its subclasses for output), a
1399
+ <tt>FILE*</tt>, or a user-defined type (as described below).</p>
1400
+
1401
+ <p>The <it>serializer</i> is a functor that takes a stream and a
1402
+ single hashtable element (a <tt>value_type</tt>) and copies the
1403
+ hashtable element to the stream (for <tt>serialize()</tt>) or fills
1404
+ the hashtable element contents from the stream (for
1405
+ <tt>unserialize()</tt>), and returns true on success or false on
1406
+ error. The copy-in and copy-out functions can be provided in a single
1407
+ functor. Here is a sample serializer that read/writes a hashtable
1408
+ element for a string hash_set to a <tt>FILE*</tt>:</p>
1409
+
1410
+ <pre>
1411
+ struct StringSerializer {
1412
+ bool operator()(FILE* fp, const std::string&amp; value) const {
1413
+ assert(value.length() &lt;= 255); // we only support writing small strings
1414
+ const unsigned char size = value.length();
1415
+ if (fwrite(&amp;size, 1, 1, fp) != 1)
1416
+ return false;
1417
+ if (fwrite(value.data(), size, 1, fp) != 1)
1418
+ return false;
1419
+ return true;
1420
+ }
1421
+ bool operator()(FILE* fp, std::string* value) const {
1422
+ unsigned char size; // all strings are &lt;= 255 chars long
1423
+ if (fread(&amp;size, 1, 1, fp) != 1)
1424
+ return false;
1425
+ char* buf = new char[size];
1426
+ if (fread(buf, size, 1, fp) != 1) {
1427
+ delete[] buf;
1428
+ return false;
1429
+ }
1430
+ new(value) string(buf, size);
1431
+ delete[] buf;
1432
+ return true;
1433
+ }
1434
+ };
1435
+ </pre>
1351
1436
 
1352
- <p>If you cannot use <tt>write_nopointer_data()</tt> for any reason,
1353
- you can write the data yourself by iterating over the
1354
- <tt>sparse_hash_set</tt> with a <tt>const_iterator</tt> and writing
1355
- the key and data in any manner you wish.</p>
1356
-
1357
- <p>To read the hashtable information from disk, first you must create
1358
- a <tt>sparse_hash_set</tt> object. Then open a file pointer to point
1359
- to the saved hashtable, and call <tt>read_metadata()</tt>. If you
1360
- saved the data via <tt>write_nopointer_data()</tt>, you can follow the
1361
- <tt>read_metadata()</tt> call with a call to
1362
- <tt>read_nopointer_data()</tt>. This is all that is needed.</p>
1363
-
1364
- <p>If you saved the data through a custom write routine, you must call
1365
- a custom read routine to read in the data. To do this, iterate over
1366
- the <tt>sparse_hash_set</tt> with an <tt>iterator</tt>; this operation
1367
- is sensical because the metadata has already been set up. For each
1368
- iterator item, you can read the key and value from disk, and set it
1369
- appropriately. You will need to do a <tt>const_cast</tt> on the
1370
- iterator, since <tt>*it</tt> is always <tt>const</tt>. The
1371
- code might look like this:</p>
1437
+ <p>Here is the functor being used in code (error checking omitted):</p>
1372
1438
  <pre>
1373
- for (sparse_hash_set&lt;int*&gt;::iterator it = ht.begin();
1374
- it != ht.end(); ++it) {
1375
- const_cast&lt;int*&gt;(*it) = new int;
1376
- fread(const_cast&lt;int*&gt;(*it), sizeof(int), 1, fp);
1377
- }
1439
+ sparse_hash_set&lt;string&gt; myset = CreateSet();
1440
+ FILE* fp = fopen("hashtable.data", "w");
1441
+ myset.serialize(StringSerializer(), fp);
1442
+ fclose(fp);
1443
+
1444
+ sparse_hash_set&lt;string&gt; myset2;
1445
+ FILE* fp_in = fopen("hashtable.data", "r");
1446
+ myset2.unserialize(StringSerializer(), fp_in);
1447
+ fclose(fp_in);
1448
+ assert(myset == myset2);
1378
1449
  </pre>
1379
1450
 
1380
- <p>Here's another example, where the item stored in the hash-set is
1381
- a C++ object with a non-trivial constructor. In this case, you must
1382
- use "placement new" to construct the object at the correct memory
1383
- location.</p>
1451
+ <p><b>Important note:</b> the code above uses placement-new to
1452
+ instantiate the <tt>string</tt>. This is <i>required</i> for any
1453
+ non-POD type. The value_type passed in to the unserializer
1454
+ points to garbage memory, so it is not safe to assign to it directly
1455
+ if doing so causes a destructor to be called.</p>
1456
+
1457
+ <p>Also note that this example serializer can only serialize to a
1458
+ FILE*. If you want to also be able to use this serializer with C++
1459
+ streams, you will need to write two more overloads of
1460
+ <tt>operator()</tt>'s, one that reads from an <tt>istream</tt>, and
1461
+ one that writes to an <tt>ostream</tt>. Likewise if you want to
1462
+ support serializing to a custom class.</p>
1463
+
1464
+ <p>If the key is "simple" enough, you can use the pre-supplied functor
1465
+ <tt>NopointerSerializer</tt>. This copies the hashtable data using
1466
+ the equivalent of a <tt>memcpy<></tt>. Native C data types can be
1467
+ serialized this way, as can structs of native C data types. Pointers
1468
+ and STL objects cannot.</p>
1469
+
1470
+ <p>Note that <tt>NopointerSerializer()</tt> does not do any endian
1471
+ conversion. Thus, it is only appropriate when you intend to read the
1472
+ data on the same endian architecture as you write the data.</p>
1473
+
1474
+ <p>If you wish to serialize to your own stream type, you can do so by
1475
+ creating an object which supports two methods:</p>
1384
1476
  <pre>
1385
- for (sparse_hash_set&lt;ComplicatedClass&gt;::iterator it = ht.begin();
1386
- it != ht.end(); ++it) {
1387
- int ctor_arg; // ComplicatedClass takes an int as its constructor arg
1388
- fread(&ctor_arg, sizeof(int), 1, fp);
1389
- new (const_cast&lt;ComplicatedClass*&gt;(&(*it))) ComplicatedClass(ctor_arg);
1390
- }
1477
+ bool Write(const void* data, size_t length);
1478
+ bool Read(void* data, size_t length);
1391
1479
  </pre>
1480
+ <p><tt>Write()</tt> writes <tt>length</tt> bytes of <tt>data</tt> to a
1481
+ stream (presumably a stream owned by the object), while
1482
+ <tt>Read()</tt> reads <tt>data</tt> bytes from the stream into
1483
+ <tt>data</tt>. Both return true on success or false on error.</p>
1484
+
1485
+ <p>To unserialize a hashtable from a stream, you wil typically create
1486
+ a new <tt>sparse_hash_set</tt> object, then call <tt>unserialize()</tt>
1487
+ on it. <tt>unserialize()</tt> destroys the old contents of the
1488
+ object. You must pass in the appropriate <tt>ValueSerializer</tt> for
1489
+ the data being read in.</p>
1490
+
1491
+ <p>Both <tt>serialize()</tt> and <tt>unserialize()</tt> return
1492
+ <tt>true</tt> on success, or <tt>false</tt> if there was an error
1493
+ streaming the data.</p>
1494
+
1495
+ <p>Note that <tt>serialize()</tt> is not a const method, since it
1496
+ purges deleted elements before serializing. It is not safe to
1497
+ serialize from two threads at once, without synchronization.</p>
1498
+
1499
+ <p>NOTE: older versions of <tt>sparse_hash_set</tt> provided a
1500
+ different API, consisting of <tt>read_metadata()</tt>,
1501
+ <tt>read_nopointer_data()</tt>, <tt>write_metadata()</tt>,
1502
+ <tt>write_nopointer_data()</tt>. Writing to disk consisted of a call
1503
+ to <tt>write_metadata()</tt> followed by
1504
+ <tt>write_nopointer_data()</tt> (if the hash data was POD) or a custom
1505
+ loop over the hashtable buckets to write the data (otherwise).
1506
+ Reading from disk was similar. Prefer the new API for new code.</p>
1392
1507
 
1393
1508
 
1394
1509
  <h3><A NAME=iter>Validity of Iterators</A></h3>
@@ -78,7 +78,7 @@ persistent.</p>
78
78
  <h3>Example</h3>
79
79
 
80
80
  <pre>
81
- #include &lt;google/sparsetable&gt;
81
+ #include &lt;sparsehash/sparsetable&gt;
82
82
 
83
83
  using google::sparsetable; // namespace where class lives by default
84
84
 
@@ -1,3 +1,4 @@
1
+ #include <sparsehash/internal/sparseconfig.h>
1
2
  #include <stdlib.h>
2
3
  #include <stdio.h>
3
4
  #include <assert.h>
@@ -118,6 +118,7 @@
118
118
  * is defined correctly for your machine! (5 for 32 bit words, 6 for 64).
119
119
  */
120
120
 
121
+ #include <sparsehash/internal/sparseconfig.h>
121
122
  #include <stdlib.h>
122
123
  #include <stdio.h>
123
124
  #include <string.h> /* for strcmp, memcmp, etc */
@@ -115,6 +115,7 @@
115
115
  * from disk.
116
116
  */
117
117
 
118
+ #include <sparsehash/internal/sparseconfig.h>
118
119
  #include <sys/types.h> /* includes definition of "ulong", we hope */
119
120
  #define ulong u_long
120
121
 
@@ -0,0 +1,520 @@
1
+ #!/bin/sh
2
+ # install - install a program, script, or datafile
3
+
4
+ scriptversion=2009-04-28.21; # UTC
5
+
6
+ # This originates from X11R5 (mit/util/scripts/install.sh), which was
7
+ # later released in X11R6 (xc/config/util/install.sh) with the
8
+ # following copyright and license.
9
+ #
10
+ # Copyright (C) 1994 X Consortium
11
+ #
12
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
13
+ # of this software and associated documentation files (the "Software"), to
14
+ # deal in the Software without restriction, including without limitation the
15
+ # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
16
+ # sell copies of the Software, and to permit persons to whom the Software is
17
+ # furnished to do so, subject to the following conditions:
18
+ #
19
+ # The above copyright notice and this permission notice shall be included in
20
+ # all copies or substantial portions of the Software.
21
+ #
22
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
+ # X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
26
+ # AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-
27
+ # TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28
+ #
29
+ # Except as contained in this notice, the name of the X Consortium shall not
30
+ # be used in advertising or otherwise to promote the sale, use or other deal-
31
+ # ings in this Software without prior written authorization from the X Consor-
32
+ # tium.
33
+ #
34
+ #
35
+ # FSF changes to this file are in the public domain.
36
+ #
37
+ # Calling this script install-sh is preferred over install.sh, to prevent
38
+ # `make' implicit rules from creating a file called install from it
39
+ # when there is no Makefile.
40
+ #
41
+ # This script is compatible with the BSD install script, but was written
42
+ # from scratch.
43
+
44
+ nl='
45
+ '
46
+ IFS=" "" $nl"
47
+
48
+ # set DOITPROG to echo to test this script
49
+
50
+ # Don't use :- since 4.3BSD and earlier shells don't like it.
51
+ doit=${DOITPROG-}
52
+ if test -z "$doit"; then
53
+ doit_exec=exec
54
+ else
55
+ doit_exec=$doit
56
+ fi
57
+
58
+ # Put in absolute file names if you don't have them in your path;
59
+ # or use environment vars.
60
+
61
+ chgrpprog=${CHGRPPROG-chgrp}
62
+ chmodprog=${CHMODPROG-chmod}
63
+ chownprog=${CHOWNPROG-chown}
64
+ cmpprog=${CMPPROG-cmp}
65
+ cpprog=${CPPROG-cp}
66
+ mkdirprog=${MKDIRPROG-mkdir}
67
+ mvprog=${MVPROG-mv}
68
+ rmprog=${RMPROG-rm}
69
+ stripprog=${STRIPPROG-strip}
70
+
71
+ posix_glob='?'
72
+ initialize_posix_glob='
73
+ test "$posix_glob" != "?" || {
74
+ if (set -f) 2>/dev/null; then
75
+ posix_glob=
76
+ else
77
+ posix_glob=:
78
+ fi
79
+ }
80
+ '
81
+
82
+ posix_mkdir=
83
+
84
+ # Desired mode of installed file.
85
+ mode=0755
86
+
87
+ chgrpcmd=
88
+ chmodcmd=$chmodprog
89
+ chowncmd=
90
+ mvcmd=$mvprog
91
+ rmcmd="$rmprog -f"
92
+ stripcmd=
93
+
94
+ src=
95
+ dst=
96
+ dir_arg=
97
+ dst_arg=
98
+
99
+ copy_on_change=false
100
+ no_target_directory=
101
+
102
+ usage="\
103
+ Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE
104
+ or: $0 [OPTION]... SRCFILES... DIRECTORY
105
+ or: $0 [OPTION]... -t DIRECTORY SRCFILES...
106
+ or: $0 [OPTION]... -d DIRECTORIES...
107
+
108
+ In the 1st form, copy SRCFILE to DSTFILE.
109
+ In the 2nd and 3rd, copy all SRCFILES to DIRECTORY.
110
+ In the 4th, create DIRECTORIES.
111
+
112
+ Options:
113
+ --help display this help and exit.
114
+ --version display version info and exit.
115
+
116
+ -c (ignored)
117
+ -C install only if different (preserve the last data modification time)
118
+ -d create directories instead of installing files.
119
+ -g GROUP $chgrpprog installed files to GROUP.
120
+ -m MODE $chmodprog installed files to MODE.
121
+ -o USER $chownprog installed files to USER.
122
+ -s $stripprog installed files.
123
+ -t DIRECTORY install into DIRECTORY.
124
+ -T report an error if DSTFILE is a directory.
125
+
126
+ Environment variables override the default commands:
127
+ CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG
128
+ RMPROG STRIPPROG
129
+ "
130
+
131
+ while test $# -ne 0; do
132
+ case $1 in
133
+ -c) ;;
134
+
135
+ -C) copy_on_change=true;;
136
+
137
+ -d) dir_arg=true;;
138
+
139
+ -g) chgrpcmd="$chgrpprog $2"
140
+ shift;;
141
+
142
+ --help) echo "$usage"; exit $?;;
143
+
144
+ -m) mode=$2
145
+ case $mode in
146
+ *' '* | *' '* | *'
147
+ '* | *'*'* | *'?'* | *'['*)
148
+ echo "$0: invalid mode: $mode" >&2
149
+ exit 1;;
150
+ esac
151
+ shift;;
152
+
153
+ -o) chowncmd="$chownprog $2"
154
+ shift;;
155
+
156
+ -s) stripcmd=$stripprog;;
157
+
158
+ -t) dst_arg=$2
159
+ shift;;
160
+
161
+ -T) no_target_directory=true;;
162
+
163
+ --version) echo "$0 $scriptversion"; exit $?;;
164
+
165
+ --) shift
166
+ break;;
167
+
168
+ -*) echo "$0: invalid option: $1" >&2
169
+ exit 1;;
170
+
171
+ *) break;;
172
+ esac
173
+ shift
174
+ done
175
+
176
+ if test $# -ne 0 && test -z "$dir_arg$dst_arg"; then
177
+ # When -d is used, all remaining arguments are directories to create.
178
+ # When -t is used, the destination is already specified.
179
+ # Otherwise, the last argument is the destination. Remove it from $@.
180
+ for arg
181
+ do
182
+ if test -n "$dst_arg"; then
183
+ # $@ is not empty: it contains at least $arg.
184
+ set fnord "$@" "$dst_arg"
185
+ shift # fnord
186
+ fi
187
+ shift # arg
188
+ dst_arg=$arg
189
+ done
190
+ fi
191
+
192
+ if test $# -eq 0; then
193
+ if test -z "$dir_arg"; then
194
+ echo "$0: no input file specified." >&2
195
+ exit 1
196
+ fi
197
+ # It's OK to call `install-sh -d' without argument.
198
+ # This can happen when creating conditional directories.
199
+ exit 0
200
+ fi
201
+
202
+ if test -z "$dir_arg"; then
203
+ trap '(exit $?); exit' 1 2 13 15
204
+
205
+ # Set umask so as not to create temps with too-generous modes.
206
+ # However, 'strip' requires both read and write access to temps.
207
+ case $mode in
208
+ # Optimize common cases.
209
+ *644) cp_umask=133;;
210
+ *755) cp_umask=22;;
211
+
212
+ *[0-7])
213
+ if test -z "$stripcmd"; then
214
+ u_plus_rw=
215
+ else
216
+ u_plus_rw='% 200'
217
+ fi
218
+ cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;
219
+ *)
220
+ if test -z "$stripcmd"; then
221
+ u_plus_rw=
222
+ else
223
+ u_plus_rw=,u+rw
224
+ fi
225
+ cp_umask=$mode$u_plus_rw;;
226
+ esac
227
+ fi
228
+
229
+ for src
230
+ do
231
+ # Protect names starting with `-'.
232
+ case $src in
233
+ -*) src=./$src;;
234
+ esac
235
+
236
+ if test -n "$dir_arg"; then
237
+ dst=$src
238
+ dstdir=$dst
239
+ test -d "$dstdir"
240
+ dstdir_status=$?
241
+ else
242
+
243
+ # Waiting for this to be detected by the "$cpprog $src $dsttmp" command
244
+ # might cause directories to be created, which would be especially bad
245
+ # if $src (and thus $dsttmp) contains '*'.
246
+ if test ! -f "$src" && test ! -d "$src"; then
247
+ echo "$0: $src does not exist." >&2
248
+ exit 1
249
+ fi
250
+
251
+ if test -z "$dst_arg"; then
252
+ echo "$0: no destination specified." >&2
253
+ exit 1
254
+ fi
255
+
256
+ dst=$dst_arg
257
+ # Protect names starting with `-'.
258
+ case $dst in
259
+ -*) dst=./$dst;;
260
+ esac
261
+
262
+ # If destination is a directory, append the input filename; won't work
263
+ # if double slashes aren't ignored.
264
+ if test -d "$dst"; then
265
+ if test -n "$no_target_directory"; then
266
+ echo "$0: $dst_arg: Is a directory" >&2
267
+ exit 1
268
+ fi
269
+ dstdir=$dst
270
+ dst=$dstdir/`basename "$src"`
271
+ dstdir_status=0
272
+ else
273
+ # Prefer dirname, but fall back on a substitute if dirname fails.
274
+ dstdir=`
275
+ (dirname "$dst") 2>/dev/null ||
276
+ expr X"$dst" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
277
+ X"$dst" : 'X\(//\)[^/]' \| \
278
+ X"$dst" : 'X\(//\)$' \| \
279
+ X"$dst" : 'X\(/\)' \| . 2>/dev/null ||
280
+ echo X"$dst" |
281
+ sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{
282
+ s//\1/
283
+ q
284
+ }
285
+ /^X\(\/\/\)[^/].*/{
286
+ s//\1/
287
+ q
288
+ }
289
+ /^X\(\/\/\)$/{
290
+ s//\1/
291
+ q
292
+ }
293
+ /^X\(\/\).*/{
294
+ s//\1/
295
+ q
296
+ }
297
+ s/.*/./; q'
298
+ `
299
+
300
+ test -d "$dstdir"
301
+ dstdir_status=$?
302
+ fi
303
+ fi
304
+
305
+ obsolete_mkdir_used=false
306
+
307
+ if test $dstdir_status != 0; then
308
+ case $posix_mkdir in
309
+ '')
310
+ # Create intermediate dirs using mode 755 as modified by the umask.
311
+ # This is like FreeBSD 'install' as of 1997-10-28.
312
+ umask=`umask`
313
+ case $stripcmd.$umask in
314
+ # Optimize common cases.
315
+ *[2367][2367]) mkdir_umask=$umask;;
316
+ .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;
317
+
318
+ *[0-7])
319
+ mkdir_umask=`expr $umask + 22 \
320
+ - $umask % 100 % 40 + $umask % 20 \
321
+ - $umask % 10 % 4 + $umask % 2
322
+ `;;
323
+ *) mkdir_umask=$umask,go-w;;
324
+ esac
325
+
326
+ # With -d, create the new directory with the user-specified mode.
327
+ # Otherwise, rely on $mkdir_umask.
328
+ if test -n "$dir_arg"; then
329
+ mkdir_mode=-m$mode
330
+ else
331
+ mkdir_mode=
332
+ fi
333
+
334
+ posix_mkdir=false
335
+ case $umask in
336
+ *[123567][0-7][0-7])
337
+ # POSIX mkdir -p sets u+wx bits regardless of umask, which
338
+ # is incompatible with FreeBSD 'install' when (umask & 300) != 0.
339
+ ;;
340
+ *)
341
+ tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$
342
+ trap 'ret=$?; rmdir "$tmpdir/d" "$tmpdir" 2>/dev/null; exit $ret' 0
343
+
344
+ if (umask $mkdir_umask &&
345
+ exec $mkdirprog $mkdir_mode -p -- "$tmpdir/d") >/dev/null 2>&1
346
+ then
347
+ if test -z "$dir_arg" || {
348
+ # Check for POSIX incompatibilities with -m.
349
+ # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or
350
+ # other-writeable bit of parent directory when it shouldn't.
351
+ # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.
352
+ ls_ld_tmpdir=`ls -ld "$tmpdir"`
353
+ case $ls_ld_tmpdir in
354
+ d????-?r-*) different_mode=700;;
355
+ d????-?--*) different_mode=755;;
356
+ *) false;;
357
+ esac &&
358
+ $mkdirprog -m$different_mode -p -- "$tmpdir" && {
359
+ ls_ld_tmpdir_1=`ls -ld "$tmpdir"`
360
+ test "$ls_ld_tmpdir" = "$ls_ld_tmpdir_1"
361
+ }
362
+ }
363
+ then posix_mkdir=:
364
+ fi
365
+ rmdir "$tmpdir/d" "$tmpdir"
366
+ else
367
+ # Remove any dirs left behind by ancient mkdir implementations.
368
+ rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null
369
+ fi
370
+ trap '' 0;;
371
+ esac;;
372
+ esac
373
+
374
+ if
375
+ $posix_mkdir && (
376
+ umask $mkdir_umask &&
377
+ $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir"
378
+ )
379
+ then :
380
+ else
381
+
382
+ # The umask is ridiculous, or mkdir does not conform to POSIX,
383
+ # or it failed possibly due to a race condition. Create the
384
+ # directory the slow way, step by step, checking for races as we go.
385
+
386
+ case $dstdir in
387
+ /*) prefix='/';;
388
+ -*) prefix='./';;
389
+ *) prefix='';;
390
+ esac
391
+
392
+ eval "$initialize_posix_glob"
393
+
394
+ oIFS=$IFS
395
+ IFS=/
396
+ $posix_glob set -f
397
+ set fnord $dstdir
398
+ shift
399
+ $posix_glob set +f
400
+ IFS=$oIFS
401
+
402
+ prefixes=
403
+
404
+ for d
405
+ do
406
+ test -z "$d" && continue
407
+
408
+ prefix=$prefix$d
409
+ if test -d "$prefix"; then
410
+ prefixes=
411
+ else
412
+ if $posix_mkdir; then
413
+ (umask=$mkdir_umask &&
414
+ $doit_exec $mkdirprog $mkdir_mode -p -- "$dstdir") && break
415
+ # Don't fail if two instances are running concurrently.
416
+ test -d "$prefix" || exit 1
417
+ else
418
+ case $prefix in
419
+ *\'*) qprefix=`echo "$prefix" | sed "s/'/'\\\\\\\\''/g"`;;
420
+ *) qprefix=$prefix;;
421
+ esac
422
+ prefixes="$prefixes '$qprefix'"
423
+ fi
424
+ fi
425
+ prefix=$prefix/
426
+ done
427
+
428
+ if test -n "$prefixes"; then
429
+ # Don't fail if two instances are running concurrently.
430
+ (umask $mkdir_umask &&
431
+ eval "\$doit_exec \$mkdirprog $prefixes") ||
432
+ test -d "$dstdir" || exit 1
433
+ obsolete_mkdir_used=true
434
+ fi
435
+ fi
436
+ fi
437
+
438
+ if test -n "$dir_arg"; then
439
+ { test -z "$chowncmd" || $doit $chowncmd "$dst"; } &&
440
+ { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } &&
441
+ { test "$obsolete_mkdir_used$chowncmd$chgrpcmd" = false ||
442
+ test -z "$chmodcmd" || $doit $chmodcmd $mode "$dst"; } || exit 1
443
+ else
444
+
445
+ # Make a couple of temp file names in the proper directory.
446
+ dsttmp=$dstdir/_inst.$$_
447
+ rmtmp=$dstdir/_rm.$$_
448
+
449
+ # Trap to clean up those temp files at exit.
450
+ trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0
451
+
452
+ # Copy the file name to the temp name.
453
+ (umask $cp_umask && $doit_exec $cpprog "$src" "$dsttmp") &&
454
+
455
+ # and set any options; do chmod last to preserve setuid bits.
456
+ #
457
+ # If any of these fail, we abort the whole thing. If we want to
458
+ # ignore errors from any of these, just make sure not to ignore
459
+ # errors from the above "$doit $cpprog $src $dsttmp" command.
460
+ #
461
+ { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } &&
462
+ { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } &&
463
+ { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } &&
464
+ { test -z "$chmodcmd" || $doit $chmodcmd $mode "$dsttmp"; } &&
465
+
466
+ # If -C, don't bother to copy if it wouldn't change the file.
467
+ if $copy_on_change &&
468
+ old=`LC_ALL=C ls -dlL "$dst" 2>/dev/null` &&
469
+ new=`LC_ALL=C ls -dlL "$dsttmp" 2>/dev/null` &&
470
+
471
+ eval "$initialize_posix_glob" &&
472
+ $posix_glob set -f &&
473
+ set X $old && old=:$2:$4:$5:$6 &&
474
+ set X $new && new=:$2:$4:$5:$6 &&
475
+ $posix_glob set +f &&
476
+
477
+ test "$old" = "$new" &&
478
+ $cmpprog "$dst" "$dsttmp" >/dev/null 2>&1
479
+ then
480
+ rm -f "$dsttmp"
481
+ else
482
+ # Rename the file to the real destination.
483
+ $doit $mvcmd -f "$dsttmp" "$dst" 2>/dev/null ||
484
+
485
+ # The rename failed, perhaps because mv can't rename something else
486
+ # to itself, or perhaps because mv is so ancient that it does not
487
+ # support -f.
488
+ {
489
+ # Now remove or move aside any old file at destination location.
490
+ # We try this two ways since rm can't unlink itself on some
491
+ # systems and the destination file might be busy for other
492
+ # reasons. In this case, the final cleanup might fail but the new
493
+ # file should still install successfully.
494
+ {
495
+ test ! -f "$dst" ||
496
+ $doit $rmcmd -f "$dst" 2>/dev/null ||
497
+ { $doit $mvcmd -f "$dst" "$rmtmp" 2>/dev/null &&
498
+ { $doit $rmcmd -f "$rmtmp" 2>/dev/null; :; }
499
+ } ||
500
+ { echo "$0: cannot unlink or rename $dst" >&2
501
+ (exit 1); exit 1
502
+ }
503
+ } &&
504
+
505
+ # Now rename the file to the real destination.
506
+ $doit $mvcmd "$dsttmp" "$dst"
507
+ }
508
+ fi || exit 1
509
+
510
+ trap '' 0
511
+ fi
512
+ done
513
+
514
+ # Local variables:
515
+ # eval: (add-hook 'write-file-hooks 'time-stamp)
516
+ # time-stamp-start: "scriptversion="
517
+ # time-stamp-format: "%:y-%02m-%02d.%02H"
518
+ # time-stamp-time-zone: "UTC"
519
+ # time-stamp-end: "; # UTC"
520
+ # End: