hash.c revision cb63aae771b2cfe51259de09dbff5431739dcc55
/* Copyright (c) 2002-2008 Dovecot authors, see the included COPYING file */
/* @UNSAFE: whole file */
#include "lib.h"
#include "hash.h"
#include "primes.h"
#include <ctype.h>
#define HASH_TABLE_MIN_SIZE 131
struct hash_node {
void *key;
void *value;
};
struct hash_table {
int frozen;
unsigned int size;
struct hash_node *free_nodes;
};
struct hash_iterate_context {
struct hash_table *table;
unsigned int pos;
};
{
}
static unsigned int direct_hash(const void *p)
{
/* NOTE: may truncate the value, but that doesn't matter. */
return POINTER_CAST_TO(p, unsigned int);
}
struct hash_table *
{
struct hash_table *table;
return table;
}
{
else {
}
}
{
}
}
{
unsigned int i;
}
}
{
}
}
{
if (free_nodes) {
}
table->nodes_count = 0;
table->removed_count = 0;
}
static struct hash_node *
{
do {
return node;
}
return NULL;
}
{
}
{
return FALSE;
return TRUE;
}
static struct hash_node *
bool check_existing)
{
unsigned int hash;
/* there may be holes, have to check everything */
return node;
}
}
/* a) primary node */
table->nodes_count++;
return node;
}
if (check_existing) {
return node;
}
}
/* b) collisions list */
break;
if (check_existing) {
return node;
}
}
}
/* resized table, try again */
}
else {
}
}
table->nodes_count++;
return node;
}
{
}
{
}
{
/* remove deleted nodes from the list */
} else {
}
}
/* update root */
}
}
{
unsigned int i;
table->removed_count = 0;
}
{
unsigned int hash;
i_panic("key not found from hash");
table->nodes_count--;
table->removed_count++;
}
{
return table->nodes_count;
}
{
struct hash_iterate_context *ctx;
return ctx;
}
{
do {
return NULL;
}
}
return node;
}
{
return FALSE;
}
return TRUE;
}
{
}
{
}
{
return;
if (table->removed_count > 0) {
}
}
{
float nodes_per_list;
return FALSE;
return FALSE;
return FALSE;
/* recreate primary table */
table->nodes_count = 0;
table->removed_count = 0;
/* move the data */
for (i = 0; i < old_size; i++) {
}
}
}
return TRUE;
}
{
struct hash_iterate_context *iter;
}
/* a char* hash function from ASU -- from glib */
unsigned int str_hash(const void *p)
{
const unsigned char *s = p;
unsigned int g, h = 0;
while (*s != '\0') {
h = (h << 4) + *s;
if ((g = h & 0xf0000000UL)) {
h = h ^ (g >> 24);
h = h ^ g;
}
s++;
}
return h;
}
/* a char* hash function from ASU -- from glib */
unsigned int strcase_hash(const void *p)
{
const unsigned char *s = p;
unsigned int g, h = 0;
while (*s != '\0') {
h = (h << 4) + i_toupper(*s);
if ((g = h & 0xf0000000UL)) {
h = h ^ (g >> 24);
h = h ^ g;
}
s++;
}
return h;
}