pintos/src/lib/kernel/hash.c File Reference

#include "hash.h"
#include "../debug.h"
#include "threads/malloc.h"

Go to the source code of this file.

Defines

#define list_elem_to_hash_elem(LIST_ELEM)   list_entry(LIST_ELEM, struct hash_elem, list_elem)
#define FNV_32_PRIME   16777619u
#define FNV_32_BASIS   2166136261u
#define MIN_ELEMS_PER_BUCKET   1
#define BEST_ELEMS_PER_BUCKET   2
#define MAX_ELEMS_PER_BUCKET   4

Functions

static struct listfind_bucket (struct hash *, struct hash_elem *)
static struct hash_elemfind_elem (struct hash *, struct list *, struct hash_elem *)
static void insert_elem (struct hash *, struct list *, struct hash_elem *)
static void remove_elem (struct hash *, struct hash_elem *)
static void rehash (struct hash *)
bool hash_init (struct hash *h, hash_hash_func *hash, hash_less_func *less, void *aux)
void hash_clear (struct hash *h, hash_action_func *destructor)
void hash_destroy (struct hash *h, hash_action_func *destructor)
struct hash_elemhash_insert (struct hash *h, struct hash_elem *new)
struct hash_elemhash_replace (struct hash *h, struct hash_elem *new)
struct hash_elemhash_find (struct hash *h, struct hash_elem *e)
struct hash_elemhash_delete (struct hash *h, struct hash_elem *e)
void hash_apply (struct hash *h, hash_action_func *action)
void hash_first (struct hash_iterator *i, struct hash *h)
struct hash_elemhash_next (struct hash_iterator *i)
struct hash_elemhash_cur (struct hash_iterator *i)
size_t hash_size (struct hash *h)
bool hash_empty (struct hash *h)
unsigned hash_bytes (const void *buf_, size_t size)
unsigned hash_string (const char *s_)
unsigned hash_int (int i)
static size_t turn_off_least_1bit (size_t x)
static size_t is_power_of_2 (size_t x)


Define Documentation

#define BEST_ELEMS_PER_BUCKET   2

Definition at line 344 of file hash.c.

Referenced by rehash().

#define FNV_32_BASIS   2166136261u

Definition at line 262 of file hash.c.

Referenced by hash_bytes(), and hash_string().

#define FNV_32_PRIME   16777619u

Definition at line 261 of file hash.c.

Referenced by hash_bytes(), and hash_string().

#define list_elem_to_hash_elem ( LIST_ELEM   )     list_entry(LIST_ELEM, struct hash_elem, list_elem)

Definition at line 12 of file hash.c.

Referenced by find_elem(), hash_apply(), hash_clear(), hash_first(), hash_next(), and rehash().

#define MAX_ELEMS_PER_BUCKET   4

Definition at line 345 of file hash.c.

#define MIN_ELEMS_PER_BUCKET   1

Definition at line 343 of file hash.c.


Function Documentation

static struct list * find_bucket ( struct hash h,
struct hash_elem e 
) [static, read]

Definition at line 306 of file hash.c.

References hash::aux, hash::bucket_cnt, hash::buckets, and hash::hash.

Referenced by hash_delete(), hash_find(), hash_insert(), hash_replace(), and rehash().

static struct hash_elem * find_elem ( struct hash h,
struct list bucket,
struct hash_elem e 
) [static, read]

void hash_apply ( struct hash h,
hash_action_func action 
)

unsigned hash_bytes ( const void *  buf_,
size_t  size 
)

Definition at line 266 of file hash.c.

References ASSERT, buf, FNV_32_BASIS, FNV_32_PRIME, and NULL.

Referenced by hash_int().

void hash_clear ( struct hash h,
hash_action_func destructor 
)

struct hash_elem* hash_cur ( struct hash_iterator i  )  [read]

Definition at line 241 of file hash.c.

References hash_iterator::elem.

struct hash_elem* hash_delete ( struct hash h,
struct hash_elem e 
) [read]

Definition at line 145 of file hash.c.

References find_bucket(), find_elem(), NULL, rehash(), and remove_elem().

void hash_destroy ( struct hash h,
hash_action_func destructor 
)

Definition at line 87 of file hash.c.

References hash::buckets, free(), hash_clear(), and NULL.

bool hash_empty ( struct hash h  ) 

Definition at line 255 of file hash.c.

References hash::elem_cnt.

struct hash_elem* hash_find ( struct hash h,
struct hash_elem e 
) [read]

Definition at line 132 of file hash.c.

References find_bucket(), and find_elem().

void hash_first ( struct hash_iterator i,
struct hash h 
)

bool hash_init ( struct hash h,
hash_hash_func hash,
hash_less_func less,
void *  aux 
)

struct hash_elem* hash_insert ( struct hash h,
struct hash_elem new 
) [read]

Definition at line 99 of file hash.c.

References find_bucket(), find_elem(), insert_elem(), NULL, and rehash().

unsigned hash_int ( int  i  ) 

Definition at line 299 of file hash.c.

References hash_bytes().

struct hash_elem* hash_next ( struct hash_iterator i  )  [read]

struct hash_elem* hash_replace ( struct hash h,
struct hash_elem new 
) [read]

Definition at line 115 of file hash.c.

References find_bucket(), find_elem(), insert_elem(), NULL, rehash(), and remove_elem().

size_t hash_size ( struct hash h  ) 

Definition at line 248 of file hash.c.

References hash::elem_cnt.

unsigned hash_string ( const char *  s_  ) 

Definition at line 283 of file hash.c.

References ASSERT, FNV_32_BASIS, FNV_32_PRIME, NULL, and s.

static void insert_elem ( struct hash h,
struct list bucket,
struct hash_elem e 
) [static]

Definition at line 417 of file hash.c.

References hash::elem_cnt, hash_elem::list_elem, and list_push_front().

Referenced by hash_insert(), and hash_replace().

static size_t is_power_of_2 ( size_t  x  )  [inline, static]

Definition at line 337 of file hash.c.

References turn_off_least_1bit().

Referenced by rehash().

static void rehash ( struct hash h  )  [static]

static void remove_elem ( struct hash h,
struct hash_elem e 
) [static]

Definition at line 425 of file hash.c.

References hash::elem_cnt, hash_elem::list_elem, and list_remove().

Referenced by hash_delete(), and hash_replace().

static size_t turn_off_least_1bit ( size_t  x  )  [inline, static]

Definition at line 330 of file hash.c.

Referenced by is_power_of_2(), and rehash().


Generated on Mon Jan 10 16:43:58 2011 for Pintos by  doxygen 1.5.6