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.
- data/ChangeLog.txt +2 -0
- data/VERSION +1 -1
- data/ext/clean.bat +0 -0
- data/ext/clean.sh +4 -0
- data/ext/extconf.rb +4 -5
- data/ext/go.bat +0 -0
- data/ext/sparsehash-2.0.2/AUTHORS +2 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/COPYING +0 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/ChangeLog +60 -0
- data/ext/sparsehash-2.0.2/INSTALL +365 -0
- data/ext/sparsehash-2.0.2/Makefile +1336 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/Makefile.am +97 -40
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/Makefile.in +538 -256
- data/ext/sparsehash-2.0.2/NEWS +188 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/README +4 -10
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/README_windows.txt +3 -3
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/TODO +0 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/aclocal.m4 +266 -166
- data/ext/sparsehash-2.0.2/allocator.patch +31 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/config.guess +235 -234
- data/ext/sparsehash-2.0.2/config.status +1238 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/config.sub +198 -64
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/configure +1118 -1000
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/configure.ac +4 -5
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/depcomp +136 -36
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/doc/dense_hash_map.html +182 -67
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/doc/dense_hash_set.html +173 -74
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/doc/designstyle.css +0 -6
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/doc/implementation.html +0 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/doc/index.html +4 -5
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/doc/performance.html +1 -1
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/doc/sparse_hash_map.html +190 -58
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/doc/sparse_hash_set.html +180 -65
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/doc/sparsetable.html +1 -1
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/experimental/Makefile +0 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/experimental/README +0 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/experimental/example.c +1 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/experimental/libchash.c +1 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/experimental/libchash.h +1 -0
- data/ext/sparsehash-2.0.2/install-sh +520 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/m4/acx_pthread.m4 +34 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/m4/google_namespace.m4 +0 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/m4/namespaces.m4 +0 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/m4/stl_hash.m4 +0 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/m4/stl_hash_fun.m4 +0 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/missing +60 -44
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/packages/deb.sh +0 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/packages/deb/README +0 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/packages/deb/changelog +42 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/packages/deb/compat +0 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/packages/deb/control +1 -1
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/packages/deb/copyright +5 -4
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/packages/deb/docs +0 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/packages/deb/rules +0 -0
- data/ext/sparsehash-2.0.2/packages/deb/sparsehash.dirs +5 -0
- data/ext/sparsehash-2.0.2/packages/deb/sparsehash.install +6 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/packages/rpm.sh +1 -1
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/packages/rpm/rpm.spec +5 -3
- data/ext/{sparsehash-1.8.1/google-sparsehash.sln → sparsehash-2.0.2/sparsehash.sln} +0 -0
- data/ext/sparsehash-2.0.2/src/config.h +132 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/config.h.in +0 -3
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/config.h.include +0 -1
- data/ext/sparsehash-2.0.2/src/google/dense_hash_map +34 -0
- data/ext/sparsehash-2.0.2/src/google/dense_hash_set +34 -0
- data/ext/sparsehash-2.0.2/src/google/sparse_hash_map +34 -0
- data/ext/sparsehash-2.0.2/src/google/sparse_hash_set +34 -0
- data/ext/sparsehash-2.0.2/src/google/sparsehash/densehashtable.h +34 -0
- data/ext/sparsehash-2.0.2/src/google/sparsehash/hashtable-common.h +34 -0
- data/ext/sparsehash-2.0.2/src/google/sparsehash/libc_allocator_with_realloc.h +34 -0
- data/ext/sparsehash-2.0.2/src/google/sparsehash/sparsehashtable.h +34 -0
- data/ext/sparsehash-2.0.2/src/google/sparsetable +34 -0
- data/ext/sparsehash-2.0.2/src/google/template_util.h +34 -0
- data/ext/sparsehash-2.0.2/src/google/type_traits.h +34 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/hash_test_interface.h +64 -37
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/hashtable_test.cc +415 -141
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/libc_allocator_with_realloc_test.cc +16 -23
- data/ext/sparsehash-2.0.2/src/simple_compat_test.cc +106 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/simple_test.cc +8 -5
- data/ext/{sparsehash-1.8.1/src/google → sparsehash-2.0.2/src/sparsehash}/dense_hash_map +80 -37
- data/ext/{sparsehash-1.8.1/src/google → sparsehash-2.0.2/src/sparsehash}/dense_hash_set +64 -34
- data/ext/{sparsehash-1.8.1/src/google/sparsehash → sparsehash-2.0.2/src/sparsehash/internal}/densehashtable.h +247 -173
- data/ext/sparsehash-2.0.2/src/sparsehash/internal/hashtable-common.h +381 -0
- data/ext/{sparsehash-1.8.1/src/google/sparsehash → sparsehash-2.0.2/src/sparsehash/internal}/libc_allocator_with_realloc.h +5 -7
- data/ext/{sparsehash-1.8.1/src/google/sparsehash → sparsehash-2.0.2/src/sparsehash/internal}/sparsehashtable.h +154 -93
- data/ext/{sparsehash-1.8.1/src/google → sparsehash-2.0.2/src/sparsehash}/sparse_hash_map +96 -36
- data/ext/{sparsehash-1.8.1/src/google → sparsehash-2.0.2/src/sparsehash}/sparse_hash_set +85 -32
- data/ext/{sparsehash-1.8.1/src/google → sparsehash-2.0.2/src/sparsehash}/sparsetable +520 -258
- data/ext/sparsehash-2.0.2/src/sparsehash/template_util.h +134 -0
- data/ext/{sparsehash-1.8.1/src/google → sparsehash-2.0.2/src/sparsehash}/type_traits.h +153 -35
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/sparsetable_unittest.cc +108 -22
- data/ext/sparsehash-2.0.2/src/stamp-h1 +1 -0
- data/ext/sparsehash-2.0.2/src/template_util_unittest.cc +134 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/testutil.h +16 -1
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/time_hash_map.cc +259 -94
- data/ext/sparsehash-2.0.2/src/type_traits_unittest.cc +636 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/windows/config.h +4 -4
- data/ext/sparsehash-2.0.2/src/windows/google/sparsehash/sparseconfig.h +49 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/windows/port.cc +1 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/src/windows/port.h +4 -13
- data/ext/sparsehash-2.0.2/src/windows/sparsehash/internal/sparseconfig.h +49 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/vsprojects/hashtable_test/hashtable_test.vcproj +11 -11
- data/ext/sparsehash-2.0.2/vsprojects/libc_allocator_with_realloc_test/libc_allocator_with_realloc_test.vcproj +161 -0
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/vsprojects/simple_test/simple_test.vcproj +10 -10
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/vsprojects/sparsetable_unittest/sparsetable_unittest.vcproj +4 -4
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/vsprojects/time_hash_map/time_hash_map.vcproj +10 -10
- data/ext/{sparsehash-1.8.1 → sparsehash-2.0.2}/vsprojects/type_traits_unittest/type_traits_unittest.vcproj +3 -3
- data/ext/spec.bat +0 -0
- data/ext/template/google_hash.cpp.erb +6 -5
- metadata +106 -86
- data/ext/sparsehash-1.8.1/AUTHORS +0 -2
- data/ext/sparsehash-1.8.1/INSTALL +0 -236
- data/ext/sparsehash-1.8.1/NEWS +0 -71
- data/ext/sparsehash-1.8.1/compile +0 -99
- data/ext/sparsehash-1.8.1/install-sh +0 -323
- data/ext/sparsehash-1.8.1/m4/stl_namespace.m4 +0 -25
- data/ext/sparsehash-1.8.1/mkinstalldirs +0 -158
- data/ext/sparsehash-1.8.1/packages/deb/sparsehash.dirs +0 -2
- data/ext/sparsehash-1.8.1/packages/deb/sparsehash.install +0 -2
- data/ext/sparsehash-1.8.1/src/google/sparsehash/hashtable-common.h +0 -178
- data/ext/sparsehash-1.8.1/src/type_traits_unittest.cc +0 -502
- data/ext/sparsehash-1.8.1/src/windows/google/sparsehash/sparseconfig.h +0 -32
@@ -0,0 +1,134 @@
|
|
1
|
+
// Copyright 2005 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
|
+
// Template metaprogramming utility functions.
|
33
|
+
//
|
34
|
+
// This code is compiled directly on many platforms, including client
|
35
|
+
// platforms like Windows, Mac, and embedded systems. Before making
|
36
|
+
// any changes here, make sure that you're not breaking any platforms.
|
37
|
+
//
|
38
|
+
//
|
39
|
+
// The names choosen here reflect those used in tr1 and the boost::mpl
|
40
|
+
// library, there are similar operations used in the Loki library as
|
41
|
+
// well. I prefer the boost names for 2 reasons:
|
42
|
+
// 1. I think that portions of the Boost libraries are more likely to
|
43
|
+
// be included in the c++ standard.
|
44
|
+
// 2. It is not impossible that some of the boost libraries will be
|
45
|
+
// included in our own build in the future.
|
46
|
+
// Both of these outcomes means that we may be able to directly replace
|
47
|
+
// some of these with boost equivalents.
|
48
|
+
//
|
49
|
+
#ifndef BASE_TEMPLATE_UTIL_H_
|
50
|
+
#define BASE_TEMPLATE_UTIL_H_
|
51
|
+
|
52
|
+
#include <sparsehash/internal/sparseconfig.h>
|
53
|
+
_START_GOOGLE_NAMESPACE_
|
54
|
+
|
55
|
+
// Types small_ and big_ are guaranteed such that sizeof(small_) <
|
56
|
+
// sizeof(big_)
|
57
|
+
typedef char small_;
|
58
|
+
|
59
|
+
struct big_ {
|
60
|
+
char dummy[2];
|
61
|
+
};
|
62
|
+
|
63
|
+
// Identity metafunction.
|
64
|
+
template <class T>
|
65
|
+
struct identity_ {
|
66
|
+
typedef T type;
|
67
|
+
};
|
68
|
+
|
69
|
+
// integral_constant, defined in tr1, is a wrapper for an integer
|
70
|
+
// value. We don't really need this generality; we could get away
|
71
|
+
// with hardcoding the integer type to bool. We use the fully
|
72
|
+
// general integer_constant for compatibility with tr1.
|
73
|
+
|
74
|
+
template<class T, T v>
|
75
|
+
struct integral_constant {
|
76
|
+
static const T value = v;
|
77
|
+
typedef T value_type;
|
78
|
+
typedef integral_constant<T, v> type;
|
79
|
+
};
|
80
|
+
|
81
|
+
template <class T, T v> const T integral_constant<T, v>::value;
|
82
|
+
|
83
|
+
|
84
|
+
// Abbreviations: true_type and false_type are structs that represent boolean
|
85
|
+
// true and false values. Also define the boost::mpl versions of those names,
|
86
|
+
// true_ and false_.
|
87
|
+
typedef integral_constant<bool, true> true_type;
|
88
|
+
typedef integral_constant<bool, false> false_type;
|
89
|
+
typedef true_type true_;
|
90
|
+
typedef false_type false_;
|
91
|
+
|
92
|
+
// if_ is a templatized conditional statement.
|
93
|
+
// if_<cond, A, B> is a compile time evaluation of cond.
|
94
|
+
// if_<>::type contains A if cond is true, B otherwise.
|
95
|
+
template<bool cond, typename A, typename B>
|
96
|
+
struct if_{
|
97
|
+
typedef A type;
|
98
|
+
};
|
99
|
+
|
100
|
+
template<typename A, typename B>
|
101
|
+
struct if_<false, A, B> {
|
102
|
+
typedef B type;
|
103
|
+
};
|
104
|
+
|
105
|
+
|
106
|
+
// type_equals_ is a template type comparator, similar to Loki IsSameType.
|
107
|
+
// type_equals_<A, B>::value is true iff "A" is the same type as "B".
|
108
|
+
//
|
109
|
+
// New code should prefer base::is_same, defined in base/type_traits.h.
|
110
|
+
// It is functionally identical, but is_same is the standard spelling.
|
111
|
+
template<typename A, typename B>
|
112
|
+
struct type_equals_ : public false_ {
|
113
|
+
};
|
114
|
+
|
115
|
+
template<typename A>
|
116
|
+
struct type_equals_<A, A> : public true_ {
|
117
|
+
};
|
118
|
+
|
119
|
+
// and_ is a template && operator.
|
120
|
+
// and_<A, B>::value evaluates "A::value && B::value".
|
121
|
+
template<typename A, typename B>
|
122
|
+
struct and_ : public integral_constant<bool, (A::value && B::value)> {
|
123
|
+
};
|
124
|
+
|
125
|
+
// or_ is a template || operator.
|
126
|
+
// or_<A, B>::value evaluates "A::value || B::value".
|
127
|
+
template<typename A, typename B>
|
128
|
+
struct or_ : public integral_constant<bool, (A::value || B::value)> {
|
129
|
+
};
|
130
|
+
|
131
|
+
|
132
|
+
_END_GOOGLE_NAMESPACE_
|
133
|
+
|
134
|
+
#endif // BASE_TEMPLATE_UTIL_H_
|
@@ -28,12 +28,16 @@
|
|
28
28
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
29
|
|
30
30
|
// ----
|
31
|
-
//
|
31
|
+
//
|
32
|
+
// This code is compiled directly on many platforms, including client
|
33
|
+
// platforms like Windows, Mac, and embedded systems. Before making
|
34
|
+
// any changes here, make sure that you're not breaking any platforms.
|
32
35
|
//
|
33
36
|
// Define a small subset of tr1 type traits. The traits we define are:
|
34
37
|
// is_integral
|
35
38
|
// is_floating_point
|
36
39
|
// is_pointer
|
40
|
+
// is_enum
|
37
41
|
// is_reference
|
38
42
|
// is_pod
|
39
43
|
// has_trivial_constructor
|
@@ -44,6 +48,7 @@
|
|
44
48
|
// remove_volatile
|
45
49
|
// remove_cv
|
46
50
|
// remove_reference
|
51
|
+
// add_reference
|
47
52
|
// remove_pointer
|
48
53
|
// is_same
|
49
54
|
// is_convertible
|
@@ -52,39 +57,40 @@
|
|
52
57
|
#ifndef BASE_TYPE_TRAITS_H_
|
53
58
|
#define BASE_TYPE_TRAITS_H_
|
54
59
|
|
55
|
-
#include <
|
60
|
+
#include <sparsehash/internal/sparseconfig.h>
|
56
61
|
#include <utility> // For pair
|
57
62
|
|
58
|
-
|
59
|
-
|
60
|
-
// integral_constant, defined in tr1, is a wrapper for an integer
|
61
|
-
// value. We don't really need this generality; we could get away
|
62
|
-
// with hardcoding the integer type to bool. We use the fully
|
63
|
-
// general integer_constant for compatibility with tr1.
|
64
|
-
|
65
|
-
template<class T, T v>
|
66
|
-
struct integral_constant {
|
67
|
-
static const T value = v;
|
68
|
-
typedef T value_type;
|
69
|
-
typedef integral_constant<T, v> type;
|
70
|
-
};
|
71
|
-
|
72
|
-
template <class T, T v> const T integral_constant<T, v>::value;
|
73
|
-
|
74
|
-
// Abbreviations: true_type and false_type are structs that represent
|
75
|
-
// boolean true and false values.
|
76
|
-
typedef integral_constant<bool, true> true_type;
|
77
|
-
typedef integral_constant<bool, false> false_type;
|
63
|
+
#include <sparsehash/template_util.h> // For true_type and false_type
|
78
64
|
|
79
|
-
|
80
|
-
// sizeof(big_)
|
81
|
-
typedef char small_;
|
65
|
+
_START_GOOGLE_NAMESPACE_
|
82
66
|
|
83
|
-
struct
|
84
|
-
|
85
|
-
|
67
|
+
template <class T> struct is_integral;
|
68
|
+
template <class T> struct is_floating_point;
|
69
|
+
template <class T> struct is_pointer;
|
70
|
+
// MSVC can't compile this correctly, and neither can gcc 3.3.5 (at least)
|
71
|
+
#if !defined(_MSC_VER) && !(defined(__GNUC__) && __GNUC__ <= 3)
|
72
|
+
// is_enum uses is_convertible, which is not available on MSVC.
|
73
|
+
template <class T> struct is_enum;
|
74
|
+
#endif
|
75
|
+
template <class T> struct is_reference;
|
76
|
+
template <class T> struct is_pod;
|
77
|
+
template <class T> struct has_trivial_constructor;
|
78
|
+
template <class T> struct has_trivial_copy;
|
79
|
+
template <class T> struct has_trivial_assign;
|
80
|
+
template <class T> struct has_trivial_destructor;
|
81
|
+
template <class T> struct remove_const;
|
82
|
+
template <class T> struct remove_volatile;
|
83
|
+
template <class T> struct remove_cv;
|
84
|
+
template <class T> struct remove_reference;
|
85
|
+
template <class T> struct add_reference;
|
86
|
+
template <class T> struct remove_pointer;
|
87
|
+
template <class T, class U> struct is_same;
|
88
|
+
#if !defined(_MSC_VER) && !(defined(__GNUC__) && __GNUC__ <= 3)
|
89
|
+
template <class From, class To> struct is_convertible;
|
90
|
+
#endif
|
86
91
|
|
87
|
-
// is_integral is false except for the built-in integer types.
|
92
|
+
// is_integral is false except for the built-in integer types. A
|
93
|
+
// cv-qualified type is integral if and only if the underlying type is.
|
88
94
|
template <class T> struct is_integral : false_type { };
|
89
95
|
template<> struct is_integral<bool> : true_type { };
|
90
96
|
template<> struct is_integral<char> : true_type { };
|
@@ -108,19 +114,80 @@ template<> struct is_integral<unsigned long> : true_type { };
|
|
108
114
|
template<> struct is_integral<long long> : true_type { };
|
109
115
|
template<> struct is_integral<unsigned long long> : true_type { };
|
110
116
|
#endif
|
111
|
-
|
117
|
+
template <class T> struct is_integral<const T> : is_integral<T> { };
|
118
|
+
template <class T> struct is_integral<volatile T> : is_integral<T> { };
|
119
|
+
template <class T> struct is_integral<const volatile T> : is_integral<T> { };
|
112
120
|
|
113
121
|
// is_floating_point is false except for the built-in floating-point types.
|
122
|
+
// A cv-qualified type is integral if and only if the underlying type is.
|
114
123
|
template <class T> struct is_floating_point : false_type { };
|
115
124
|
template<> struct is_floating_point<float> : true_type { };
|
116
125
|
template<> struct is_floating_point<double> : true_type { };
|
117
126
|
template<> struct is_floating_point<long double> : true_type { };
|
127
|
+
template <class T> struct is_floating_point<const T>
|
128
|
+
: is_floating_point<T> { };
|
129
|
+
template <class T> struct is_floating_point<volatile T>
|
130
|
+
: is_floating_point<T> { };
|
131
|
+
template <class T> struct is_floating_point<const volatile T>
|
132
|
+
: is_floating_point<T> { };
|
118
133
|
|
119
|
-
|
120
|
-
//
|
134
|
+
// is_pointer is false except for pointer types. A cv-qualified type (e.g.
|
135
|
+
// "int* const", as opposed to "int const*") is cv-qualified if and only if
|
136
|
+
// the underlying type is.
|
121
137
|
template <class T> struct is_pointer : false_type { };
|
122
138
|
template <class T> struct is_pointer<T*> : true_type { };
|
139
|
+
template <class T> struct is_pointer<const T> : is_pointer<T> { };
|
140
|
+
template <class T> struct is_pointer<volatile T> : is_pointer<T> { };
|
141
|
+
template <class T> struct is_pointer<const volatile T> : is_pointer<T> { };
|
142
|
+
|
143
|
+
#if !defined(_MSC_VER) && !(defined(__GNUC__) && __GNUC__ <= 3)
|
144
|
+
|
145
|
+
namespace internal {
|
146
|
+
|
147
|
+
template <class T> struct is_class_or_union {
|
148
|
+
template <class U> static small_ tester(void (U::*)());
|
149
|
+
template <class U> static big_ tester(...);
|
150
|
+
static const bool value = sizeof(tester<T>(0)) == sizeof(small_);
|
151
|
+
};
|
152
|
+
|
153
|
+
// is_convertible chokes if the first argument is an array. That's why
|
154
|
+
// we use add_reference here.
|
155
|
+
template <bool NotUnum, class T> struct is_enum_impl
|
156
|
+
: is_convertible<typename add_reference<T>::type, int> { };
|
157
|
+
|
158
|
+
template <class T> struct is_enum_impl<true, T> : false_type { };
|
123
159
|
|
160
|
+
} // namespace internal
|
161
|
+
|
162
|
+
// Specified by TR1 [4.5.1] primary type categories.
|
163
|
+
|
164
|
+
// Implementation note:
|
165
|
+
//
|
166
|
+
// Each type is either void, integral, floating point, array, pointer,
|
167
|
+
// reference, member object pointer, member function pointer, enum,
|
168
|
+
// union or class. Out of these, only integral, floating point, reference,
|
169
|
+
// class and enum types are potentially convertible to int. Therefore,
|
170
|
+
// if a type is not a reference, integral, floating point or class and
|
171
|
+
// is convertible to int, it's a enum. Adding cv-qualification to a type
|
172
|
+
// does not change whether it's an enum.
|
173
|
+
//
|
174
|
+
// Is-convertible-to-int check is done only if all other checks pass,
|
175
|
+
// because it can't be used with some types (e.g. void or classes with
|
176
|
+
// inaccessible conversion operators).
|
177
|
+
template <class T> struct is_enum
|
178
|
+
: internal::is_enum_impl<
|
179
|
+
is_same<T, void>::value ||
|
180
|
+
is_integral<T>::value ||
|
181
|
+
is_floating_point<T>::value ||
|
182
|
+
is_reference<T>::value ||
|
183
|
+
internal::is_class_or_union<T>::value,
|
184
|
+
T> { };
|
185
|
+
|
186
|
+
template <class T> struct is_enum<const T> : is_enum<T> { };
|
187
|
+
template <class T> struct is_enum<volatile T> : is_enum<T> { };
|
188
|
+
template <class T> struct is_enum<const volatile T> : is_enum<T> { };
|
189
|
+
|
190
|
+
#endif
|
124
191
|
|
125
192
|
// is_reference is false except for reference types.
|
126
193
|
template<typename T> struct is_reference : false_type {};
|
@@ -128,13 +195,20 @@ template<typename T> struct is_reference<T&> : true_type {};
|
|
128
195
|
|
129
196
|
|
130
197
|
// We can't get is_pod right without compiler help, so fail conservatively.
|
131
|
-
// We will assume it's false except for arithmetic types
|
132
|
-
// and
|
198
|
+
// We will assume it's false except for arithmetic types, enumerations,
|
199
|
+
// pointers and cv-qualified versions thereof. Note that std::pair<T,U>
|
200
|
+
// is not a POD even if T and U are PODs.
|
133
201
|
template <class T> struct is_pod
|
134
202
|
: integral_constant<bool, (is_integral<T>::value ||
|
135
203
|
is_floating_point<T>::value ||
|
204
|
+
#if !defined(_MSC_VER) && !(defined(__GNUC__) && __GNUC__ <= 3)
|
205
|
+
// is_enum is not available on MSVC.
|
206
|
+
is_enum<T>::value ||
|
207
|
+
#endif
|
136
208
|
is_pointer<T>::value)> { };
|
137
209
|
template <class T> struct is_pod<const T> : is_pod<T> { };
|
210
|
+
template <class T> struct is_pod<volatile T> : is_pod<T> { };
|
211
|
+
template <class T> struct is_pod<const volatile T> : is_pod<T> { };
|
138
212
|
|
139
213
|
|
140
214
|
// We can't get has_trivial_constructor right without compiler help, so
|
@@ -203,10 +277,13 @@ template<typename T> struct remove_cv {
|
|
203
277
|
};
|
204
278
|
|
205
279
|
|
206
|
-
// Specified by TR1 [4.7.2]
|
280
|
+
// Specified by TR1 [4.7.2] Reference modifications.
|
207
281
|
template<typename T> struct remove_reference { typedef T type; };
|
208
282
|
template<typename T> struct remove_reference<T&> { typedef T type; };
|
209
283
|
|
284
|
+
template <typename T> struct add_reference { typedef T& type; };
|
285
|
+
template <typename T> struct add_reference<T&> { typedef T& type; };
|
286
|
+
|
210
287
|
// Specified by TR1 [4.7.4] Pointer modifications.
|
211
288
|
template<typename T> struct remove_pointer { typedef T type; };
|
212
289
|
template<typename T> struct remove_pointer<T*> { typedef T type; };
|
@@ -219,6 +296,47 @@ template<typename T> struct remove_pointer<T* const volatile> {
|
|
219
296
|
template<typename T, typename U> struct is_same : public false_type { };
|
220
297
|
template<typename T> struct is_same<T, T> : public true_type { };
|
221
298
|
|
299
|
+
// Specified by TR1 [4.6] Relationships between types
|
300
|
+
#if !defined(_MSC_VER) && !(defined(__GNUC__) && __GNUC__ <= 3)
|
301
|
+
namespace internal {
|
302
|
+
|
303
|
+
// This class is an implementation detail for is_convertible, and you
|
304
|
+
// don't need to know how it works to use is_convertible. For those
|
305
|
+
// who care: we declare two different functions, one whose argument is
|
306
|
+
// of type To and one with a variadic argument list. We give them
|
307
|
+
// return types of different size, so we can use sizeof to trick the
|
308
|
+
// compiler into telling us which function it would have chosen if we
|
309
|
+
// had called it with an argument of type From. See Alexandrescu's
|
310
|
+
// _Modern C++ Design_ for more details on this sort of trick.
|
311
|
+
|
312
|
+
template <typename From, typename To>
|
313
|
+
struct ConvertHelper {
|
314
|
+
static small_ Test(To);
|
315
|
+
static big_ Test(...);
|
316
|
+
static From Create();
|
317
|
+
};
|
318
|
+
} // namespace internal
|
319
|
+
|
320
|
+
// Inherits from true_type if From is convertible to To, false_type otherwise.
|
321
|
+
template <typename From, typename To>
|
322
|
+
struct is_convertible
|
323
|
+
: integral_constant<bool,
|
324
|
+
sizeof(internal::ConvertHelper<From, To>::Test(
|
325
|
+
internal::ConvertHelper<From, To>::Create()))
|
326
|
+
== sizeof(small_)> {
|
327
|
+
};
|
328
|
+
#endif
|
329
|
+
|
222
330
|
_END_GOOGLE_NAMESPACE_
|
223
331
|
|
332
|
+
// Right now these macros are no-ops, and mostly just document the fact
|
333
|
+
// these types are PODs, for human use. They may be made more contentful
|
334
|
+
// later. The typedef is just to make it legal to put a semicolon after
|
335
|
+
// these macros.
|
336
|
+
#define DECLARE_POD(TypeName) typedef int Dummy_Type_For_DECLARE_POD
|
337
|
+
#define DECLARE_NESTED_POD(TypeName) DECLARE_POD(TypeName)
|
338
|
+
#define PROPAGATE_POD_FROM_TEMPLATE_ARGUMENT(TemplateName) \
|
339
|
+
typedef int Dummy_Type_For_PROPAGATE_POD_FROM_TEMPLATE_ARGUMENT
|
340
|
+
#define ENFORCE_POD(TypeName) typedef int Dummy_Type_For_ENFORCE_POD
|
341
|
+
|
224
342
|
#endif // BASE_TYPE_TRAITS_H_
|
@@ -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,32 +28,31 @@
|
|
28
28
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
29
29
|
|
30
30
|
// ---
|
31
|
-
// Author: Craig Silverstein
|
32
|
-
//
|
33
|
-
// This tests <google/sparsetable>
|
34
31
|
//
|
35
32
|
// Since sparsetable is templatized, it's important that we test every
|
36
33
|
// function in every class in this file -- not just to see if it
|
37
34
|
// works, but even if it compiles.
|
38
35
|
|
39
|
-
#include
|
40
|
-
#include <
|
36
|
+
#include <sparsehash/internal/sparseconfig.h>
|
37
|
+
#include <config.h>
|
41
38
|
#include <stdio.h>
|
42
|
-
#include <string.h>
|
39
|
+
#include <string.h>
|
40
|
+
#include <sys/types.h> // for size_t
|
43
41
|
#include <stdlib.h> // defines unlink() on some windows platforms(?)
|
44
42
|
#ifdef HAVE_UNISTD_H
|
45
|
-
#include <unistd.h>
|
46
|
-
#
|
47
|
-
#include <string>
|
43
|
+
# include <unistd.h>
|
44
|
+
#endif // for unlink()
|
48
45
|
#include <memory> // for allocator
|
49
|
-
#
|
50
|
-
#include <
|
51
|
-
|
52
|
-
using
|
53
|
-
using STL_NAMESPACE::allocator;
|
46
|
+
#include <string>
|
47
|
+
#include <sparsehash/sparsetable>
|
48
|
+
using std::string;
|
49
|
+
using std::allocator;
|
54
50
|
using GOOGLE_NAMESPACE::sparsetable;
|
55
51
|
using GOOGLE_NAMESPACE::DEFAULT_SPARSEGROUP_SIZE;
|
56
52
|
|
53
|
+
typedef u_int16_t uint16;
|
54
|
+
string FLAGS_test_tmpdir = "/tmp/";
|
55
|
+
|
57
56
|
// Many sparsetable operations return a size_t. Rather than have to
|
58
57
|
// use PRIuS everywhere, we'll just cast to a "big enough" value.
|
59
58
|
#define UL(x) ( static_cast<unsigned long>(x) )
|
@@ -273,6 +272,28 @@ void TestInt() {
|
|
273
272
|
TEST(x.begin() == x.begin() + 1 - 1);
|
274
273
|
TEST(z.begin() != z.end());
|
275
274
|
|
275
|
+
// ----------------------------------------------------------------------
|
276
|
+
// Test the non-empty iterators get_pos function
|
277
|
+
|
278
|
+
sparsetable<unsigned int> gp(100);
|
279
|
+
for (int i = 0; i < 100; i += 9) {
|
280
|
+
gp.set(i,i);
|
281
|
+
}
|
282
|
+
|
283
|
+
for (sparsetable<unsigned int>::const_nonempty_iterator
|
284
|
+
it = gp.nonempty_begin(); it != gp.nonempty_end(); ++it) {
|
285
|
+
out += snprintf(out, LEFT,
|
286
|
+
"get_pos() for const nonempty_iterator: %u == %lu\n",
|
287
|
+
*it, UL(gp.get_pos(it)));
|
288
|
+
}
|
289
|
+
|
290
|
+
for (sparsetable<unsigned int>::nonempty_iterator
|
291
|
+
it = gp.nonempty_begin(); it != gp.nonempty_end(); ++it) {
|
292
|
+
out += snprintf(out, LEFT,
|
293
|
+
"get_pos() for nonempty_iterator: %u == %lu\n",
|
294
|
+
*it, UL(gp.get_pos(it)));
|
295
|
+
}
|
296
|
+
|
276
297
|
// ----------------------------------------------------------------------
|
277
298
|
// Test sparsetable functions
|
278
299
|
out += snprintf(out, LEFT, "x has %lu/%lu buckets, "
|
@@ -280,7 +301,7 @@ void TestInt() {
|
|
280
301
|
UL(x.num_nonempty()), UL(x.size()),
|
281
302
|
UL(y.num_nonempty()), UL(y.size()),
|
282
303
|
UL(z.num_nonempty()), UL(z.size()));
|
283
|
-
|
304
|
+
|
284
305
|
y.resize(48); // should get rid of 48 and 49
|
285
306
|
y.resize(70); // 48 and 49 should still be gone
|
286
307
|
out += snprintf(out, LEFT, "y shrank and grew: it's now %lu/%lu\n",
|
@@ -322,8 +343,8 @@ void TestInt() {
|
|
322
343
|
out += snprintf(out, LEFT, "y[??] = %d\n", *--it);
|
323
344
|
|
324
345
|
// ----------------------------------------------------------------------
|
325
|
-
// Test I/O
|
326
|
-
string filestr = "
|
346
|
+
// Test I/O using deprecated read/write_metadata
|
347
|
+
string filestr = FLAGS_test_tmpdir + "/.sparsetable.test";
|
327
348
|
const char *file = filestr.c_str();
|
328
349
|
FILE *fp = fopen(file, "wb");
|
329
350
|
if ( fp == NULL ) {
|
@@ -354,6 +375,31 @@ void TestInt() {
|
|
354
375
|
out += snprintf(out, LEFT, "That's %lu set buckets\n", UL(y2.num_nonempty()));
|
355
376
|
}
|
356
377
|
unlink(file);
|
378
|
+
|
379
|
+
// ----------------------------------------------------------------------
|
380
|
+
// Also test I/O using serialize()/unserialize()
|
381
|
+
fp = fopen(file, "wb");
|
382
|
+
if ( fp == NULL ) {
|
383
|
+
out += snprintf(out, LEFT, "Can't open %s, skipping disk write...\n", file);
|
384
|
+
} else {
|
385
|
+
y.serialize(sparsetable<int>::NopointerSerializer(), fp);
|
386
|
+
fclose(fp);
|
387
|
+
}
|
388
|
+
fp = fopen(file, "rb");
|
389
|
+
if ( fp == NULL ) {
|
390
|
+
out += snprintf(out, LEFT, "Can't open %s, skipping disk read...\n", file);
|
391
|
+
} else {
|
392
|
+
sparsetable<int> y2;
|
393
|
+
y2.unserialize(sparsetable<int>::NopointerSerializer(), fp);
|
394
|
+
fclose(fp);
|
395
|
+
|
396
|
+
for ( sparsetable<int>::const_iterator it = y2.begin(); it != y2.end(); ++it ) {
|
397
|
+
if ( y2.test(it) )
|
398
|
+
out += snprintf(out, LEFT, "y2[%lu] is %d\n", UL(it - y2.begin()), *it);
|
399
|
+
}
|
400
|
+
out += snprintf(out, LEFT, "That's %lu set buckets\n", UL(y2.num_nonempty()));
|
401
|
+
}
|
402
|
+
unlink(file);
|
357
403
|
}
|
358
404
|
|
359
405
|
// Test sparsetable with a non-POD type, std::string
|
@@ -462,7 +508,7 @@ void ResetAllocatorCounters() {
|
|
462
508
|
template <class T> class instrumented_allocator {
|
463
509
|
public:
|
464
510
|
typedef T value_type;
|
465
|
-
typedef
|
511
|
+
typedef uint16 size_type;
|
466
512
|
typedef ptrdiff_t difference_type;
|
467
513
|
|
468
514
|
typedef T* pointer;
|
@@ -758,6 +804,30 @@ static const char g_expected[] = (
|
|
758
804
|
"first non-empty x: 10\n"
|
759
805
|
"x.begin() == x.begin() + 1 - 1? yes\n"
|
760
806
|
"z.begin() != z.end()? no\n"
|
807
|
+
"get_pos() for const nonempty_iterator: 0 == 0\n"
|
808
|
+
"get_pos() for const nonempty_iterator: 9 == 9\n"
|
809
|
+
"get_pos() for const nonempty_iterator: 18 == 18\n"
|
810
|
+
"get_pos() for const nonempty_iterator: 27 == 27\n"
|
811
|
+
"get_pos() for const nonempty_iterator: 36 == 36\n"
|
812
|
+
"get_pos() for const nonempty_iterator: 45 == 45\n"
|
813
|
+
"get_pos() for const nonempty_iterator: 54 == 54\n"
|
814
|
+
"get_pos() for const nonempty_iterator: 63 == 63\n"
|
815
|
+
"get_pos() for const nonempty_iterator: 72 == 72\n"
|
816
|
+
"get_pos() for const nonempty_iterator: 81 == 81\n"
|
817
|
+
"get_pos() for const nonempty_iterator: 90 == 90\n"
|
818
|
+
"get_pos() for const nonempty_iterator: 99 == 99\n"
|
819
|
+
"get_pos() for nonempty_iterator: 0 == 0\n"
|
820
|
+
"get_pos() for nonempty_iterator: 9 == 9\n"
|
821
|
+
"get_pos() for nonempty_iterator: 18 == 18\n"
|
822
|
+
"get_pos() for nonempty_iterator: 27 == 27\n"
|
823
|
+
"get_pos() for nonempty_iterator: 36 == 36\n"
|
824
|
+
"get_pos() for nonempty_iterator: 45 == 45\n"
|
825
|
+
"get_pos() for nonempty_iterator: 54 == 54\n"
|
826
|
+
"get_pos() for nonempty_iterator: 63 == 63\n"
|
827
|
+
"get_pos() for nonempty_iterator: 72 == 72\n"
|
828
|
+
"get_pos() for nonempty_iterator: 81 == 81\n"
|
829
|
+
"get_pos() for nonempty_iterator: 90 == 90\n"
|
830
|
+
"get_pos() for nonempty_iterator: 99 == 99\n"
|
761
831
|
"x has 3/7 buckets, y 4/70, z 0/0\n"
|
762
832
|
"y shrank and grew: it's now 2/70\n"
|
763
833
|
"y[12] = -12, y.get(12) = -12\n"
|
@@ -803,6 +873,19 @@ static const char g_expected[] = (
|
|
803
873
|
"y2[37] is -37\n"
|
804
874
|
"y2[9898] is -9898\n"
|
805
875
|
"That's 12 set buckets\n"
|
876
|
+
"y2[10] is -10\n"
|
877
|
+
"y2[11] is -11\n"
|
878
|
+
"y2[13] is -13\n"
|
879
|
+
"y2[14] is -14\n"
|
880
|
+
"y2[30] is -30\n"
|
881
|
+
"y2[31] is -31\n"
|
882
|
+
"y2[32] is -32\n"
|
883
|
+
"y2[33] is -33\n"
|
884
|
+
"y2[35] is -35\n"
|
885
|
+
"y2[36] is -36\n"
|
886
|
+
"y2[37] is -37\n"
|
887
|
+
"y2[9898] is -9898\n"
|
888
|
+
"That's 12 set buckets\n"
|
806
889
|
"string test\n"
|
807
890
|
"x[0]: \n"
|
808
891
|
"x[1]: \n"
|
@@ -873,7 +956,10 @@ static const char g_expected[] = (
|
|
873
956
|
);
|
874
957
|
|
875
958
|
// defined at bottom of file for ease of maintainence
|
876
|
-
int main(int
|
959
|
+
int main(int argc, char **argv) { // though we ignore the args
|
960
|
+
(void)argc;
|
961
|
+
(void)argv;
|
962
|
+
|
877
963
|
TestInt();
|
878
964
|
TestString();
|
879
965
|
TestAllocator();
|