OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libstdc++-v3/] [include/] [ext/] [pb_assoc/] [detail/] [gp_ht_map_/] [gp_ht_map_.hpp] - Blame information for rev 17

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 17 jlechner
// -*- C++ -*-
2
 
3
// Copyright (C) 2005 Free Software Foundation, Inc.
4
//
5
// This file is part of the GNU ISO C++ Library.  This library is free
6
// software; you can redistribute it and/or modify it under the
7
// terms of the GNU General Public License as published by the
8
// Free Software Foundation; either version 2, or (at your option)
9
// any later version.
10
 
11
// This library is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
// GNU General Public License for more details.
15
 
16
// You should have received a copy of the GNU General Public License along
17
// with this library; see the file COPYING.  If not, write to the Free
18
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19
// USA.
20
 
21
// As a special exception, you may use this file as part of a free software
22
// library without restriction.  Specifically, if other files instantiate
23
// templates or use macros or inline functions from this file, or you compile
24
// this file and link it with other files to produce an executable, this
25
// file does not by itself cause the resulting executable to be covered by
26
// the GNU General Public License.  This exception does not however
27
// invalidate any other reasons why the executable file might be covered by
28
// the GNU General Public License.
29
 
30
// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
31
 
32
// Permission to use, copy, modify, sell, and distribute this software
33
// is hereby granted without fee, provided that the above copyright
34
// notice appears in all copies, and that both that copyright notice and
35
// this permission notice appear in supporting documentation. None of
36
// the above authors, nor IBM Haifa Research Laboratories, make any
37
// representation about the suitability of this software for any
38
// purpose. It is provided "as is" without express or implied warranty.
39
 
40
/**
41
 * @file gp_ht_map_.hpp
42
 * Contains an implementation class for gp_ht_map_.
43
 */
44
 
45
#include <ext/pb_assoc/detail/cond_dealtor.hpp>
46
#include <ext/pb_assoc/trivial_iterator_def.hpp>
47
#include <ext/pb_assoc/detail/hash_fn/ranged_probe_fn.hpp>
48
#include <ext/pb_assoc/detail/hash_types_traits.hpp>
49
#include <ext/pb_assoc/detail/types_traits.hpp>
50
#include <ext/pb_assoc/exception.hpp>
51
#include <ext/pb_assoc/detail/map_debug_base.hpp>
52
#include <ext/pb_assoc/detail/eq_fn/hash_eq_fn.hpp>
53
#ifdef PB_ASSOC_BASIC_REGRESSION
54
#include <pb_assoc/testsuite/regression/basic_test/throw_prob_adjustor.hpp>
55
#endif // #ifdef PB_ASSOC_BASIC_REGRESSION
56
#include <utility>
57
 
