google_hash 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. data/README +21 -0
  2. data/Rakefile +11 -0
  3. data/VERSION +1 -0
  4. data/ext/extconf.rb +15 -0
  5. data/ext/go.cpp +109 -0
  6. data/ext/sparsehash-1.5.2/AUTHORS +2 -0
  7. data/ext/sparsehash-1.5.2/COPYING +28 -0
  8. data/ext/sparsehash-1.5.2/ChangeLog +167 -0
  9. data/ext/sparsehash-1.5.2/INSTALL +236 -0
  10. data/ext/sparsehash-1.5.2/Makefile.am +157 -0
  11. data/ext/sparsehash-1.5.2/Makefile.in +1019 -0
  12. data/ext/sparsehash-1.5.2/NEWS +0 -0
  13. data/ext/sparsehash-1.5.2/README +149 -0
  14. data/ext/sparsehash-1.5.2/README.windows +25 -0
  15. data/ext/sparsehash-1.5.2/TODO +28 -0
  16. data/ext/sparsehash-1.5.2/aclocal.m4 +868 -0
  17. data/ext/sparsehash-1.5.2/compile +99 -0
  18. data/ext/sparsehash-1.5.2/config.guess +1516 -0
  19. data/ext/sparsehash-1.5.2/config.sub +1626 -0
  20. data/ext/sparsehash-1.5.2/configure +8054 -0
  21. data/ext/sparsehash-1.5.2/configure.ac +74 -0
  22. data/ext/sparsehash-1.5.2/depcomp +530 -0
  23. data/ext/sparsehash-1.5.2/doc/dense_hash_map.html +1591 -0
  24. data/ext/sparsehash-1.5.2/doc/dense_hash_set.html +1445 -0
  25. data/ext/sparsehash-1.5.2/doc/designstyle.css +115 -0
  26. data/ext/sparsehash-1.5.2/doc/implementation.html +365 -0
  27. data/ext/sparsehash-1.5.2/doc/index.html +69 -0
  28. data/ext/sparsehash-1.5.2/doc/performance.html +96 -0
  29. data/ext/sparsehash-1.5.2/doc/sparse_hash_map.html +1527 -0
  30. data/ext/sparsehash-1.5.2/doc/sparse_hash_set.html +1376 -0
  31. data/ext/sparsehash-1.5.2/doc/sparsetable.html +1393 -0
  32. data/ext/sparsehash-1.5.2/experimental/Makefile +9 -0
  33. data/ext/sparsehash-1.5.2/experimental/README +14 -0
  34. data/ext/sparsehash-1.5.2/experimental/example.c +54 -0
  35. data/ext/sparsehash-1.5.2/experimental/libchash.c +1537 -0
  36. data/ext/sparsehash-1.5.2/experimental/libchash.h +252 -0
  37. data/ext/sparsehash-1.5.2/google-sparsehash.sln +47 -0
  38. data/ext/sparsehash-1.5.2/install-sh +323 -0
  39. data/ext/sparsehash-1.5.2/m4/acx_pthread.m4 +363 -0
  40. data/ext/sparsehash-1.5.2/m4/google_namespace.m4 +42 -0
  41. data/ext/sparsehash-1.5.2/m4/namespaces.m4 +15 -0
  42. data/ext/sparsehash-1.5.2/m4/stl_hash.m4 +70 -0
  43. data/ext/sparsehash-1.5.2/m4/stl_hash_fun.m4 +36 -0
  44. data/ext/sparsehash-1.5.2/m4/stl_namespace.m4 +25 -0
  45. data/ext/sparsehash-1.5.2/missing +360 -0
  46. data/ext/sparsehash-1.5.2/mkinstalldirs +158 -0
  47. data/ext/sparsehash-1.5.2/packages/deb.sh +74 -0
  48. data/ext/sparsehash-1.5.2/packages/deb/README +7 -0
  49. data/ext/sparsehash-1.5.2/packages/deb/changelog +107 -0
  50. data/ext/sparsehash-1.5.2/packages/deb/compat +1 -0
  51. data/ext/sparsehash-1.5.2/packages/deb/control +17 -0
  52. data/ext/sparsehash-1.5.2/packages/deb/copyright +35 -0
  53. data/ext/sparsehash-1.5.2/packages/deb/docs +16 -0
  54. data/ext/sparsehash-1.5.2/packages/deb/rules +117 -0
  55. data/ext/sparsehash-1.5.2/packages/deb/sparsehash.dirs +2 -0
  56. data/ext/sparsehash-1.5.2/packages/deb/sparsehash.install +2 -0
  57. data/ext/sparsehash-1.5.2/packages/rpm.sh +86 -0
  58. data/ext/sparsehash-1.5.2/packages/rpm/rpm.spec +61 -0
  59. data/ext/sparsehash-1.5.2/src/config.h.in +131 -0
  60. data/ext/sparsehash-1.5.2/src/config.h.include +23 -0
  61. data/ext/sparsehash-1.5.2/src/google/dense_hash_map +310 -0
  62. data/ext/sparsehash-1.5.2/src/google/dense_hash_set +287 -0
  63. data/ext/sparsehash-1.5.2/src/google/sparse_hash_map +294 -0
  64. data/ext/sparsehash-1.5.2/src/google/sparse_hash_set +275 -0
  65. data/ext/sparsehash-1.5.2/src/google/sparsehash/densehashtable.h +1062 -0
  66. data/ext/sparsehash-1.5.2/src/google/sparsehash/sparsehashtable.h +1015 -0
  67. data/ext/sparsehash-1.5.2/src/google/sparsetable +1468 -0
  68. data/ext/sparsehash-1.5.2/src/google/type_traits.h +250 -0
  69. data/ext/sparsehash-1.5.2/src/hashtable_unittest.cc +1375 -0
  70. data/ext/sparsehash-1.5.2/src/simple_test.cc +103 -0
  71. data/ext/sparsehash-1.5.2/src/sparsetable_unittest.cc +696 -0
  72. data/ext/sparsehash-1.5.2/src/time_hash_map.cc +488 -0
  73. data/ext/sparsehash-1.5.2/src/type_traits_unittest.cc +492 -0
  74. data/ext/sparsehash-1.5.2/src/windows/config.h +149 -0
  75. data/ext/sparsehash-1.5.2/src/windows/google/sparsehash/sparseconfig.h +32 -0
  76. data/ext/sparsehash-1.5.2/src/windows/port.cc +63 -0
  77. data/ext/sparsehash-1.5.2/src/windows/port.h +81 -0
  78. data/ext/sparsehash-1.5.2/src/words +8944 -0
  79. data/ext/sparsehash-1.5.2/vsprojects/hashtable_unittest/hashtable_unittest.vcproj +187 -0
  80. data/ext/sparsehash-1.5.2/vsprojects/sparsetable_unittest/sparsetable_unittest.vcproj +172 -0
  81. data/ext/sparsehash-1.5.2/vsprojects/time_hash_map/time_hash_map.vcproj +187 -0
  82. data/ext/sparsehash-1.5.2/vsprojects/type_traits_unittest/type_traits_unittest.vcproj +169 -0
  83. data/ext/test.rb +10 -0
  84. data/test/spec.go +70 -0
  85. metadata +147 -0
