ReactOS  0.4.13-dev-99-g7e18b6d
hash.h File Reference
#include "GL/gl.h"
Include dependency graph for hash.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

struct HashTableNewHashTable (void)
 
void DeleteHashTable (struct HashTable *table)
 
voidHashLookup (const struct HashTable *table, GLuint key)
 
void HashInsert (struct HashTable *table, GLuint key, void *data)
 
void HashRemove (struct HashTable *table, GLuint key)
 
GLuint HashFirstEntry (const struct HashTable *table)
 
void HashPrint (const struct HashTable *table)
 
GLuint HashFindFreeKeyBlock (const struct HashTable *table, GLuint numKeys)
 

Function Documentation

◆ DeleteHashTable()

void DeleteHashTable ( struct HashTable table)

Definition at line 87 of file hash.c.

88 {
89  GLuint i;
90  assert(table);
91  for (i=0;i<TABLE_SIZE;i++) {
92  struct HashEntry *entry = table->Table[i];
93  while (entry) {
94  struct HashEntry *next = entry->Next;
95  free(entry);
96  entry = next;
97  }
98  }
99  free(table);
100 }
#define free
Definition: debug_ros.c:5
uint8_t entry
Definition: isohybrid.c:63
#define assert(x)
Definition: debug.h:53
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
Definition: hash.c:61
static unsigned __int64 next
Definition: rand_nt.c:6
unsigned int GLuint
Definition: gl.h:159
#define TABLE_SIZE
Definition: hash.c:59

Referenced by alloc_shared_state(), and free_shared_state().

◆ HashFindFreeKeyBlock()

GLuint HashFindFreeKeyBlock ( const struct HashTable table,
GLuint  numKeys 
)

Definition at line 248 of file hash.c.

249 {
250  GLuint maxKey = ~((GLuint) 0);
251  if (maxKey - numKeys > table->MaxKey) {
252  /* the quick solution */
253  return table->MaxKey + 1;
254  }
255  else {
256  /* the slow solution */
257  GLuint freeCount = 0;
258  GLuint freeStart = 0;
259  GLuint key;
260  for (key=0; key!=maxKey; key++) {
261  if (HashLookup(table, key)) {
262  /* darn, this key is already in use */
263  freeCount = 0;
264  freeStart = key+1;
265  }
266  else {
267  /* this key not in use, check if we've found enough */
268  freeCount++;
269  if (freeCount == numKeys) {
270  return freeStart;
271  }
272  }
273  }
274  /* cannot allocate a block of numKeys consecutive keys */
275  return 0;
276  }
277 }
void * HashLookup(const struct HashTable *table, GLuint key)
Definition: hash.c:110
HKEY key
Definition: reg.c:42
unsigned int GLuint
Definition: gl.h:159
Definition: path.c:42

Referenced by gl_GenLists(), and gl_GenTextures().

◆ HashFirstEntry()

GLuint HashFirstEntry ( const struct HashTable table)

Definition at line 211 of file hash.c.

212 {
213  GLuint pos;
214  assert(table);
215  for (pos=0; pos < TABLE_SIZE; pos++) {
216  if (table->Table[pos])
217  return table->Table[pos]->Key;
218  }
219  return 0;
220 }
#define assert(x)
Definition: debug.h:53
unsigned int GLuint
Definition: gl.h:159
#define TABLE_SIZE
Definition: hash.c:59

Referenced by free_shared_state().

◆ HashInsert()

void HashInsert ( struct HashTable table,
GLuint  key,
void data 
)

Definition at line 138 of file hash.c.