58
namespace pb_assoc
59
{
60
 
61
  namespace detail
62
  {
63
 
64
#ifdef PB_ASSOC_GP_HT_MAP_DEBUG_
65
#define PB_ASSOC_DBG_ASSERT(X) assert(X)
66
#define PB_ASSOC_DBG_VERIFY(X) assert(X)
67
#define PB_ASSOC_DBG_ONLY(X) X
68
#else // #ifdef PB_ASSOC_GP_HT_MAP_DEBUG_
69
#define PB_ASSOC_DBG_ASSERT(X)
70
#define PB_ASSOC_DBG_VERIFY(X) {if((X)==0);}
71
#define PB_ASSOC_DBG_ONLY(X) ;
72
#endif // #ifdef PB_ASSOC_GP_HT_MAP_DEBUG_
73
 
74
#define PB_ASSOC_CLASS_T_DEC \
75
        template< \
76
                typename Key, \
77
                typename Data, \
78
                class Hash_Fn, \
79
                class Eq_Fn, \
80
                class Allocator, \
81
                bool Store_Hash, \
82
                class Comb_Probe_Fn, \
83
                class Probe_Fn, \
84
                class Resize_Policy>
85
 
86
#ifdef PB_ASSOC_DATA_TRUE_INDICATOR
87
#define PB_ASSOC_CLASS_NAME \
88
        gp_ht_map_data_
89
#endif // #ifdef PB_ASSOC_DATA_TRUE_INDICATOR
90
 
91
#ifdef PB_ASSOC_DATA_FALSE_INDICATOR
92
#define PB_ASSOC_CLASS_NAME \
93
        gp_ht_map_no_data_
94
#endif // #ifdef PB_ASSOC_DATA_FALSE_INDICATOR
95
 
96
#define PB_ASSOC_CLASS_C_DEC \
97
        PB_ASSOC_CLASS_NAME< \
98
                Key, \
99
                Data, \
100
                Hash_Fn, \
101
                Eq_Fn, \
102
                Allocator, \
103
                Store_Hash, \
104
                Comb_Probe_Fn, \
105
                Probe_Fn, \
106
                Resize_Policy>
107
 
108
#define PB_ASSOC_HASH_EQ_FN_C_DEC \
109
        pb_assoc::detail::hash_eq_fn< \
110
                Key, \
111
                Eq_Fn, \
112
                Allocator, \
113
                Store_Hash>
114
 
115
#define PB_ASSOC_RANGED_PROBE_FN_C_DEC \
116
        pb_assoc::detail::ranged_probe_fn< \
117
                Key, \
118
                Hash_Fn, \
119
                Allocator, \
120
                Comb_Probe_Fn, \
121
                Probe_Fn, \
122
                Store_Hash>
123
 
124
#define PB_ASSOC_TYPES_TRAITS_C_DEC \
125
        types_traits< \
126
                Key, \
127
                Data, \
128
                Allocator>
129
 
130
#define PB_ASSOC_HASH_TYPES_TRAITS_C_DEC \
131
        hash_types_traits< \
132
                typename Allocator::size_type, \
133
                Store_Hash>
134
 
135
#ifdef PB_ASSOC_USE_MAP_DEBUG_BASE
136
#define PB_ASSOC_MAP_DEBUG_BASE_C_DEC \
137
        pb_assoc::detail::map_debug_base< \
138
                Key, \
139
                Eq_Fn>
140
#endif // #ifdef PB_ASSOC_USE_MAP_DEBUG_BASE
141
 
142
#ifdef PB_ASSOC_DATA_TRUE_INDICATOR
143
#define PB_ASSOC_V2F(X) (X).first
144
#define PB_ASSOC_V2S(X) (X).second
145
#endif // #ifdef PB_ASSOC_DATA_TRUE_INDICATOR
146
 
147
#ifdef PB_ASSOC_DATA_FALSE_INDICATOR
148
#define PB_ASSOC_V2F(X) (X)
149
#define PB_ASSOC_V2S(X) Mapped_Data()
150
#endif // #ifdef PB_ASSOC_DATA_FALSE_INDICATOR
151
 
152
#define PB_ASSOC_STATIC_ASSERT(UNIQUE, E) \
153
        typedef \
154
                pb_assoc::detail::static_assert_dummy_class< \
155
                        sizeof(pb_assoc::detail::static_assert<(bool)(E)>)> \
156
                        UNIQUE##static_assert_type
157
 
158
    template<typename Key,
159
             typename Data,
160
             class Hash_Fn,
161
             class Eq_Fn,
162
             class Allocator,
163
             bool Store_Hash,
164
             class Comb_Probe_Fn,
165
             class Probe_Fn,
166
             class Resize_Policy>
167
    class PB_ASSOC_CLASS_NAME :
168
#ifdef PB_ASSOC_GP_HT_MAP_DEBUG_
169
      protected PB_ASSOC_MAP_DEBUG_BASE_C_DEC,
170
#endif // #ifdef PB_ASSOC_GP_HT_MAP_DEBUG_
171
      public PB_ASSOC_HASH_EQ_FN_C_DEC,
172
      public Resize_Policy,
173
      public PB_ASSOC_RANGED_PROBE_FN_C_DEC,
174
      public PB_ASSOC_TYPES_TRAITS_C_DEC,
175
      public PB_ASSOC_HASH_TYPES_TRAITS_C_DEC
176
    {
177
 
178
    public:
179
 
180
      typedef typename Allocator::size_type size_type;
181
 
182
      typedef
183
      typename PB_ASSOC_TYPES_TRAITS_C_DEC::const_key_reference
184
      const_key_reference;
185
 
186
      typedef typename PB_ASSOC_TYPES_TRAITS_C_DEC::data_type data_type;
187
 
188
      typedef
189
      typename PB_ASSOC_TYPES_TRAITS_C_DEC::data_reference
190
      data_reference;
191
 
192
      typedef
193
      typename PB_ASSOC_TYPES_TRAITS_C_DEC::const_data_reference
194
      const_data_reference;
195
 
196
      typedef typename PB_ASSOC_TYPES_TRAITS_C_DEC::value_type value_type;
197
 
198
      typedef typename PB_ASSOC_TYPES_TRAITS_C_DEC::pointer pointer;
199
 
200
      typedef
201
      typename PB_ASSOC_TYPES_TRAITS_C_DEC::const_pointer
202
      const_pointer;
203
 
204
      typedef typename PB_ASSOC_TYPES_TRAITS_C_DEC::reference reference;
205
 
206
      typedef
207
      typename PB_ASSOC_TYPES_TRAITS_C_DEC::const_reference
208
      const_reference;
209
 
210
    protected:
211
 
212
      typedef typename PB_ASSOC_HASH_TYPES_TRAITS_C_DEC::comp_hash comp_hash;
213
 
214
      enum ENTRY_STATUS
215
        {
216
          EMPTY_ENTRY_STATUS,
217
          VALID_ENTRY_STATUS,
218
          ERASED_ENTRY_STATUS
219
        };
220
 
221
      typedef char entry_status;
222
 
223
      struct store_hash_entry
224
      {
225
        value_type m_value;
226
 
227
        entry_status m_stat;
228
 
229
        size_type m_hash;
230
      };
231
 
232
      struct no_store_hash_entry
233
      {
234
        value_type m_value;
235
 
236
        entry_status m_stat;
237
      };
238
 
239
      typedef
240
      typename cond_type<
241
        Store_Hash,
242
        store_hash_entry,
243
        no_store_hash_entry>::type
244
      entry;
245
 
246
      typedef
247
      typename Allocator::template rebind<entry>::other
248
      entry_allocator;
249
 
250
      typedef typename entry_allocator::pointer entry_pointer;
251
 
252
      typedef typename entry_allocator::const_pointer const_entry_pointer;
253
 
254
      typedef typename entry_allocator::reference entry_reference;
255
 
256
      typedef
257
      typename entry_allocator::const_reference
258
      const_entry_reference;
259
 
260
      typedef typename entry_allocator::pointer entry_array;
261
 
262
      typedef value_type mapped_value_type;
263
 
264
      typedef pointer mapped_pointer;
265
 
266
      typedef const_pointer const_mapped_pointer;
267
 
268
      typedef reference mapped_reference;
269
 
270
      typedef const_reference const_mapped_reference;
271
 
272
#define PB_ASSOC_GEN_POS size_type
273
 
274
#include <ext/pb_assoc/detail/unordered_iterator/const_find_iterator.hpp>
275
#include <ext/pb_assoc/detail/unordered_iterator/find_iterator.hpp>
276
#include <ext/pb_assoc/detail/unordered_iterator/const_iterator.hpp>
277
#include <ext/pb_assoc/detail/unordered_iterator/iterator.hpp>
278
 
279
#undef PB_ASSOC_GEN_POS
280
 
281
      typedef find_iterator_ find_iterator;
282
 
283
      typedef const_find_iterator_ const_find_iterator;
284
 
285
      typedef iterator_ iterator;
286
 
287
      typedef const_iterator_ const_iterator;
288
 
289
      typedef Hash_Fn hash_fn;
290
 
291
      typedef Eq_Fn eq_fn;
292
 
293
      typedef Allocator allocator;
294
 
295
      typedef Probe_Fn probe_fn;
296
 
297
      typedef Comb_Probe_Fn comb_hash_fn;
298
 
299
      typedef Resize_Policy resize_policy;
300
 
301
    protected:
302
 
303
      PB_ASSOC_CLASS_NAME();
304
 
305
      PB_ASSOC_CLASS_NAME(const PB_ASSOC_CLASS_C_DEC& r_other);
306
 
307
      PB_ASSOC_CLASS_NAME(const Hash_Fn& r_hash_fn);
308
 
309
      PB_ASSOC_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn);
310
 
311
      PB_ASSOC_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, const Comb_Probe_Fn& r_comb_probe_fn);
312
 
313
      PB_ASSOC_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, const Comb_Probe_Fn& r_comb_probe_fn, const Probe_Fn& r_probe_fn);
