~ubuntu-branches/ubuntu/maverick/aspectc++/maverick

« back to all changes in this revision

Viewing changes to Puma/src/basics/StrHashTable.cc

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2008-04-10 17:40:52 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080410174052-xdnsm7oi8hauyyf1
Tags: 1.0pre4~svn.20080409+dfsg-3
Fix another missing include, this time in Ag++/StdSystem.cc

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
namespace Puma {
25
25
 
26
26
 
27
 
unsigned int StrHashTable::hash (const char *p,unsigned int len) {
28
 
  unsigned h = 0, g;
29
 
 
30
 
  while (len--) {
31
 
    h = (h << 4) + (*p);
32
 
    if ((g = h & 0xf0000000)) {
33
 
      h = h ^ (g >> 24);
34
 
      h = h ^ g;
35
 
    }
 
27
unsigned int StrHashTable::hash (const char *p, unsigned int& len) {
 
28
  unsigned h = 0;
 
29
  len = 0;
 
30
  while (*p) {
 
31
    h = (h * 65599) + (*p);
36
32
    p++;
 
33
    len++;
37
34
  }
38
35
  return h % STRHASHTABLE_SIZE;
39
36
}
40
37
 
41
38
 
42
 
StrHashKey *StrHashTable::find (unsigned int magic, const char *str,
43
 
 unsigned int len) {
 
39
StrHashKey *StrHashTable::find (unsigned int magic, const char *str, unsigned int len) {
44
40
  StrHashKey *key = (StrHashKey*)m_Table[magic].select ();
45
41
 
46
42
  while (key) {
47
 
    if (key->length () == len && strcmp (key->c_str (), str) == 0) {
 
43
    if (key->length () == len && memcmp (key->c_str(), str, len) == 0) {
48
44
      return key;
49
45
    }
50
46
    key = (StrHashKey*)key->select ();
53
49
}
54
50
 
55
51
 
 
52
void StrHashTable::clear () {
 
53
  // delete all dynamically created hash keys
 
54
  for (long i = 0; i < STRHASHTABLE_SIZE; i++) {
 
55
    StrHashKey *key = (StrHashKey*)m_Table[i].select ();
 
56
    while (key) {
 
57
      StrHashKey *curr = key;
 
58
      key = (StrHashKey*)key->select ();
 
59
      // don't need to unlink since the whole chain 
 
60
      // is deleted and unlinked below
 
61
      delete curr;
 
62
    }
 
63
    // unlink the whole chain
 
64
    m_Table[i].select (0);
 
65
  }
 
66
  // restore valid state
 
67
  _emptyKey = insert ("");
 
68
  assert (_emptyKey);
 
69
}
 
70
 
 
71
 
56
72
StrHashKey *StrHashTable::insert (const char *str) {
57
 
  unsigned int len = strlen (str);
 
73
  unsigned int len;
58
74
  unsigned int magic = hash (str, len);
59
75
  StrHashKey *key = find (magic, str, len);
60
76
  if (key == 0) {
61
77
    key = new StrHashKey (magic, str, len);
62
78
    m_Table[magic].insert (key);
63
 
    //cout << "%" << key->getString () << "%" << endl;
64
79
  }
65
80
  return key;
66
81
}