ReactOS 0.4.16-dev-122-g325d74c
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.

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.

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}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
struct hash_bucket * new_hash_bucket(void)
Definition: alloc.c:71
static __inline int do_hash(unsigned char *name, int len, int size)
Definition: hash.c:63
GLsizei const GLvoid * pointer
Definition: glext.h:5848
GLenum GLsizei len
Definition: glext.h:6722
static unsigned __int64 next
Definition: rand_nt.c:6
#define warn(...)
unsigned char * name
Definition: dhcpd.h:263
Definition: name.c:39
Definition: pdh_main.c:94

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

◆ 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 strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
void free_hash_bucket(struct hash_bucket *ptr, char *name)
Definition: alloc.c:89

◆ do_hash()

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

Definition at line 63 of file hash.c.

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}
GLdouble s
Definition: gl.h:2039
GLsizeiptr size
Definition: glext.h:5919
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

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

◆ 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}
unsigned char * value
Definition: dhcpd.h:265

◆ new_hash()

struct hash_table * new_hash ( void  )

Definition at line 53 of file hash.c.

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_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
struct hash_bucket * buckets[DEFAULT_HASH_SIZE]
Definition: dhcpd.h:270

Referenced by initialize_universes(), and test_put_hash().

◆ PROTO()

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