314
 
315
      PB_ASSOC_CLASS_NAME(const Hash_Fn& r_hash_fn, const Eq_Fn& r_eq_fn, const Comb_Probe_Fn& r_comb_probe_fn, const Probe_Fn& r_probe_fn, const Resize_Policy& r_resize_policy);
316
 
317
      template<class It>
318
      void
319
      copy_from_range(It first_it, It last_it);
320
 
321
      virtual
322
      ~PB_ASSOC_CLASS_NAME();
323
 
324
      void
325
      swap(PB_ASSOC_CLASS_C_DEC& r_other);
326
 
327
      inline size_type
328
      size() const;
329
 
330
      inline size_type
331
      max_size() const;
332
 
333
      inline bool
334
      empty() const;
335
 
336
      Hash_Fn&
337
      get_hash_fn();
338
 
339
      const Hash_Fn&
340
      get_hash_fn() const;
341
 
342
      Eq_Fn&
343
      get_eq_fn();
344
 
345
      const Eq_Fn&
346
      get_eq_fn() const;
347
 
348
      Probe_Fn&
349
      get_probe_fn();
350
 
351
      const Probe_Fn&
352
      get_probe_fn() const;
353
 
354
      Comb_Probe_Fn&
355
      get_comb_probe_fn();
356
 
