X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flib%2Fkernel%2Fhash.h;h=db9f6746431a4aa24f60baf762b2c37fb965275e;hb=f294e7e618e110f8203ea7cf800acb2e1334774b;hp=b6423386c0929c122b76b24965890c70df6fdf15;hpb=96c122af8890db8f39dfd2ee21df761c6131e8f5;p=pintos-anon diff --git a/src/lib/kernel/hash.h b/src/lib/kernel/hash.h index b642338..db9f674 100644 --- a/src/lib/kernel/hash.h +++ b/src/lib/kernel/hash.h @@ -3,6 +3,9 @@ /* Hash table. + This data structure is thoroughly documented in the Tour of + Pintos for Project 3. + This is a standard hash table with chaining. To locate an element in the table, we compute a hash function over the element's data and use that as an index into an array of @@ -15,10 +18,7 @@ conversion from a struct hash_elem back to a structure object that contains it. This is the same technique used in the linked list implementation. Refer to lib/kernel/list.h for a - detailed explanation. - - The FAQ for the VM project contains a detailed example of how - to use the hash table. */ + detailed explanation. */ #include #include @@ -36,8 +36,9 @@ struct hash_elem name of the outer structure STRUCT and the member name MEMBER of the hash element. See the big comment at the top of the file for an example. */ -#define hash_entry(HASH_ELEM, STRUCT, MEMBER) \ - ((STRUCT *) ((uint8_t *) (HASH_ELEM) - offsetof (STRUCT, MEMBER))) +#define hash_entry(HASH_ELEM, STRUCT, MEMBER) \ + ((STRUCT *) ((uint8_t *) &(HASH_ELEM)->list_elem \ + - offsetof (STRUCT, MEMBER.list_elem))) /* Computes and returns the hash value for hash element E, given auxiliary data AUX. */ @@ -50,6 +51,10 @@ typedef bool hash_less_func (const struct hash_elem *a, const struct hash_elem *b, void *aux); +/* Performs some operation on hash element E, given auxiliary + data AUX. */ +typedef void hash_action_func (struct hash_elem *e, void *aux); + /* Hash table. */ struct hash { @@ -71,8 +76,8 @@ struct hash_iterator /* Basic life cycle. */ bool hash_init (struct hash *, hash_hash_func *, hash_less_func *, void *aux); -void hash_clear (struct hash *); -void hash_destroy (struct hash *); +void hash_clear (struct hash *, hash_action_func *); +void hash_destroy (struct hash *, hash_action_func *); /* Search, insertion, deletion. */ struct hash_elem *hash_insert (struct hash *, struct hash_elem *); @@ -81,6 +86,7 @@ struct hash_elem *hash_find (struct hash *, struct hash_elem *); struct hash_elem *hash_delete (struct hash *, struct hash_elem *); /* Iteration. */ +void hash_apply (struct hash *, hash_action_func *); void hash_first (struct hash_iterator *, struct hash *); struct hash_elem *hash_next (struct hash_iterator *); struct hash_elem *hash_cur (struct hash_iterator *);