Back to index

texmacs  1.0.7.15
Public Member Functions | Private Attributes | Friends
hashmap_rep< T, U > Class Template Reference

#include <hashmap.hpp>

Inheritance diagram for hashmap_rep< T, U >:
Inheritance graph
[legend]
Collaboration diagram for hashmap_rep< T, U >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 hashmap_rep (U init2, int n2=1, int max2=1)
 ~hashmap_rep ()
void resize (int n)
void reset (T x)
void generate (void(*routine)(T))
bool contains (T x)
bool empty ()
bracket_ro (T x)
U & bracket_rw (T x)
U & bracket_rw_debug (T x)
void join (hashmap< T, U > H)
void write_back (T x, hashmap< T, U > base)
void pre_patch (hashmap< T, U > patch, hashmap< T, U > base)
void post_patch (hashmap< T, U > patch, hashmap< T, U > base)

Private Attributes

int size
int n
int max
init
list< hashentry< T, U > > * a
int ref_count

Friends

class hashmap< T, U >
class rel_hashmap< T, U >
class rel_hashmap_rep< T, U >
class hashmap_iterator_rep< T, U >
class edit_env_rep
int N LESSGTR (hashmap< T, U > h)
tm_ostreamoperator<< LESSGTR (tm_ostream &out, hashmap< T, U > h)
hashmap< T, U > copy LESSGTR (hashmap< T, U > h)
hashmap< T, U > changes LESSGTR (hashmap< T, U > patch, hashmap< T, U > base)
hashmap< T, U > invert LESSGTR (hashmap< T, U > patch, hashmap< T, U > base)
bool operator==LESSGTR (hashmap< T, U > h1, hashmap< T, U > h2)
bool operator!=LESSGTR (hashmap< T, U > h1, hashmap< T, U > h2)

Detailed Description

template<class T, class U>
class hashmap_rep< T, U >

Definition at line 40 of file hashmap.hpp.


Constructor & Destructor Documentation

template<class T , class U >
hashmap_rep< T, U >::hashmap_rep ( init2,
int  n2 = 1,
int  max2 = 1 
) [inline]

Definition at line 48 of file hashmap.hpp.

                                                        :
    size(0), n(n2), max(max2), init(init2), a(tm_new_array<list<hashentry<T,U> > > (n)) {}
template<class T , class U >
hashmap_rep< T, U >::~hashmap_rep ( ) [inline]

Definition at line 50 of file hashmap.hpp.

Here is the call graph for this function:


Member Function Documentation

template<class T , class U >
TMPL U hashmap_rep< T, U >::bracket_ro ( T  x)

Definition at line 100 of file hashmap.cpp.

                                 {
  register int hv= hash (x);
  list<hashentry<T,U> >  l (a [hv & (n-1)]);
  while (!is_nil (l)) {
    if (l->item.code == hv && l->item.key == x)
      return l->item.im;
    l= l->next;
  }
  return init;
}

Here is the call graph for this function:

template<class T , class U >
template lb_info & hashmap_rep< T, U >::bracket_rw ( T  x)

Definition at line 84 of file hashmap.cpp.

                                 {
  register int hv= hash (x);
  list<hashentry<T,U> >  l (a [hv & (n-1)]);
  while (!is_nil (l)) {
    if (l->item.code == hv && l->item.key == x)
      return l->item.im;
    l= l->next;
  }
  if (size >= n*max) resize (n<<1);
  list<hashentry<T,U> >& rl= a [hv & (n-1)];
  rl= list<hashentry<T,U> > (H (hv, x, init), rl);
  size ++;
  return rl->item.im;
}

Here is the call graph for this function:

template<class T , class U >
U& hashmap_rep< T, U >::bracket_rw_debug ( T  x)
template<class T , class U >
TMPL bool hashmap_rep< T, U >::contains ( T  x)

Definition at line 67 of file hashmap.cpp.

                               {
  register int hv= hash (x);
  list<hashentry<T,U> >  l (a [hv & (n-1)]);
  while (!is_nil (l)) {
    if (l->item.code == hv && l->item.key == x)
      return true;
    l= l->next;
  }
  return false;
}

Here is the call graph for this function:

template<class T , class U >
TMPL bool hashmap_rep< T, U >::empty ( )