357
      const Comb_Probe_Fn&
358
      get_comb_probe_fn() const;
359
 
360
      Resize_Policy&
361
      get_resize_policy();
362
 
363
      const Resize_Policy&
364
      get_resize_policy() const;
365
 
366
      inline std::pair<find_iterator, bool>
367
      insert(const_reference r_val);
368
 
369
      inline data_reference
370
      subscript_imp(const_key_reference r_key);
371
 
372
      inline find_iterator
373
      find(const_key_reference r_key);
374
 
375
      inline const_find_iterator
376
      find(const_key_reference r_key) const;
377
 
378
      inline find_iterator
379
      find_end();
380
 
381
      inline const_find_iterator
382
      find_end() const;
383
 
384
      inline size_type
385
      erase(const_key_reference r_key, int_to_type<false>);
386
 
387
      inline size_type
388
      erase(const_key_reference r_key, int_to_type<true>);
389
 
390
      template<class Pred>
391
      inline size_type
392
      erase_if(Pred prd);
393
 
394
      void
395
      clear();
396
 
397
      inline iterator
398
      begin();
399
 
400
      inline const_iterator
401
      begin() const;
402
 
403
      inline iterator
404
      end();
405
 
406
      inline const_iterator
407
      end() const;
408
 
409
#ifdef PB_ASSOC_CC_HT_MAP_DEBUG
410
 