@@ -0,0 +1,61 @@
1
+ %define RELEASE 1
2
+ %define rel %{?CUSTOM_RELEASE} %{!?CUSTOM_RELEASE:%RELEASE}
3
+ %define prefix /usr
4
+
5
+ Name: %NAME
6
+ Summary: hash_map and hash_set classes with minimal space overhead
7
+ Version: %VERSION
8
+ Release: %rel
9
+ Group: Development/Libraries
10
+ URL: http://code.google.com/p/google-sparsehash
11
+ License: BSD
12
+ Vendor: Google
13
+ Packager: Google <opensource@google.com>
14
+ Source: http://%{NAME}.googlecode.com/files/%{NAME}-%{VERSION}.tar.gz
15
+ Distribution: Redhat 7 and above.
16
+ Buildroot: %{_tmppath}/%{name}-root
17
+ Prefix: %prefix
18
+ Buildarch: noarch
19
+
20
+ %description
21
+ The %name package contains several hash-map implementations, similar
22
+ in API to the SGI hash_map class, but with different performance
23
+ characteristics. sparse_hash_map uses very little space overhead: 1-2
24
+ bits per entry. dense_hash_map is typically faster than the default
25
+ SGI STL implementation. This package also includes hash-set analogues
26
+ of these classes.
27
+
28
+ %changelog
29
+ * Wed Apr 22 2009 <opensource@google.com>
30
+ - Change build rule to use %configure instead of ./configure
31
+ - Change install to use DESTDIR instead of prefix for make install
32
+ - Use wildcards for doc/ and lib/ directories
33
+ - Use {_includedir} instead of {prefix}/include
34
+
35
+ * Fri Jan 14 2005 <opensource@google.com>
36
+ - First draft
37
+
38
+ %prep
39
+ %setup
40
+
41
+ %build
42
+ # I can't use '% configure', because it defines -m32 which breaks on
43
+ # my development environment for some reason. But I do take
44
+ # as much from % configure (in /usr/lib/rpm/macros) as I can.
45
+ ./configure --prefix=%{_prefix} --exec-prefix=%{_exec_prefix} --bindir=%{_bindir} --sbindir=%{_sbindir} --sysconfdir=%{_sysconfdir} --datadir=%{_datadir} --includedir=%{_includedir} --libdir=%{_libdir} --libexecdir=%{_libexecdir} --localstatedir=%{_localstatedir} --sharedstatedir=%{_sharedstatedir} --mandir=%{_mandir} --infodir=%{_infodir}
46
+ make
47
+
48
+ %install
49
+ rm -rf $RPM_BUILD_ROOT
50
+ make DESTDIR=$RPM_BUILD_ROOT install
51
+
52
+ %clean
53
+ rm -rf $RPM_BUILD_ROOT
54
+
55
+ %files
56
+ %defattr(-,root,root)
57
+
58
+ %docdir %{prefix}/share/doc/%{NAME}-%{VERSION}
59
+ %{prefix}/share/doc/%{NAME}-%{VERSION}/*
60
+
61
+ %{_includedir}/google
@@ -0,0 +1,131 @@
1
+ /* src/config.h.in. Generated from configure.ac by autoheader. */
2
+
3
+ /* Namespace for Google classes */
4
+ #undef GOOGLE_NAMESPACE
5
+
6
+ /* the location of the header defining hash functions */
7
+ #undef HASH_FUN_H
8
+
9
+ /* the location of <unordered_map> or <hash_map> */
10
+ #undef HASH_MAP_H
11
+
12
+ /* the namespace of the hash<> function */
13
+ #undef HASH_NAMESPACE
14
+
15
+ /* the location of <unordered_set> or <hash_set> */
16
+ #undef HASH_SET_H
17
+
18
+ /* Define to 1 if you have the <google/malloc_extension.h> header file. */
19
+ #undef HAVE_GOOGLE_MALLOC_EXTENSION_H
20
+
21
+ /* define if the compiler has hash_map */
22
+ #undef HAVE_HASH_MAP
23
+
24
+ /* define if the compiler has hash_set */
25
+ #undef HAVE_HASH_SET
26
+
27
+ /* Define to 1 if you have the <inttypes.h> header file. */
28
+ #undef HAVE_INTTYPES_H
29
+
30
+ /* Define to 1 if the system has the type `long long'. */
31
+ #undef HAVE_LONG_LONG
32
+
33
+ /* Define to 1 if you have the `memcpy' function. */
34
+ #undef HAVE_MEMCPY
35
+
36
+ /* Define to 1 if you have the `memmove' function. */
37
+ #undef HAVE_MEMMOVE
38
+
39
+ /* Define to 1 if you have the <memory.h> header file. */
40
+ #undef HAVE_MEMORY_H
41
+
42
+ /* define if the compiler implements namespaces */
43
+ #undef HAVE_NAMESPACES
44
+
45
+ /* Define if you have POSIX threads libraries and header files. */
46
+ #undef HAVE_PTHREAD
47
+
48
+ /* Define to 1 if you have the <stdint.h> header file. */
49
+ #undef HAVE_STDINT_H
50
+
51
+ /* Define to 1 if you have the <stdlib.h> header file. */
52
+ #undef HAVE_STDLIB_H
53
+
54
+ /* Define to 1 if you have the <strings.h> header file. */
55
+ #undef HAVE_STRINGS_H
56
+
57
+ /* Define to 1 if you have the <string.h> header file. */
58
+ #undef HAVE_STRING_H
59
+
60
+ /* Define to 1 if you have the <sys/resource.h> header file. */
61
+ #undef HAVE_SYS_RESOURCE_H
62
+
63
+ /* Define to 1 if you have the <sys/stat.h> header file. */
64
+ #undef HAVE_SYS_STAT_H
65
+
66
+ /* Define to 1 if you have the <sys/time.h> header file. */
67
+ #undef HAVE_SYS_TIME_H
68
+
69
+ /* Define to 1 if you have the <sys/types.h> header file. */
70
+ #undef HAVE_SYS_TYPES_H
71
+
72
+ /* Define to 1 if you have the <sys/utsname.h> header file. */
73
+ #undef HAVE_SYS_UTSNAME_H
74
+
75
+ /* Define to 1 if the system has the type `uint16_t'. */
76
+ #undef HAVE_UINT16_T
77
+
78
+ /* Define to 1 if you have the <unistd.h> header file. */
79
+ #undef HAVE_UNISTD_H
80
+
81
+ /* define if the compiler supports unordered_{map,set} */
82
+ #undef HAVE_UNORDERED_MAP
83
+
84
+ /* Define to 1 if the system has the type `u_int16_t'. */
85
+ #undef HAVE_U_INT16_T
86
+
87
+ /* Define to 1 if the system has the type `__uint16'. */
88
+ #undef HAVE___UINT16
89
+
90
+ /* Name of package */
91
+ #undef PACKAGE
92
+
93
+ /* Define to the address where bug reports for this package should be sent. */
94
+ #undef PACKAGE_BUGREPORT
95
+
96
+ /* Define to the full name of this package. */
97
+ #undef PACKAGE_NAME
98
+
99
+ /* Define to the full name and version of this package. */
100
+ #undef PACKAGE_STRING
101
+
102
+ /* Define to the one symbol short name of this package. */
103
+ #undef PACKAGE_TARNAME
104
+
105
+ /* Define to the version of this package. */
106
+ #undef PACKAGE_VERSION
107
+
108
+ /* Define to necessary symbol if this constant uses a non-standard name on
109
+ your system. */
110
+ #undef PTHREAD_CREATE_JOINABLE
111
+
112
+ /* The system-provided hash function including the namespace. */
113
+ #undef SPARSEHASH_HASH
114
+
115
+ /* The system-provided hash function, in namespace HASH_NAMESPACE. */
116
+ #undef SPARSEHASH_HASH_NO_NAMESPACE
117
+
118
+ /* Define to 1 if you have the ANSI C header files. */
119
+ #undef STDC_HEADERS
120
+
121
+ /* the namespace where STL code like vector<> is defined */
122
+ #undef STL_NAMESPACE
123
+
124
+ /* Version number of package */
125
+ #undef VERSION
126
+
127
+ /* Stops putting the code inside the Google namespace */
128
+ #undef _END_GOOGLE_NAMESPACE_
129
+
130
+ /* Puts following code inside the Google namespace */
131
+ #undef _START_GOOGLE_NAMESPACE_
@@ -0,0 +1,23 @@
1
+ /***
2
+ *** These are #defines that autoheader puts in config.h.in that we
3
+ *** want to show up in sparseconfig.h, the minimal config.h file
4
+ *** #included by all our .h files. The reason we don't take
5
+ *** everything that autoheader emits is that we have to include a
6
+ *** config.h in installed header files, and we want to minimize the
7
+ *** number of #defines we make so as to not pollute the namespace.
8
+ ***/
9
+ GOOGLE_NAMESPACE
10
+ HASH_NAMESPACE
11
+ HASH_FUN_H
12
+ SPARSEHASH_HASH
13
+ HAVE_UINT16_T
14
+ HAVE_U_INT16_T
15
+ HAVE___UINT16
16
+ HAVE_LONG_LONG
17
+ HAVE_SYS_TYPES_H
18
+ HAVE_STDINT_H
19
+ HAVE_INTTYPES_H
20
+ HAVE_MEMCPY
21
+ STL_NAMESPACE
22
+ _END_GOOGLE_NAMESPACE_
23
+ _START_GOOGLE_NAMESPACE_
@@ -0,0 +1,310 @@
1
+ // Copyright (c) 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
+ // Author: Craig Silverstein
32
+ //
33
+ // This is just a very thin wrapper over densehashtable.h, just
34
+ // like sgi stl's stl_hash_map is a very thin wrapper over
35
+ // stl_hashtable. The major thing we define is operator[], because
36
+ // we have a concept of a data_type which stl_hashtable doesn't
37
+ // (it only has a key and a value).
38
+ //
39
+ // NOTE: this is exactly like sparse_hash_map.h, with the word
40
+ // "sparse" replaced by "dense", except for the addition of
41
+ // set_empty_key().
42
+ //
43
+ // YOU MUST CALL SET_EMPTY_KEY() IMMEDIATELY AFTER CONSTRUCTION.
44
+ //
45
+ // Otherwise your program will die in mysterious ways.
46
+ //
47
+ // In other respects, we adhere mostly to the STL semantics for
48
+ // hash-map. One important exception is that insert() invalidates
49
+ // iterators entirely. On the plus side, though, erase() doesn't
50
+ // invalidate iterators at all, or even change the ordering of elements.
51
+ //
52
+ // Here are a few "power user" tips:
53
+ //
54
+ // 1) set_deleted_key():
55
+ // If you want to use erase() you *must* call set_deleted_key(),
56
+ // in addition to set_empty_key(), after construction.
57
+ // The deleted and empty keys must differ.
58
+ //
59
+ // 2) resize(0):
60
+ // When an item is deleted, its memory isn't freed right
61
+ // away. This allows you to iterate over a hashtable,
62
+ // and call erase(), without invalidating the iterator.
63
+ // To force the memory to be freed, call resize(0).
64
+ // For tr1 compatibility, this can also be called as rehash(0).
65
+ //
66
+ // 3) min_load_factor(0.0)
67
+ // Setting the minimum load factor to 0.0 guarantees that
68
+ // the hash table will never shrink.
69
+ //
70
+ // Guide to what kind of hash_map to use:
71
+ // (1) dense_hash_map: fastest, uses the most memory
72
+ // (2) sparse_hash_map: slowest, uses the least memory
73
+ // (3) hash_map (STL): in the middle
74
+ // Typically I use sparse_hash_map when I care about space and/or when
75
+ // I need to save the hashtable on disk. I use hash_map otherwise. I
76
+ // don't personally use dense_hash_set ever; some people use it for
77
+ // small sets with lots of lookups.
78
+ //
79
+ // - dense_hash_map has, typically, a factor of 2 memory overhead (if your
80
+ // data takes up X bytes, the hash_map uses X more bytes in overhead).
81
+ // - sparse_hash_map has about 2 bits overhead per entry.
82
+ // - sparse_hash_map can be 3-7 times slower than the others for lookup and,
83
+ // especially, inserts. See time_hash_map.cc for details.
84
+ //
85
+ // See /usr/(local/)?doc/sparsehash-*/dense_hash_map.html
86
+ // for information about how to use this class.
87
+
88
+ #ifndef _DENSE_HASH_MAP_H_
89
+ #define _DENSE_HASH_MAP_H_
90
+
91
+ #include <google/sparsehash/sparseconfig.h>
92
+ #include <stdio.h> // for FILE * in read()/write()
93
+ #include <algorithm> // for the default template args
94
+ #include <functional> // for equal_to
95
+ #include <memory> // for alloc<>
96
+ #include <utility> // for pair<>
97
+ #include HASH_FUN_H // defined in config.h
98
+ #include <google/sparsehash/densehashtable.h>
99
+
100
+
101
+ _START_GOOGLE_NAMESPACE_
102
+
103
+ using STL_NAMESPACE::pair;
104
+
105
+ template <class Key, class T,
106
+ class HashFcn = SPARSEHASH_HASH<Key>, // defined in sparseconfig.h
107
+ class EqualKey = STL_NAMESPACE::equal_to<Key>,
108
+ class Alloc = STL_NAMESPACE::allocator<T> >
109
+ class dense_hash_map {
110
+ private:
111
+ // Apparently select1st is not stl-standard, so we define our own
112
+ struct SelectKey {
113
+ const Key& operator()(const pair<const Key, T>& p) const {
114
+ return p.first;
115
+ }
116
+ };
117
+ struct SetKey {
118
+ void operator()(pair<const Key, T>* value, const Key& new_key) const {
119
+ *const_cast<Key*>(&value->first) = new_key;
120
+ // It would be nice to clear the rest of value here as well, in
121
+ // case it's taking up a lot of memory. We do this by clearing
122
+ // the value. This assumes T has a zero-arg constructor!
123
+ value->second = T();
124
+ }
125
+ };
126
+
127
+ // The actual data
128
+ typedef dense_hashtable<pair<const Key, T>, Key, HashFcn,
129
+ SelectKey, SetKey, EqualKey, Alloc> ht;
130
+ ht rep;
131
+
132
+ public:
133
+ typedef typename ht::key_type key_type;
134
+ typedef T data_type;
135
+ typedef T mapped_type;
136
+ typedef typename ht::value_type value_type;
137
+ typedef typename ht::hasher hasher;
138
+ typedef typename ht::key_equal key_equal;
139
+ typedef Alloc allocator_type;
140
+
141
+ typedef typename ht::size_type size_type;
142
+ typedef typename ht::difference_type difference_type;
143
+ typedef typename ht::pointer pointer;
144
+ typedef typename ht::const_pointer const_pointer;
145
+ typedef typename ht::reference reference;
146
+ typedef typename ht::const_reference const_reference;
147
+
148
+ typedef typename ht::iterator iterator;
149
+ typedef typename ht::const_iterator const_iterator;
150
+ typedef typename ht::local_iterator local_iterator;
151
+ typedef typename ht::const_local_iterator const_local_iterator;
152
+
153
+ // Iterator functions
154
+ iterator begin() { return rep.begin(); }
155
+ iterator end() { return rep.end(); }
156
+ const_iterator begin() const { return rep.begin(); }
157
+ const_iterator end() const { return rep.end(); }
158
+
159
+
160
+ // These come from tr1's unordered_map. For us, a bucket has 0 or 1 elements.
161
+ local_iterator begin(size_type i) { return rep.begin(i); }
162
+ local_iterator end(size_type i) { return rep.end(i); }
163
+ const_local_iterator begin(size_type i) const { return rep.begin(i); }
164
+ const_local_iterator end(size_type i) const { return rep.end(i); }
165
+
166
+ // Accessor functions
167
+ // TODO(csilvers): implement Alloc get_allocator() const;
168
+ hasher hash_funct() const { return rep.hash_funct(); }
169
+ hasher hash_function() const { return hash_funct(); }
170
+ key_equal key_eq() const { return rep.key_eq(); }
171
+
172
+
173
+ // Constructors
174
+ explicit dense_hash_map(size_type expected_max_items_in_table = 0,
175
+ const hasher& hf = hasher(),
176
+ const key_equal& eql = key_equal())
177
+ : rep(expected_max_items_in_table, hf, eql) { }
178
+
179
+ template <class InputIterator>
180
+ dense_hash_map(InputIterator f, InputIterator l,
181
+ size_type expected_max_items_in_table = 0,
182
+ const hasher& hf = hasher(),
183
+ const key_equal& eql = key_equal())
184
+ : rep(expected_max_items_in_table, hf, eql) {
185
+ rep.insert(f, l);
186
+ }
187
+ // We use the default copy constructor
188
+ // We use the default operator=()
189
+ // We use the default destructor
190
+
191
+ void clear() { rep.clear(); }
192
+ // This clears the hash map without resizing it down to the minimum
193
+ // bucket count, but rather keeps the number of buckets constant
194
+ void clear_no_resize() { rep.clear_no_resize(); }
195
+ void swap(dense_hash_map& hs) { rep.swap(hs.rep); }
196
+
197
+
198
+ // Functions concerning size
199
+ size_type size() const { return rep.size(); }
200
+ size_type max_size() const { return rep.max_size(); }
201
+ bool empty() const { return rep.empty(); }
202
+ size_type bucket_count() const { return rep.bucket_count(); }
203
+ size_type max_bucket_count() const { return rep.max_bucket_count(); }
204
+
205
+ // These are tr1 methods. bucket() is the bucket the key is or would be in.
206
+ size_type bucket_size(size_type i) const { return rep.bucket_size(i); }
207
+ size_type bucket(const key_type& key) const { return rep.bucket(key); }
208
+ float load_factor() const {
209
+ return size() * 1.0f / bucket_count();
210
+ }
211
+ float max_load_factor() const {
212
+ float shrink, grow;
213
+ rep.get_resizing_parameters(&shrink, &grow);
214
+ return grow;
215
+ }
216
+ void max_load_factor(float new_grow) {
217
+ float shrink, grow;
218
+ rep.get_resizing_parameters(&shrink, &grow);
219
+ rep.set_resizing_parameters(shrink, new_grow);
220
+ }
221
+ // These aren't tr1 methods but perhaps ought to be.
222
+ float min_load_factor() const {
223
+ float shrink, grow;
224
+ rep.get_resizing_parameters(&shrink, &grow);
225
+ return shrink;
226
+ }
227
+ void min_load_factor(float new_shrink) {
228
+ float shrink, grow;
229
+ rep.get_resizing_parameters(&shrink, &grow);
230
+ rep.set_resizing_parameters(new_shrink, grow);
231
+ }
232
+ // Deprecated; use min_load_factor() or max_load_factor() instead.
233
+ void set_resizing_parameters(float shrink, float grow) {
234
+ return rep.set_resizing_parameters(shrink, grow);
235
+ }
236
+
237
+ void resize(size_type hint) { rep.resize(hint); }
238
+ void rehash(size_type hint) { resize(hint); } // the tr1 name
239
+
240
+ // Lookup routines
241
+ iterator find(const key_type& key) { return rep.find(key); }
242
+ const_iterator find(const key_type& key) const { return rep.find(key); }
243
+
244
+ data_type& operator[](const key_type& key) { // This is our value-add!
245
+ iterator it = find(key);
246
+ if (it != end()) {
247
+ return it->second;
248
+ } else {
249
+ return insert(value_type(key, data_type())).first->second;
250
+ }
251
+ }
252
+
253
+ size_type count(const key_type& key) const { return rep.count(key); }
254
+
255
+ pair<iterator, iterator> equal_range(const key_type& key) {
256
+ return rep.equal_range(key);
257
+ }
258
+ pair<const_iterator, const_iterator> equal_range(const key_type& key) const {
259
+ return rep.equal_range(key);
260
+ }
261
+
262
+ // Insertion routines
263
+ pair<iterator, bool> insert(const value_type& obj) { return rep.insert(obj); }
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
+
271
+ // Deletion and empty routines
272
+ // THESE ARE NON-STANDARD! I make you specify an "impossible" key
273
+ // value to identify deleted and empty buckets. You can change the
274
+ // deleted key as time goes on, or get rid of it entirely to be insert-only.
275
+ void set_empty_key(const key_type& key) { // YOU MUST CALL THIS!
276
+ rep.set_empty_key(value_type(key, data_type())); // rep wants a value
277
+ }
278
+ void set_deleted_key(const key_type& key) {
279
+ rep.set_deleted_key(key);
280
+ }
281
+ void clear_deleted_key() { rep.clear_deleted_key(); }
282
+
283
+ // These are standard
284
+ size_type erase(const key_type& key) { return rep.erase(key); }
285
+ void erase(iterator it) { rep.erase(it); }
286
+ void erase(iterator f, iterator l) { rep.erase(f, l); }
287
+
288
+
289
+ // Comparison
290
+ bool operator==(const dense_hash_map& hs) const { return rep == hs.rep; }
291
+ bool operator!=(const dense_hash_map& hs) const { return rep != hs.rep; }
292
+
293
+
294
+ // I/O -- this is an add-on for writing metainformation to disk
295
+ bool write_metadata(FILE *fp) { return rep.write_metadata(fp); }
296
+ bool read_metadata(FILE *fp) { return rep.read_metadata(fp); }
297
+ bool write_nopointer_data(FILE *fp) { return rep.write_nopointer_data(fp); }
298
+ bool read_nopointer_data(FILE *fp) { return rep.read_nopointer_data(fp); }
299
+ };
300
+
301
+ // We need a global swap as well
302
+ template <class Key, class T, class HashFcn, class EqualKey, class Alloc>
303
+ inline void swap(dense_hash_map<Key, T, HashFcn, EqualKey, Alloc>& hm1,
304
+ dense_hash_map<Key, T, HashFcn, EqualKey, Alloc>& hm2) {
305
+ hm1.swap(hm2);
306
+ }
307
+
308
+ _END_GOOGLE_NAMESPACE_
309
+
310
+ #endif /* _DENSE_HASH_MAP_H_ */