~ubuntu-branches/ubuntu/quantal/texmacs/quantal

« back to all changes in this revision

Viewing changes to src/Kernel/Containers/hashmap.hpp

  • Committer: Bazaar Package Importer
  • Author(s): Atsuhito KOHDA, Kamaraju Kusumanchi, kohda
  • Date: 2008-04-06 15:11:41 UTC
  • mfrom: (1.1.7 upstream) (4.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080406151141-w0sg20jnv86mlt6f
Tags: 1:1.0.6.14-1
[Kamaraju Kusumanchi <kamaraju@gmail.com>]
* New upstream release
* 01_american.dpatch is updated
* Since thread support in guile-1.8 is now disabled, the segmentation faults
  should not arise anymore. More info at #439923. (Closes: #450499, #458685)
[kohda]
* This version fixed menu problem.  (Closes: #447083)
* Reverted orig.tar.gz to the upstream tarball.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/******************************************************************************
 
3
* MODULE     : hashmap.hpp
 
4
* DESCRIPTION: fixed size hashmaps with reference counting
 
5
* COPYRIGHT  : (C) 1999  Joris van der Hoeven
 
6
*******************************************************************************
 
7
* This software falls under the GNU general public license and comes WITHOUT
 
8
* ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details.
 
9
* If you don't have this file, write to the Free Software Foundation, Inc.,
 
10
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
11
******************************************************************************/
 
12
 
 
13
#ifndef HASHMAP_H
 
14
#define HASHMAP_H
 
15
#include "list.hpp"
 
16
 
 
17
class tree;
 
18
template<class T> class list;
 
19
template<class T,class U> class hashmap;
 
20
template<class T,class U> class rel_hashmap;
 
21
template<class T,class U> class rel_hashmap_rep;
 
22
template<class T,class U> class hashmap_iterator_rep;
 
23
 
 
24
template<class T,class U> int N (hashmap<T,U> a);
 
25
template<class T,class U> ostream& operator << (ostream& out, hashmap<T,U> h);
 
26
template<class T,class U> hashmap<T,U> copy (hashmap<T,U> h);
 
27
template<class T,class U> hashmap<T,U> changes (hashmap<T,U> p,hashmap<T,U> b);
 
28
template<class T,class U> hashmap<T,U> invert (hashmap<T,U> p, hashmap<T,U> b);
 
29
template<class T,class U> bool operator == (hashmap<T,U> h1, hashmap<T,U> h2);
 
30
template<class T,class U> bool operator != (hashmap<T,U> h1, hashmap<T,U> h2);
 
31
 
 
32
template<class T, class U> struct hashentry {
 
33
  int code;
 
34
  T key;
 
35
  U im;
 
36
  hashentry<T,U> () { }
 
37
  hashentry<T,U> (int code, T key2, U im2);
 
38
  operator tree ();
 
39
};
 
40
 
 
41
template<class T, class U> class hashmap_rep: concrete_struct {
 
42
  int size;                  // size of hashmap (nr of entries)
 
43
  int n;                     // nr of keys (a power of two)
 
44
  int max;                   // mean number of entries per key
 
45
  U   init;                  // default entry
 
46
  list<hashentry<T,U> >* a;  // the array of entries
 
47
 
 
48
public:
 
49
  inline hashmap_rep<T,U>(U init2, int n2=1, int max2=1):
 
50
    size(0), n(n2), max(max2), init(init2), a(new list<hashentry<T,U> >[n]) {}
 
51
  inline ~hashmap_rep<T,U> () { delete[] a; }
 
52
  void resize (int n);
 
53
  void reset (T x);
 
54
  void generate (void (*routine) (T));
 
55
  bool contains (T x);
 
56
  bool empty ();
 
57
  U    bracket_ro (T x);
 
58
  U&   bracket_rw (T x);
 
59
  void join (hashmap<T,U> H);
 
60
 
 
61
  friend class hashmap<T,U>;
 
62
  friend class rel_hashmap<T,U>;
 
63
  friend class rel_hashmap_rep<T,U>;
 
64
  friend class hashmap_iterator_rep<T,U>;
 
65
  friend int N LESSGTR (hashmap<T,U> h);
 
66
  friend ostream& operator << LESSGTR (ostream& out, hashmap<T,U> h);
 
67
 
 
68
  // only for hashmap<string,tree>
 
69
  void write_back (T x, hashmap<T,U> base);
 
70
  void pre_patch (hashmap<T,U> patch, hashmap<T,U> base);
 
71
  void post_patch (hashmap<T,U> patch, hashmap<T,U> base);
 
72
  friend hashmap<T,U> copy LESSGTR (hashmap<T,U> h);
 
73
  friend hashmap<T,U> changes LESSGTR (hashmap<T,U> patch, hashmap<T,U> base);
 
74
  friend hashmap<T,U> invert LESSGTR (hashmap<T,U> patch, hashmap<T,U> base);
 
75
  friend class edit_env_rep; // FIXME: broken encapsulation
 
76
  // end only for hashmap<string,tree>
 
77
 
 
78
  friend bool operator == LESSGTR (hashmap<T,U> h1, hashmap<T,U> h2);
 
79
  friend bool operator != LESSGTR (hashmap<T,U> h1, hashmap<T,U> h2);
 
80
};
 
81
 
 
82
template<class T, class U> class hashmap {
 
83
CONCRETE_TEMPLATE_2(hashmap,T,U);
 
84
  static hashmap<T,U> init;
 
85
  inline hashmap ():
 
86
    rep (new hashmap_rep<T,U> (type_helper<U>::init, 1, 1)) {}
 
87
  inline hashmap (U init, int n=1, int max=1):
 
88
    rep (new hashmap_rep<T,U> (init, n, max)) {}
 
89
  // only for hashmap<string,tree>
 
90
  hashmap (U init, tree t);
 
91
  // end only for hashmap<string,tree>
 
92
  inline U  operator [] (T x) { return rep->bracket_ro (x); }
 
93
  inline U& operator () (T x) { return rep->bracket_rw (x); }
 
94
  operator tree ();
 
95
};
 
96
CONCRETE_TEMPLATE_2_CODE(hashmap,class,T,class,U);
 
97
 
 
98
#define TMPL template<class T, class U>
 
99
TMPL inline int N (hashmap<T,U> h) { return h->size; }
 
100
TMPL hashmap<T,U> changes (hashmap<T,U> patch, hashmap<T,U> base);
 
101
TMPL hashmap<T,U> invert (hashmap<T,U> patch, hashmap<T,U> base);
 
102
#undef TMPL
 
103
 
 
104
#include "hashmap.cpp"
 
105
#include "hashmap_extra.cpp"
 
106
 
 
107
#endif // defined HASHMAP_H