411
      virtual void
412
      assert_valid() const;
413
 
414
#endif // #ifdef PB_ASSOC_GP_HT_MAP_DEBUG_
415
 
416
      virtual void
417
      do_resize(size_type new_size);
418
 
419
    private:
420
 
421
      typedef PB_ASSOC_TYPES_TRAITS_C_DEC my_traits_base;
422
 
423
      typedef PB_ASSOC_HASH_TYPES_TRAITS_C_DEC my_hash_traits_base;
424
 
425
      typedef PB_ASSOC_RANGED_PROBE_FN_C_DEC my_ranged_probe_fn_base;
426
 
427
#ifdef PB_ASSOC_GP_HT_MAP_DEBUG_
428
      typedef PB_ASSOC_MAP_DEBUG_BASE_C_DEC my_map_debug_base;
429
#endif // #ifdef PB_ASSOC_GP_HT_MAP_DEBUG_
430
 
431
      typedef PB_ASSOC_HASH_EQ_FN_C_DEC my_hash_eq_fn_base;
432
 
433
      typedef Resize_Policy my_resize_base;
434
 
435
      friend class iterator_;
436
 
437
      friend class const_iterator_;
438
 
439
    private:
440
 
441
      void
442
      deallocate_all();
443
 
444
      void
445
      initialize();
446
 
447
      inline void
448
      constructor_insert_new_imp(const_reference r_val, size_type pos, int_to_type<true>);
449
 
450
      inline void
451
      constructor_insert_new_imp(const_reference r_val, size_type pos, int_to_type<false>);
452
 
453
      void
454
      erase_all_valid_entries(entry_array a_entries_resized, size_type size);
455
 
456
      inline bool
457
      do_resize_if_needed();
458
 
459
      inline void
460
      do_resize_if_needed_no_throw();
461
 
462
      void
463
      resize_imp(entry_array a_entries_resized, size_type old_size);
464
 
465
      inline void
466
      resize_imp_reassign(entry_pointer p_e, entry_array a_entries_resized, int_to_type<false>);
467
 
468
      inline void
469
      resize_imp_reassign(entry_pointer p_e, entry_array a_entries_resized, int_to_type<true>);
470
 
471
      inline size_type
472
      find_ins_pos(const_key_reference r_key, int_to_type<false>);
473
 
474
      inline comp_hash
475
      find_ins_pos(const_key_reference r_key, int_to_type<true>);
476
 
477
      inline std::pair<find_iterator, bool>
478
      insert_imp(const_reference r_val, int_to_type<false>);
479
 
480
      inline std::pair<find_iterator, bool>
481
      insert_imp(const_reference r_val, int_to_type<true>);
482
 
483
      inline pointer
484
      insert_new_imp(const_reference r_val, size_type pos);
485
 
486
      inline pointer
487
      insert_new_imp(const_reference r_val, comp_hash& r_pos_hash_pair);
488
 
489
      inline data_reference
490
      subscript_imp(const_key_reference r_key, int_to_type<false>);
491
 
492
      inline data_reference
493
      subscript_imp(const_key_reference r_key, int_to_type<true>);
494
 
495
      inline const_data_reference
496
      const_subscript_imp(const_key_reference r_key) const;
497
 
498
      inline pointer
499
      find_key_pointer(const_key_reference r_key, int_to_type<false>);
500
 
501
      inline pointer
502
      find_key_pointer(const_key_reference r_key, int_to_type<true>);
503
 
504
      inline const_data_reference
505
      const_subscript_imp(const_key_reference r_key, int_to_type<false>) const;
506
 
507
      inline const_data_reference
508
      const_subscript_imp(const_key_reference r_key, int_to_type<true>) const;
509
 
510
      inline size_type
511
      erase_in_pos_imp(const_key_reference r_key, const comp_hash& r_pos_hash_pair);
