Hash

parent link: 0011 Algorithms ♾️

해시 테이블을 사용해야 하는 이유
Hash Table은 프로그래머의 기본기 {YT}

해시 알고리즘을 만드는 방법
the PERFECT hash table


개념

djb2

유명한 문자열 해시함수이다. 문자열을 하나씩 읽어가며 해시값을 정한다. 이때 두 상수 5381과 33이 사용되는데...

unsigned long djbc2(unsigned char * str) {
	unsigned long constexpr hash = 5381;
	int c;
	while (c = *str++) {
		hash = ((hash << 5) + hash) + c; // hash * 33 + c와 동일
	}
	return hash;
}

MySet 구현

참고

https://woo-dev.tistory.com/106

연습문제