hash.cc File Reference
#include "squid.h"
#include "hash.h"
#include "profiler/Profiler.h"
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
Include dependency graph for hash.cc:

Go to the source code of this file.

Macros

#define HASH4a   h = (h << 5) - h + *key++;
 
#define HASH4b   h = (h << 5) + h + *key++;
 
#define HASH4   HASH4b
 

Functions

static void hash_next_bucket (hash_table *hid)
 
unsigned int hash_string (const void *data, unsigned int size)
 
unsigned int hash4 (const void *data, unsigned int size)
 
hash_tablehash_create (HASHCMP *cmp_func, int hash_sz, HASHHASH *hash_func)
 
void hash_join (hash_table *hid, hash_link *lnk)
 
hash_linkhash_lookup (hash_table *hid, const void *k)
 
void hash_first (hash_table *hid)
 
hash_linkhash_next (hash_table *hid)
 
void hash_last (hash_table *hid)
 
void hash_remove_link (hash_table *hid, hash_link *hl)
 
hash_linkhash_get_bucket (hash_table *hid, unsigned int bucket)
 
void hashFreeItems (hash_table *hid, HASHFREE *free_func)
 
void hashFreeMemory (hash_table *hid)
 
int hashPrime (int n)
 
const char * hashKeyStr (hash_link *hl)
 

Variables

static int hash_primes []
 

Macro Definition Documentation

#define HASH4   HASH4b

Referenced by hash4().

#define HASH4a   h = (h << 5) - h + *key++;
#define HASH4b   h = (h << 5) + h + *key++;

Function Documentation

unsigned int hash4 ( const void *  data,
unsigned int  size 
)

Definition at line 51 of file hash.cc.

References data, HASH4, key, len, and size.

hash_table* hash_create ( HASHCMP cmp_func,
int  hash_sz,
HASHHASH hash_func 
)

hash_create - creates a new hash table, uses the cmp_func to compare keys. Returns the identification for the hash table; otherwise returns a negative number on error.

Definition at line 109 of file hash.cc.

void hash_first ( hash_table hid)

hash_first - initializes the hash table for the hash_next() function.

Definition at line 176 of file hash.cc.

Referenced by hashFreeItems().

hash_link* hash_get_bucket ( hash_table hid,
unsigned int  bucket 
)

hash_get_bucket - returns the head item of the bucket in the hash table 'hid'. Otherwise, returns NULL on error.

Definition at line 248 of file hash.cc.

void hash_join ( hash_table hid,
hash_link lnk 
)

hash_join - joins a hash_link under its key lnk->key into the hash table 'hid'.

It does not copy any data into the hash table, only links pointers.

Definition at line 132 of file hash.cc.

void hash_last ( hash_table hid)

hash_last - resets hash traversal state to NULL

Definition at line 208 of file hash.cc.

References assert, hash_table::current_slot, hash_table::next, and NULL.

Referenced by client_entry().

hash_link* hash_lookup ( hash_table hid,
const void *  k 
)

hash_lookup - locates the item under the key 'k' in the hash table 'hid'. Returns a pointer to the hash bucket on success; otherwise returns NULL.

Definition at line 147 of file hash.cc.

Referenced by hash_lookup().

hash_link* hash_next ( hash_table hid)

hash_next - returns the next item in the hash table 'hid'. Otherwise, returns NULL on error or end of list.

MUST call hash_first() before hash_next().

Definition at line 192 of file hash.cc.

Referenced by hashFreeItems().

static void hash_next_bucket ( hash_table hid)
static
void hash_remove_link ( hash_table hid,
hash_link hl 
)

hash_remove_link - deletes the given hash_link node from the hash table 'hid'. Does not free the item, only removes it from the list.

An assertion is triggered if the hash_link is not found in the list.

Definition at line 224 of file hash.cc.

unsigned int hash_string ( const void *  data,
unsigned int  size 
)

Definition at line 31 of file hash.cc.

References data, i, and size.

void hashFreeMemory ( hash_table hid)

Definition at line 272 of file hash.cc.

int hashPrime ( int  n)

Definition at line 297 of file hash.cc.

References hash_primes, i, log(), and min().

Referenced by externalAclInit(), fqdncache_init(), Ident::Init(), ipcache_init(), and netdbInit().

Variable Documentation

int hash_primes[]
static
Initial value:
= {
103,
229,
467,
977,
1979,
4019,
6037,
7951,
12149,
16231,
33493,
65357
}

Definition at line 281 of file hash.cc.

Referenced by hashPrime().

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors