ReactOS  0.4.12-dev-102-g4b7f1e0
hash.c File Reference
#include <rosdhcp.h>
Include dependency graph for hash.c:

Go to the source code of this file.

Macros

#define lint
 

Functions

static __inline int do_hash PROTO ((unsigned char *, int, int))
 
struct hash_tablenew_hash ()
 
static __inline int do_hash (unsigned char *name, int len, int size)
 
void add_hash (struct hash_table *table, unsigned char *name, int len, unsigned char *pointer)
 
void delete_hash_entry (struct hash_table *table, unsigned char *name, int len)
 
unsigned charhash_lookup (struct hash_table *table, unsigned char *name, int len)
 

Macro Definition Documentation

◆ lint

#define lint

Definition at line 43 of file hash.c.

Referenced by AlgTest::search_n_test(), and wmain().

Function Documentation

◆ add_hash()

void add_hash ( struct hash_table table,
unsigned char name,
int  len,
unsigned char pointer 
)

Definition at line 82 of file hash.c.

Referenced by assign_file_addresses(), assign_inodes(), compute_linkcount(), endpad_write(), initialize_universes(), and root_gen().

87 {
88  int hashno;
89  struct hash_bucket *bp;
90 
91  if (!table)
92  return;
93  if (!len)
94  len = strlen ((char *)name);
95 
96  hashno = do_hash (name, len, table -> hash_count);
97  bp = new_hash_bucket ();
98 
99  if (!bp) {
100  warn ("Can't add %s to hash table.", name);
101  return;
102  }
103  bp -> name = name;
104  bp -> value = pointer;
105  bp -> next = table -> buckets [hashno];
106  bp -> len = len;
107  table -> buckets [hashno] = bp;
108 }
Definition: get.c:139
#define warn(...)
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLsizei const GLvoid * pointer
Definition: glext.h:5848
static __inline int do_hash(unsigned char *name, int len, int size)
Definition: hash.c:63
GLenum GLsizei len
Definition: glext.h:6722
static unsigned __int64 next
Definition: rand_nt.c:6
Definition: name.c:36
struct hash_bucket * new_hash_bucket(void)
Definition: alloc.c:71
GLuint const GLchar * name
Definition: glext.h:6031

◆ delete_hash_entry()

void delete_hash_entry ( struct hash_table table,
unsigned char name,
int  len 
)

Definition at line 110 of file hash.c.

114 {
115  int hashno;
116  struct hash_bucket *bp, *pbp = (struct hash_bucket *)0;
117 
118  if (!table)
119  return;
120  if (!len)
121  len = strlen ((char *)name);
122 
123  hashno = do_hash (name, len, table -> hash_count);
124 
125  /* Go through the list looking for an entry that matches;
126  if we find it, delete it. */
127  for (bp = table -> buckets [hashno]; bp; bp = bp -> next) {
128  if ((!bp -> len &&
129  !strcmp ((char *)bp -> name, (char *)name)) ||
130  (bp -> len == len &&
131  !memcmp (bp -> name, name, len))) {
132  if (pbp) {
133  pbp -> next = bp -> next;
134  } else {
135  table -> buckets [hashno] = bp -> next;
136  }
137  free_hash_bucket (bp, "delete_hash_entry");
138  break;
139  }
140  pbp = bp; /* jwg, 9/6/96 - nice catch! */
141  }
142 }
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
static __inline int do_hash(unsigned char *name, int len, int size)
Definition: hash.c:63
void free_hash_bucket(struct hash_bucket *ptr, char *name)
Definition: alloc.c:89
GLenum GLsizei len
Definition: glext.h:6722
static unsigned __int64 next
Definition: rand_nt.c:6
Definition: name.c:36
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469

◆ do_hash()

static __inline int do_hash ( unsigned char name,
int  len,
int  size 
)
static

Definition at line 63 of file hash.c.

Referenced by add_hash(), delete_hash_entry(), collate< char >::hash(), collate< wchar_t >::hash(), and hash_lookup().

67 {
68  register int accum = 0;
69  register unsigned char *s = name;
70  int i = len;
71  while (i--) {
72  /* Add the character in... */
73  accum += *s++;
74  /* Add carry back in... */
75  while (accum > 255) {
76  accum = (accum & 255) + (accum >> 8);
77  }
78  }
79  return accum % size;
80 }
GLenum GLclampf GLint i
Definition: glfuncs.h:14
GLsizeiptr size
Definition: glext.h:5919
GLenum GLsizei len
Definition: glext.h:6722
GLdouble s
Definition: gl.h:2039
GLuint const GLchar * name
Definition: glext.h:6031

◆ hash_lookup()

unsigned char* hash_lookup ( struct hash_table table,
unsigned char name,
int  len 
)

Definition at line 144 of file hash.c.

148 {
149  int hashno;
150  struct hash_bucket *bp;
151 
152  if (!table)
153  return (unsigned char *)0;
154 
155  if (!len)
156  len = strlen ((char *)name);
157 
158  hashno = do_hash (name, len, table -> hash_count);
159 
160  for (bp = table -> buckets [hashno]; bp; bp = bp -> next) {
161  if (len == bp -> len && !memcmp (bp -> name, name, len))
162  return bp -> value;
163  }
164  return (unsigned char *)0;
165 }
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
static __inline int do_hash(unsigned char *name, int len, int size)
Definition: hash.c:63
GLenum GLsizei len
Definition: glext.h:6722
GLsizei const GLfloat * value
Definition: glext.h:6069
static unsigned __int64 next
Definition: rand_nt.c:6
Definition: name.c:36

◆ new_hash()

struct hash_table* new_hash ( void  )

Definition at line 53 of file hash.c.

Referenced by initialize_universes().

54 {
56  if (!rv)
57  return rv;
58  memset (&rv -> buckets [0], 0,
59  DEFAULT_HASH_SIZE * sizeof (struct hash_bucket *));
60  return rv;
61 }
struct hash_bucket * buckets[DEFAULT_HASH_SIZE]
Definition: dhcpd.h:270
struct hash_table * new_hash_table(int count)
Definition: alloc.c:57
#define DEFAULT_HASH_SIZE
Definition: dhcpd.h:259
#define memset(x, y, z)
Definition: compat.h:39

◆ PROTO()

static __inline int do_hash PROTO ( (unsigned char *, int, int )
static