512
 
513
      inline void
514
      erase_entry(entry_pointer p_e);
515
 
516
#ifdef PB_ASSOC_DATA_TRUE_INDICATOR
517
      void
518
      inc_it_state(pointer& r_p_value, size_type& r_pos) const;
519
#endif // #ifdef PB_ASSOC_DATA_TRUE_INDICATOR
520
 
521
      void
522
      inc_it_state(const_pointer& r_p_value, size_type& r_pos) const;
523
 
524
      void
525
      get_start_it_state(const_pointer& r_p_value, size_type& r_pos) const;
526
 
527
      void
528
      get_start_it_state(pointer& r_p_value, size_type& r_pos);
529
 
530
#ifdef PB_ASSOC_CC_HT_MAP_DEBUG
531
 
532
      void
533
      assert_entry_array_valid(const entry_array a_entries, int_to_type<false>) const;
534
 
535
      void
536
      assert_entry_array_valid(const entry_array a_entries, int_to_type<true>) const;
537
 
538
#endif // #ifdef PB_ASSOC_GP_HT_MAP_DEBUG_
539
 
540
    private:
541
      static entry_allocator s_entry_allocator;
542
 
543
      entry_pointer m_a_entries;
544
 
545
      size_type m_num_e;
546
 
547
      size_type m_num_used_e;
548
 
549
      static iterator s_end_it;
550
 
551
      static const_iterator s_const_end_it;
552
 
553
      enum
554
        {
555
          store_hash_ok =
556
          !Store_Hash ||
557
          !pb_assoc::detail::is_same_type<
558
          Hash_Fn,
559
          pb_assoc::null_hash_fn>::value
560
        };
561
 
562
      PB_ASSOC_STATIC_ASSERT(sth, store_hash_ok);
563
    };
564
 
565
#include <ext/pb_assoc/detail/gp_ht_map_/constructor_destructor_fn_imps.hpp>
566
#include <ext/pb_assoc/detail/gp_ht_map_/find_fn_imps.hpp>
567
#include <ext/pb_assoc/detail/gp_ht_map_/resize_fn_imps.hpp>
568
#include <ext/pb_assoc/detail/gp_ht_map_/debug_fn_imps.hpp>
569
#include <ext/pb_assoc/detail/gp_ht_map_/info_fn_imps.hpp>
570
#include <ext/pb_assoc/detail/gp_ht_map_/policy_access_fn_imps.hpp>
571
#include <ext/pb_assoc/detail/gp_ht_map_/erase_fn_imps.hpp>
572
#include <ext/pb_assoc/detail/gp_ht_map_/iterator_fn_imps.hpp>
573
#include <ext/pb_assoc/detail/gp_ht_map_/insert_fn_imps.hpp>
574
 
575
#undef PB_ASSOC_CLASS_T_DEC
576
 
577
#undef PB_ASSOC_CLASS_C_DEC
578
 
579
#undef PB_ASSOC_HASH_EQ_FN_C_DEC
580
 
581
#undef PB_ASSOC_RANGED_PROBE_FN_C_DEC
582
 
583
#undef PB_ASSOC_TYPES_TRAITS_C_DEC
584
 
585
#undef PB_ASSOC_HASH_TYPES_TRAITS_C_DEC
586
 
587
#undef PB_ASSOC_MAP_DEBUG_BASE_C_DEC
588
 
589
#undef PB_ASSOC_CLASS_NAME
590
 
591
#undef PB_ASSOC_V2F
592
#undef PB_ASSOC_V2S
593
 
594
#undef PB_ASSOC_DBG_ASSERT
595
#undef PB_ASSOC_DBG_VERIFY
596
#undef PB_ASSOC_DBG_ONLY
597
 
598
#undef PB_ASSOC_STATIC_ASSERT
599
 
600
  } // namespace detail
601
 
602
} // namespace pb_assoc

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.