139 {
140  /* search for existing entry with this key */
141  GLuint pos;
142  struct HashEntry *entry;
143 
144  assert(table);
145  assert(key);
146 
147  if (key > table->MaxKey)
148  table->MaxKey = key;
149 
150  pos = key % TABLE_SIZE;
151  entry = table->Table[pos];
152  while (entry) {
153  if (entry->Key == key) {
154  /* replace entry's data */
155  entry->Data = data;
156  return;
157  }
158  entry = entry->Next;
159  }
160 
161  /* alloc and insert new table entry */
162  entry = (struct HashEntry *) calloc(sizeof(struct HashEntry), 1);
163  entry->Key = key;
164  entry->Data = data;
165  entry->Next = table->Table[pos];
166  table->Table[pos] = entry;
167 }
uint8_t entry
Definition: isohybrid.c:63
#define assert(x)
Definition: debug.h:53
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
HKEY key
Definition: reg.c:42
Definition: hash.c:61
unsigned int GLuint
Definition: gl.h:159
#define calloc
Definition: rosglue.h:14
#define TABLE_SIZE
Definition: hash.c:59
Definition: path.c:42

Referenced by gl_alloc_texture_object(), gl_EndList(), and gl_GenLists().

◆ HashLookup()

void* HashLookup ( const struct HashTable table,
GLuint  key 
)

Definition at line 110 of file hash.c.

111 {
112  GLuint pos;
113  struct HashEntry *entry;
114 
115  assert(table);
116  assert(key);
117 
118  pos = key % TABLE_SIZE;
119  entry = table->Table[pos];
120  while (entry) {
121  if (entry->Key == key) {
122  return entry->Data;
123  }
124  entry = entry->Next;
125  }
126  return NULL;
127 }
uint8_t entry
Definition: isohybrid.c:63
#define assert(x)
Definition: debug.h:53
smooth NULL
Definition: ftsmooth.c:416
Definition: hash.c:61
unsigned int GLuint
Definition: gl.h:159
#define TABLE_SIZE
Definition: hash.c:59
Definition: path.c:42

Referenced by execute_list(), gl_AreTexturesResident(), gl_BindTexture(), gl_DeleteTextures(), gl_destroy_list(), gl_IsList(), gl_IsTexture(), gl_PrioritizeTextures(), and HashFindFreeKeyBlock().

◆ HashPrint()

void HashPrint ( const struct HashTable table)

Definition at line 227 of file hash.c.

228 {
229  GLuint i;
230  assert(table);
231  for (i=0;i<TABLE_SIZE;i++) {
232  struct HashEntry *entry = table->Table[i];
233  while (entry) {
234  printf("%u %p\n", entry->Key, entry->Data);
235  entry = entry->Next;
236  }
237  }
238 }
uint8_t entry
Definition: isohybrid.c:63
#define assert(x)
Definition: debug.h:53
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
Definition: hash.c:61
unsigned int GLuint
Definition: gl.h:159
#define TABLE_SIZE
Definition: hash.c:59
#define printf
Definition: config.h:203

◆ HashRemove()

void HashRemove ( struct HashTable table,
GLuint  key 
)

Definition at line 176 of file hash.c.

177 {
178  GLuint pos;
179  struct HashEntry *entry, *prev;
180 
181  assert(table);
182  assert(key);
183 
184  pos = key % TABLE_SIZE;
185  prev = NULL;
186  entry = table->Table[pos];
187  while (entry) {
188  if (entry->Key == key) {
189  /* found it! */
190  if (prev) {
191  prev->Next = entry->Next;
192  }
193  else {
194  table->Table[pos] = entry->Next;
195  }
196  free(entry);
197  return;
198  }
199  prev = entry;
200  entry = entry->Next;
201  }
202 }
#define free
Definition: debug_ros.c:5
uint8_t entry
Definition: isohybrid.c:63
#define assert(x)
Definition: debug.h:53
smooth NULL
Definition: ftsmooth.c:416
Definition: hash.c:61
unsigned int GLuint
Definition: gl.h:159
#define TABLE_SIZE
Definition: hash.c:59
struct HashEntry * Next
Definition: hash.c:64
Definition: path.c:42

Referenced by gl_destroy_list(), and gl_free_texture_object().

◆ NewHashTable()

struct HashTable* NewHashTable ( void  )

Definition at line 77 of file hash.c.

78 {
79  return (struct HashTable *) calloc(sizeof (struct HashTable), 1);
80 }
Definition: hash.c:67
#define calloc
Definition: rosglue.h:14

Referenced by alloc_shared_state(), and WahInsertHandleContext().