구조체 안에 struct hash_elem; 를 사용 (해시 테이블에 포함시키고 싶은 구조체의 멤버로 삽입)

struct hash_elem {
	struct list_elem list_elem;
};
#define hash_entry(HASH_ELEM, STRUCT, MEMBER)                   \\
	((STRUCT *) ((uint8_t *) &(HASH_ELEM)->list_elem        \\
		- offsetof (STRUCT, MEMBER.list_elem)))

인자

예시

struct hash_elem * h

h가 가리키는 것은 thread 구조체의 멤버변수 struct hash_elem h_elem 라고 할때

hash_entry (h, struct thread, h_elem)

위의 함수는 h가 가리키는 struct thread의 주소를 반환합니다.

해시 테이블의 key에 동작하는 두 개의 함수 hash & comparison

typedef unsigned hash_hash_func (const struct hash_elem *e, void *aux);

핀토스가 제공하는 해싱 함수

// buf 에서 시작하는 size 만큼의 byte를 해싱한 값을 리턴
unsigned hash_bytes (const void *buf, size t *size)

//문자열을 해싱한 값을 리턴
unsigned hash_string (const char *s)

// 정수 i를 해싱한 값을 리턴 
unsigned hash_int (int i)