libstdc++: ranged_hash_fn.hpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42#ifndef PB_DS_RANGED_HASH_FN_HPP

43#define PB_DS_RANGED_HASH_FN_HPP

44

48

50{

51 namespace detail

52 {

53

54 template<typename Key, typename Hash_Fn, typename _Alloc,

55 typename Comb_Hash_Fn, bool Store_Hash>

57

58#define PB_DS_CLASS_T_DEC \

59 template<typename Key, typename Hash_Fn, typename _Alloc, \

60 typename Comb_Hash_Fn>

61

62#define PB_DS_CLASS_C_DEC \

63 ranged_hash_fn<Key, Hash_Fn, _Alloc, Comb_Hash_Fn, false>

64

65

66

67

68

69

70 template<typename Key, typename Hash_Fn, typename _Alloc,

71 typename Comb_Hash_Fn>

72 class ranged_hash_fn< Key, Hash_Fn, _Alloc, Comb_Hash_Fn, false>

73 : public Hash_Fn, public Comb_Hash_Fn

74 {

75 protected:

76 typedef typename _Alloc::size_type size_type;

77 typedef Hash_Fn hash_fn_base;

78 typedef Comb_Hash_Fn comb_hash_fn_base;

79 typedef typename rebind_traits<_Alloc, Key>::const_reference

80 key_const_reference;

81

83

85

86 ranged_hash_fn(size_type, const Hash_Fn&, const Comb_Hash_Fn&);

87

88 void

89 swap(PB_DS_CLASS_C_DEC&);

90

91 void

92 notify_resized(size_type);

93

94 inline size_type

95 operator()(key_const_reference) const;

96 };

97

98 PB_DS_CLASS_T_DEC

99 PB_DS_CLASS_C_DEC::

100 ranged_hash_fn(size_type size)

101 { Comb_Hash_Fn::notify_resized(size); }

102

103 PB_DS_CLASS_T_DEC

104 PB_DS_CLASS_C_DEC::

105 ranged_hash_fn(size_type size, const Hash_Fn& r_hash_fn)

106 : Hash_Fn(r_hash_fn)

107 { Comb_Hash_Fn::notify_resized(size); }

108

109 PB_DS_CLASS_T_DEC

110 PB_DS_CLASS_C_DEC::

111 ranged_hash_fn(size_type size, const Hash_Fn& r_hash_fn,

112 const Comb_Hash_Fn& r_comb_hash_fn)

113 : Hash_Fn(r_hash_fn), Comb_Hash_Fn(r_comb_hash_fn)

114 { comb_hash_fn_base::notify_resized(size); }

115

116 PB_DS_CLASS_T_DEC

117 void

118 PB_DS_CLASS_C_DEC::

119 swap(PB_DS_CLASS_C_DEC& other)

120 {

121 comb_hash_fn_base::swap(other);

122 std::swap((Hash_Fn& )(*this), (Hash_Fn& )other);

123 }

124

125 PB_DS_CLASS_T_DEC

126 void

127 PB_DS_CLASS_C_DEC::

128 notify_resized(size_type size)

129 { comb_hash_fn_base::notify_resized(size); }

130

131 PB_DS_CLASS_T_DEC

132 inline typename PB_DS_CLASS_C_DEC::size_type

133 PB_DS_CLASS_C_DEC::

134 operator()(key_const_reference r_key) const

135 { return (comb_hash_fn_base::operator()(hash_fn_base::operator()(r_key)));}

136

137#undef PB_DS_CLASS_T_DEC

138#undef PB_DS_CLASS_C_DEC

139

140#define PB_DS_CLASS_T_DEC \

141 template<typename Key, typename Hash_Fn, typename _Alloc, \

142 typename Comb_Hash_Fn>

143

144#define PB_DS_CLASS_C_DEC \

145 ranged_hash_fn<Key,Hash_Fn, _Alloc, Comb_Hash_Fn, true>

146

147

148

149

150

151

152 template<typename Key, typename Hash_Fn, typename _Alloc,

153 typename Comb_Hash_Fn>

155 : public Hash_Fn, public Comb_Hash_Fn

156 {

157 protected:

158 typedef typename _Alloc::size_type size_type;

160 typedef Hash_Fn hash_fn_base;

161 typedef Comb_Hash_Fn comb_hash_fn_base;

162 typedef typename rebind_traits<_Alloc, Key>::const_reference

163 key_const_reference;

164

166

168

169 ranged_hash_fn(size_type, const Hash_Fn&, const Comb_Hash_Fn&);

170

171 void

172 swap(PB_DS_CLASS_C_DEC&);

173

174 void

175 notify_resized(size_type);

176

178 operator()(key_const_reference) const;

179

181 operator()(key_const_reference, size_type) const;

182 };

183

184 PB_DS_CLASS_T_DEC

185 PB_DS_CLASS_C_DEC::

186 ranged_hash_fn(size_type size)

187 { Comb_Hash_Fn::notify_resized(size); }

188

189 PB_DS_CLASS_T_DEC

190 PB_DS_CLASS_C_DEC::

191 ranged_hash_fn(size_type size, const Hash_Fn& r_hash_fn) :

192 Hash_Fn(r_hash_fn)

193 { Comb_Hash_Fn::notify_resized(size); }

194

195 PB_DS_CLASS_T_DEC

196 PB_DS_CLASS_C_DEC::

197 ranged_hash_fn(size_type size, const Hash_Fn& r_hash_fn,

198 const Comb_Hash_Fn& r_comb_hash_fn)

199 : Hash_Fn(r_hash_fn), Comb_Hash_Fn(r_comb_hash_fn)

200 { comb_hash_fn_base::notify_resized(size); }

201

202 PB_DS_CLASS_T_DEC

203 void

204 PB_DS_CLASS_C_DEC::

205 swap(PB_DS_CLASS_C_DEC& other)

206 {

207 comb_hash_fn_base::swap(other);

208 std::swap((Hash_Fn& )(*this), (Hash_Fn& )other);

209 }

210

211 PB_DS_CLASS_T_DEC

212 void

213 PB_DS_CLASS_C_DEC::

214 notify_resized(size_type size)

215 { comb_hash_fn_base::notify_resized(size); }

216

217 PB_DS_CLASS_T_DEC

218 inline typename PB_DS_CLASS_C_DEC::comp_hash

219 PB_DS_CLASS_C_DEC::

220 operator()(key_const_reference r_key) const

221 {

222 const size_type hash = hash_fn_base::operator()(r_key);

223 return std::make_pair(comb_hash_fn_base::operator()(hash), hash);

224 }

225

226 PB_DS_CLASS_T_DEC

227 inline typename PB_DS_CLASS_C_DEC::comp_hash

228 PB_DS_CLASS_C_DEC::

229 operator()

230#ifdef _GLIBCXX_DEBUG

231 (key_const_reference r_key, size_type hash) const

232#else

233 (key_const_reference , size_type hash) const

234#endif

235 {

236 _GLIBCXX_DEBUG_ASSERT(hash == hash_fn_base::operator()(r_key));

237 return std::make_pair(comb_hash_fn_base::operator()(hash), hash);

238 }

239

240#undef PB_DS_CLASS_T_DEC

241#undef PB_DS_CLASS_C_DEC

242

243#define PB_DS_CLASS_T_DEC \

244 template<typename Key, typename _Alloc, typename Comb_Hash_Fn>

245

246#define PB_DS_CLASS_C_DEC \

247 ranged_hash_fn<Key, null_type, _Alloc, Comb_Hash_Fn, false>

248

249

250

251

252

253

254

255 template<typename Key, typename _Alloc, typename Comb_Hash_Fn>

257 : public Comb_Hash_Fn

258 {

259 protected:

260 typedef typename _Alloc::size_type size_type;

261 typedef Comb_Hash_Fn comb_hash_fn_base;

262

264

266

268

269 void

270 swap(PB_DS_CLASS_C_DEC&);

271 };

272

273 PB_DS_CLASS_T_DEC

274 PB_DS_CLASS_C_DEC::

275 ranged_hash_fn(size_type size)

276 { Comb_Hash_Fn::notify_resized(size); }

277

278 PB_DS_CLASS_T_DEC

279 PB_DS_CLASS_C_DEC::

280 ranged_hash_fn(size_type size, const Comb_Hash_Fn& r_comb_hash_fn) :

281 Comb_Hash_Fn(r_comb_hash_fn)

282 { }

283

284 PB_DS_CLASS_T_DEC

285 PB_DS_CLASS_C_DEC::

286 ranged_hash_fn(size_type size, const null_type& r_null_type,

287 const Comb_Hash_Fn& r_comb_hash_fn)

288 : Comb_Hash_Fn(r_comb_hash_fn)

289 { }

290

291 PB_DS_CLASS_T_DEC

292 void

293 PB_DS_CLASS_C_DEC::

294 swap(PB_DS_CLASS_C_DEC& other)

295 { comb_hash_fn_base::swap(other); }

296

297#undef PB_DS_CLASS_T_DEC

298#undef PB_DS_CLASS_C_DEC

299

300#define PB_DS_CLASS_T_DEC \

301 template<typename Key, typename _Alloc, typename Comb_Hash_Fn>

302

303#define PB_DS_CLASS_C_DEC \

304 ranged_hash_fn<Key, null_type, _Alloc, Comb_Hash_Fn, true>

305

306

307

308

309

310

311

312 template<typename Key, typename _Alloc, typename Comb_Hash_Fn>

314 : public Comb_Hash_Fn

315 {

316 protected:

317 typedef typename _Alloc::size_type size_type;

318 typedef Comb_Hash_Fn comb_hash_fn_base;

319

321

323

325

326 void

327 swap(PB_DS_CLASS_C_DEC&);

328 };

329

330 PB_DS_CLASS_T_DEC

331 PB_DS_CLASS_C_DEC::

332 ranged_hash_fn(size_type size)

333 { Comb_Hash_Fn::notify_resized(size); }

334

335 PB_DS_CLASS_T_DEC

336 PB_DS_CLASS_C_DEC::

337 ranged_hash_fn(size_type size, const Comb_Hash_Fn& r_comb_hash_fn)

338 : Comb_Hash_Fn(r_comb_hash_fn)

339 { }

340

341 PB_DS_CLASS_T_DEC

342 PB_DS_CLASS_C_DEC::

343 ranged_hash_fn(size_type size, const null_type& r_null_type,

344 const Comb_Hash_Fn& r_comb_hash_fn)

345 : Comb_Hash_Fn(r_comb_hash_fn)

346 { }

347

348 PB_DS_CLASS_T_DEC

349 void

350 PB_DS_CLASS_C_DEC::

351 swap(PB_DS_CLASS_C_DEC& other)

352 { comb_hash_fn_base::swap(other); }

353

354#undef PB_DS_CLASS_T_DEC

355#undef PB_DS_CLASS_C_DEC

356

357 }

358}

359

360#endif

GNU extensions for policy-based data structures for public use.

Struct holding two objects of arbitrary type.

Represents no type, or absence of type, for template tricks.