File: PlainHashIndexTable.hh

package info (click to toggle)
topcom 0.17.8%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 78,572 kB
  • sloc: cpp: 16,640; sh: 975; makefile: 345; ansic: 40
file content (76 lines) | stat: -rw-r--r-- 2,828 bytes parent folder | download
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
////////////////////////////////////////////////////////////////////////////////
// 
// PlainHashIndexTable.hh
//    produced: 06/04/98 jr
// last change: 06/04/98 jr
//
////////////////////////////////////////////////////////////////////////////////
#ifndef PLAINHASHINDEXTABLE_HH
#define PLAINHASHINDEXTABLE_HH

#include <stdlib.h>
#include <iostream>
#include <ctype.h>
#include <string.h>

#include "Global.hh"
#include "RefCount.hh"
#include "Array.hh"
#include "PlainHashMap.hh"

template<class Key>
class PlainHashIndexTable : public PlainHashMap<Key, size_type> {
public:
  typedef          PlainHashMap<Key, size_type>                     plainhashindextable_data;
  typedef typename PlainHashMap<Key, size_type>::keyptr_type        keyptr_type;
  typedef typename PlainHashMap<Key, size_type>::const_keyptr_type  const_keyptr_type;
  typedef typename PlainHashMap<Key, size_type>::dataptr_type       dataptr_type;
  typedef typename PlainHashMap<Key, size_type>::const_dataptr_type const_dataptr_type;
  typedef          Array<const_keyptr_type>                         index_data_type;
private:
  index_data_type _index_data;
public:
  // constructors:
  inline PlainHashIndexTable() : plainhashindextable_data() {}
  inline PlainHashIndexTable(const plainhashindextable_data& phitd) : plainhashindextable_data(phitd) {}
  inline PlainHashIndexTable(const PlainHashIndexTable& phit) : plainhashindextable_data(phit) {}
  inline PlainHashIndexTable(const size_type init_size) : plainhashindextable_data(init_size) {}
  // destructor:
  inline ~PlainHashIndexTable() {}
  // assignment:
  inline PlainHashIndexTable& operator=(const PlainHashIndexTable& phit) {
    plainhashindextable_data::operator=(phit);
    return *this;
  }
  // accessors:
  inline const size_type maxindex() const { return _index_data.maxindex(); }
  // functions:
  inline const Key& get_obj(const size_type index) const {
#ifdef INDEX_CHECK
    if (index >= _index_data.maxindex()) {
      std::cerr << "Key& get_obj(const size_type): "
	   << "index out of range." << std::endl;
    }
#endif
   return *_index_data[index];
 }
  inline const size_type get_index(const Key& key) {
    const dataptr_type& indexptr(this->member(key));
    if (indexptr) {
      return *indexptr;
    }    
    const size_type new_index(_index_data.maxindex());
    const HashMapData<Key, size_type>* 
      hashptr(plainhashindextable_data::plainhashmap_data::insert(HashMapData<Key, size_type>(key, new_index)));
    _index_data.resize(new_index + 1);
    _index_data[new_index] = hashptr->keyptr();
    return new_index;
  }
  inline void insert(const Key& key) { get_index(key); }
private:
  void erase(const Key&);		// no erase allowed!
  size_type operator[](const Key&);	// no non-const reference to Data allowed!
};

#endif
// eof PlainHashIndexTable.hh