OpenCores
URL https://opencores.org/ocsvn/thor/thor/trunk

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v5/] [software/] [AS64/] [source/] [HT.cpp] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 robfinch
/* -----------------------------------------------------------------------------
2
 
3
   Description :
4
 
5
   Changes
6
           Author      : R. Finch
7
           Date        : 92/
8
           Version     :
9
           Description : new module
10
 
11
----------------------------------------------------------------------------- */
12
 
13
#include "stdafx.h"
14
 
15
/* -----------------------------------------------------------------------------
16
 
17
   Description :
18
 
19
   Changes
20
           Author      : R. Finch
21
           Date        : 92/
22
           Version     :
23
           Description : new module
24
 
25
----------------------------------------------------------------------------- */
26
 
27
void *htInsert(SHashTbl *hi, void *item)
28
{
29
   SHashVal hash;
30
   int rr, ii;
31
   int TableIndex;
32
   int count;
33
   int8_t *htbl;
34
   SYM *sym = (SYM *)item;
35
   char *pn;
36
   int flg = 0;
37
 
38
   pn = nmTable.GetName(sym->name);
39
   if (!strcmp(pn, "VideoBIOS_FuncTable")) {
40
      flg = 1;
41
   }
42
   htbl = (int8_t *)hi->table;
43
   hash = (*hi->Hash)(item);
44
   TableIndex = hash.hash;
45
   for (count = 0; count < hi->size; count++)
46
   {
47
      for (rr = ii = 0; ii < hi->width && rr == 0; ii++)
48
         rr |= htbl[TableIndex * hi->width + ii];
49
      if (rr == 0)
50
      {
51
         memcpy(&htbl[TableIndex * hi->width], item, hi->width);
52
         break;
53
      }
54
      TableIndex = (TableIndex + hash.delta) % hi->size;
55
   }
56
   if (flg)
57
      printf("ins vbft:%d\r\n", TableIndex);
58
   return rr ? NULL : &htbl[TableIndex * hi->width];
59
}
60
 
61
 
62
/* -----------------------------------------------------------------------------
63
 
64
   Description :
65
      Searchs for and deletes(zeros out) specified entry.
66
 
67
   Returns :
68
      Pointer to deleted entry if found, NULL if enrty not found.
69
 
70
   Changes
71
           Author      : R. Finch
72
           Date        : 92/
73
           Version     :
74
           Description : new module
75
 
76
----------------------------------------------------------------------------- */
77
 
78
void *htDelete(SHashTbl *hi, void *item)
79
{
80
   void *p;
81
 
82
        p = htFind(hi,item);
83
        if (p)
84
            memset(p,0,hi->width);
85
   return p;
86
}
87
 
88
 
89
/* -----------------------------------------------------------------------------
90
   Description :
91
      Finds an entry in a hash table.
92
   Returns :
93
      Pointer to entry in hash table.
94
----------------------------------------------------------------------------- */
95
 
96
void *htFind(SHashTbl *hi, void *item)
97
{
98
   SHashVal hash;
99
   int rr;
100
   int TableIndex;
101
   int count;
102
   char *htbl;
103
 
104
   htbl = (char *)hi->table;
105
   hash = (*hi->Hash)(item);
106
   TableIndex = hash.hash;
107
   // Loop throughout the entire table. We cannot stop on a blank entry because
108
   // the blank entry could be the result of a delete. Which means there might
109
   // still be valid data somewhere in the table, after the deleted entry.
110
   for (count = 0; count < hi->size; count++)
111
   {
112
      rr = (*hi->IsEqual)(item, &htbl[TableIndex * hi->width]);
113
      if (rr == 0)
114
         break;
115
      TableIndex = (TableIndex + hash.delta) % hi->size;
116
   }
117
   // Try a linear table search if not found
118
   if (rr) {
119
       for (count = 0; count < hi->size; count++) {
120
           rr = (*hi->IsEqual)(item, &htbl[count * hi->width]);
121
           if (rr==0) {
122
                   TableIndex = count;
123
                   break;
124
                   }
125
           }
126
   }
127
   return rr ? 0 : &htbl[TableIndex * hi->width];
128
}
129
 
130
void *htFind2(SHashTbl *hi, char *name)
131
{
132
   SHashVal hash;
133
   int rr;
134
   int TableIndex;
135
   int count;
136
   char *htbl;
137
 
138
   htbl = (char *)hi->table;
139
   hash = htSymHash(hi,name);
140
   TableIndex = hash.hash;
141
   // Loop throughout the entire table. We cannot stop on a blank entry because
142
   // the blank entry could be the result of a delete. Which means there might
143
   // still be valid data somewhere in the table, after the deleted entry.
144
   for (count = 0; count < hi->size; count++)
145
   {
146
      rr = (*hi->IsEqualName)(name, &htbl[TableIndex * hi->width]);
147
      if (rr == 0)
148
         break;
149
      TableIndex = (TableIndex + hash.delta) % hi->size;
150
   }
151
/*
152
   if (rr==0) {
153
      for (TableIndex = 0; TableIndex < hi->size; TableIndex++) {
154
            rr = (*hi->IsEqualName)(name, &htbl[TableIndex * hi->width]);
155
            if (rr == 0)
156
               break;
157
      }
158
   }
159
*/
160
   // Try a linear table search if not found
161
   if (rr) {
162
       for (count = 0; count < hi->size; count++) {
163
           rr = (*hi->IsEqualName)(name, &htbl[count * hi->width]);
164
           if (rr==0) {
165
                   TableIndex = count;
166
                   break;
167
                   }
168
           }
169
   }
170
   return rr ? 0 : &htbl[TableIndex * hi->width];
171
}
172
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.