Definition at line 79 of file hashmap.cpp.

                         {
  return size==0;
}
template<class T , class U >
TMPL void hashmap_rep< T, U >::generate ( void(*)(T routine)

Definition at line 127 of file hashmap.cpp.

                                               {
  int i;
  for (i=0; i<n; i++) {
    list<hashentry<T,U> > l (a[i]);
    while (!is_nil (l)) {
      routine (l->item.key);
      l=l->next;
    }
  }
}

Here is the call graph for this function:

template<class T , class U >
TMPL void hashmap_rep< T, U >::join ( hashmap< T, U >  H)

Definition at line 165 of file hashmap.cpp.

                                      {
  int i= 0, n= h->n;
  for (; i<n; i++) {
    list<hashentry<T,U> > l= h->a[i];
    for (; !is_nil(l); l= l->next)
      bracket_rw (l->item.key)= copy (l->item.im);
  }
}

Here is the call graph for this function:

template<class T , class U >
TMPL void hashmap_rep< T, U >::post_patch ( hashmap< T, U >  patch,
hashmap< T, U >  base 
)

Definition at line 58 of file hashmap_extra.cpp.

                                                                   {
  int i= 0, n= patch->n;
  for (; i<n; i++) {
    list<hashentry<T,U> > l= patch->a[i];
    for (; !is_nil (l); l= l->next) {
      T x= l->item.key;
      U y= l->item.im;
      if (base[x] == y) reset (x);
      else bracket_rw (x)= y;
    }
  }
}

Here is the call graph for this function:

template<class T , class U >
TMPL void hashmap_rep< T, U >::pre_patch ( hashmap< T, U >  patch,
hashmap< T, U >  base 
)

Definition at line 44 of file hashmap_extra.cpp.

                                                                  {
  int i= 0, n= patch->n;
  for (; i<n; i++) {
    list<hashentry<T,U> > l= patch->a[i];
    for (; !is_nil (l); l= l->next) {
      T x= l->item.key;
      U y= contains (x)? bracket_ro (x): l->item.im;
      if (base[x] == y) reset (x);
      else bracket_rw (x)= y;
    }
  }
}

Here is the call graph for this function:

template<class T , class U >
TMPL void hashmap_rep< T, U >::reset ( T  x)

Definition at line 112 of file hashmap.cpp.

                            {
  register int hv= hash (x);
  list<hashentry<T,U> > *l= &(a [hv & (n-1)]);
  while (!is_nil (*l)) {
    if ((*l)->item.code == hv && (*l)->item.key == x) {
      *l= (*l)->next;
      size --;
      if (size < (n>>1) * max) resize (n>>1);
      return;
    }
    l= &((*l)->next);
  }
}

Here is the call graph for this function:

template<class T , class U >
TMPL void hashmap_rep< T, U >::resize ( int  n)

Definition at line 49 of file hashmap.cpp.

                                {
  int i;
  int oldn= n;
  list<hashentry<T,U> >* olda= a;
  n= n2;
  a= tm_new_array<list<hashentry<T,U> > > (n);
  for (i=0; i<oldn; i++) {
    list<hashentry<T,U> > l(olda[i]);
    while (!is_nil (l)) {
      list<hashentry<T,U> >& newl= a[hash(l->item.key)&(n-1)];
      newl= list<hashentry<T,U> > (l->item, newl);
      l=l->next;
    }
  }
  tm_delete_array (olda);
}

Here is the call graph for this function:

template<class T , class U >
TMPL void hashmap_rep< T, U >::write_back ( T  x,
hashmap< T, U >  base 
)

Definition at line 19 of file hashmap_extra.cpp.

                                                    {
  register int hv= hash (x);
  list<hashentry<T,U> > l (a [hv & (n-1)]);
  while (!is_nil (l)) {
    if (l->item.code == hv && l->item.key == x)
      return;
    l= l->next;
  }
  if (size >= n*max) resize (n<<1);
  list<hashentry<T,U> >& rl= a[hv & (n-1)];
  rl= list<hashentry<T,U> > (H (hv, x, init), rl);
  size ++;

  list<hashentry<T,U> > bl (base->a [hv & (base->n-1)]);
  while (!is_nil (bl)) {
    if (bl->item.code == hv && bl->item.key == x) {
      rl->item.im= bl->item.im;
      return;
    }
    bl= bl->next;
  }
  rl->item.im= base->init;
}

Here is the call graph for this function:


Friends And Related Function Documentation

template<class T , class U >
friend class edit_env_rep [friend]

Definition at line 75 of file hashmap.hpp.

template<class T , class U >
friend class hashmap< T, U > [friend]

Definition at line 61 of file hashmap.hpp.

template<class T , class U >
friend class hashmap_iterator_rep< T, U > [friend]

Definition at line 64 of file hashmap.hpp.

template<class T , class U >
int N LESSGTR ( hashmap< T, U >  h) [friend]
template<class T , class U >
hashmap<T,U> copy LESSGTR ( hashmap< T, U >  h) [friend]
template<class T , class U >
hashmap<T,U> changes LESSGTR ( hashmap< T, U >  patch,
hashmap< T, U >  base 
) [friend]
template<class T , class U >
hashmap<T,U> invert LESSGTR ( hashmap< T, U >  patch,
hashmap< T, U >  base 
) [friend]
template<class T , class U >
bool operator!=LESSGTR ( hashmap< T, U >  h1,
hashmap< T, U >  h2 
) [friend]
template<class T , class U >
tm_ostream& operator<< LESSGTR ( tm_ostream out,
hashmap< T, U >  h 
) [friend]
template<class T , class U >
bool operator==LESSGTR ( hashmap< T, U >  h1,
hashmap< T, U >  h2 
) [friend]
template<class T , class U >
friend class rel_hashmap< T, U > [friend]

Definition at line 62 of file hashmap.hpp.

template<class T , class U >
friend class rel_hashmap_rep< T, U > [friend]

Definition at line 63 of file hashmap.hpp.


Member Data Documentation

template<class T , class U >
list<hashentry<T,U> >* hashmap_rep< T, U >::a [private]

Definition at line 45 of file hashmap.hpp.

template<class T , class U >
U hashmap_rep< T, U >::init [private]

Definition at line 44 of file hashmap.hpp.

template<class T , class U >
int hashmap_rep< T, U >::max [private]

Definition at line 43 of file hashmap.hpp.

template<class T , class U >
int hashmap_rep< T, U >::n [private]

Definition at line 42 of file hashmap.hpp.

int concrete_struct::ref_count [inherited]

Definition at line 135 of file basic.hpp.

template<class T , class U >
int hashmap_rep< T, U >::size [private]

Definition at line 41 of file hashmap.hpp.


The documentation for this class was generated from the following files: