Back to index

tetex-bin  3.0
Public Member Functions | Private Member Functions | Private Attributes
NameToCharCode Class Reference

#include <NameToCharCode.h>

Collaboration diagram for NameToCharCode:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 NameToCharCode ()
 ~NameToCharCode ()
void add (char *name, CharCode c)
CharCode lookup (char *name)

Private Member Functions

int hash (char *name)

Private Attributes

NameToCharCodeEntrytab
int size
int len

Detailed Description

Definition at line 24 of file NameToCharCode.h.


Constructor & Destructor Documentation

Definition at line 28 of file NameToCharCode.cc.

                               {
  int i;

  size = 31;
  len = 0;
  tab = (NameToCharCodeEntry *)gmalloc(size * sizeof(NameToCharCodeEntry));
  for (i = 0; i < size; ++i) {
    tab[i].name = NULL;
  }
}

Here is the call graph for this function:

Definition at line 39 of file NameToCharCode.cc.

                                {
  int i;

  for (i = 0; i < size; ++i) {
    if (tab[i].name) {
      gfree(tab[i].name);
    }
  }
  gfree(tab);
}

Here is the call graph for this function:


Member Function Documentation

void NameToCharCode::add ( char *  name,
CharCode  c 
)

Definition at line 50 of file NameToCharCode.cc.

                                               {
  NameToCharCodeEntry *oldTab;
  int h, i, oldSize;

  // expand the table if necessary
  if (len >= size / 2) {
    oldSize = size;
    oldTab = tab;
    size = 2*size + 1;
    tab = (NameToCharCodeEntry *)gmalloc(size * sizeof(NameToCharCodeEntry));
    for (h = 0; h < size; ++h) {
      tab[h].name = NULL;
    }
    for (i = 0; i < oldSize; ++i) {
      if (oldTab[i].name) {
       h = hash(oldTab[i].name);
       while (tab[h].name) {
         if (++h == size) {
           h = 0;
         }
       }
       tab[h] = oldTab[i];
      }
    }
    gfree(oldTab);
  }

  // add the new name
  h = hash(name);
  while (tab[h].name && strcmp(tab[h].name, name)) {
    if (++h == size) {
      h = 0;
    }
  }
  if (!tab[h].name) {
    tab[h].name = copyString(name);
  }
  tab[h].c = c;

  ++len;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int NameToCharCode::hash ( char *  name) [private]

Definition at line 107 of file NameToCharCode.cc.

                                   {
  char *p;
  unsigned int h;

  h = 0;
  for (p = name; *p; ++p) {
    h = 17 * h + (int)(*p & 0xff);
  }
  return (int)(h % size);
}

Here is the caller graph for this function:

CharCode NameToCharCode::lookup ( char *  name)

Definition at line 92 of file NameToCharCode.cc.

                                          {
  int h;

  h = hash(name);
  while (tab[h].name) {
    if (!strcmp(tab[h].name, name)) {
      return tab[h].c;
    }
    if (++h == size) {
      h = 0;
    }
  }
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 39 of file NameToCharCode.h.

Definition at line 38 of file NameToCharCode.h.

Definition at line 37 of file NameToCharCode.h.


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