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

« back to all changes in this revision

Viewing changes to src/Classes/Compound/hashmap_extra.cpp

  • 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_extra.cpp
4
 
* DESCRIPTION: extra routines for hashmap<string,tree>
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_EXTRA_CC
14
 
#define HASHMAP_EXTRA_CC
15
 
#include "hashmap.hpp"
16
 
#define TMPL template<class T, class U>
17
 
#define H hashentry<T,U>
18
 
 
19
 
TMPL void
20
 
hashmap_rep<T,U>::write_back (T x, hashmap<T,U> base) {
21
 
  register int hv= hash (x);
22
 
  list<hashentry<T,U> > l (a [hv & (n-1)]);
23
 
  while (!nil (l)) {
24
 
    if (l->item.code == hv && l->item.key == x)
25
 
      return;
26
 
    l= l->next;
27
 
  }
28
 
  if (size >= n*max) resize (n<<1);
29
 
  list<hashentry<T,U> >& rl= a[hv & (n-1)];
30
 
  rl= list<hashentry<T,U> > (H (hv, x, init), rl);
31
 
  size ++;
32
 
 
33
 
  list<hashentry<T,U> > bl (base->a [hv & (base->n-1)]);
34
 
  while (!nil (bl)) {
35
 
    if (bl->item.code == hv && bl->item.key == x) {
36
 
      rl->item.im= bl->item.im;
37
 
      return;
38
 
    }
39
 
    bl= bl->next;
40
 
  }
41
 
  rl->item.im= base->init;
42
 
}
43
 
 
44
 
TMPL void
45
 
hashmap_rep<T,U>::pre_patch (hashmap<T,U> patch, hashmap<T,U> base) {
46
 
  int i= 0, n= patch->n;
47
 
  for (; i<n; i++) {
48
 
    list<hashentry<T,U> > l= patch->a[i];
49
 
    for (; !nil (l); l= l->next) {
50
 
      T x= l->item.key;
51
 
      U y= contains (x)? bracket_ro (x): l->item.im;
52
 
      if (base[x] == y) reset (x);
53
 
      else bracket_rw (x)= y;
54
 
    }
55
 
  }
56
 
}
57
 
 
58
 
TMPL void
59
 
hashmap_rep<T,U>::post_patch (hashmap<T,U> patch, hashmap<T,U> base) {
60
 
  int i= 0, n= patch->n;
61
 
  for (; i<n; i++) {
62
 
    list<hashentry<T,U> > l= patch->a[i];
63
 
    for (; !nil (l); l= l->next) {
64
 
      T x= l->item.key;
65
 
      U y= l->item.im;
66
 
      if (base[x] == y) reset (x);
67
 
      else bracket_rw (x)= y;
68
 
    }
69
 
  }
70
 
}
71
 
 
72
 
TMPL list<hashentry<T,U> >
73
 
copy_list (list<hashentry<T,U> > l) {
74
 
  if (nil (l)) return l;
75
 
  else return list<hashentry<T,U> >
76
 
                (hashentry<T,U> (l->item.code, l->item.key, l->item.im),
77
 
                 copy_list (l->next));
78
 
}
79
 
 
80
 
TMPL hashmap<T,U>
81
 
copy (hashmap<T,U> h) {
82
 
  int i, n= h->n;
83
 
  hashmap<T,U> h2 (h->init, n, h->max);
84
 
  h2->size= h->size;
85
 
  for (i=0; i<n; i++)
86
 
    h2->a[i]= copy_list (h->a[i]);
87
 
  return h2;
88
 
}
89
 
 
90
 
TMPL hashmap<T,U>
91
 
changes (hashmap<T,U> patch, hashmap<T,U> base) {
92
 
  int i;
93
 
  hashmap<T,U> h (base->init);
94
 
  for (i=0; i<patch->n; i++) {
95
 
    list<hashentry<T,U> > l (patch->a[i]);
96
 
    while (!nil (l)) {
97
 
      if (l->item.im != base [l->item.key])
98
 
        h (l->item.key)= l->item.im;
99
 
      l=l->next;
100
 
    }
101
 
  }
102
 
  return h;
103
 
}
104
 
 
105
 
TMPL hashmap<T,U>
106
 
invert (hashmap<T,U> patch, hashmap<T,U> base) {
107
 
  int i;
108
 
  hashmap<T,U> h (base->init);
109
 
  for (i=0; i<patch->n; i++) {
110
 
    list<hashentry<T,U> > l (patch->a[i]);
111
 
    while (!nil (l)) {
112
 
      if (l->item.im != base [l->item.key])
113
 
        h (l->item.key)= base [l->item.key];
114
 
      l=l->next;
115
 
    }
116
 
  }
117
 
  return h;
118
 
}
119
 
 
120
 
TMPL hashmap<T,U>::hashmap (U init, tree t):
121
 
  rep (new hashmap_rep<T,U>(init, 1, 1))
122
 
{
123
 
  int i, n= arity (t);
124
 
  for (i=0; i<n; i++)
125
 
    if (is_func (t[i], ASSOCIATE, 2))
126
 
      rep->bracket_rw (get_label (t[i][0]))= copy (t[i][1]);
127
 
}
128
 
 
129
 
#undef H
130
 
#undef TMPL
131
 
#endif // defined HASHMAP_EXTRA_CC