[Go] Map ์๋ฆฌ์ ํ์ฉ(feat. hash)
ยท
ํ๋ก๊ทธ๋๋ฐ ์ธ์ด/Go
์๊ฐGo์ map์ ๋งค์ฐ ์ค์ํ ๋ด์ฅ ์๋ฃ๊ตฌ์กฐ๋ก, key-value ํํ์ ํด์ ํ
์ด๋ธ(hash table) ๊ธฐ๋ฐ ์ปจํ
์ด๋์
๋๋ค.์๋ฆฌ (๋ด๋ถ ๊ตฌ์กฐ)Go์ map์ hash table์ ๊ธฐ๋ฐ์ผ๋ก ๊ตฌํ๋์ด ์์ต๋๋ค.ํต์ฌ ๊ฐ๋
Key → Hashing → Bucket → Valueํด์ ํจ์(hash(key))๋ฅผ ํตํด ๋ฒํท(bucket) ์ธ๋ฑ์ค๋ฅผ ๊ณ์ฐํ๊ณ , ๊ทธ ๋ฒํท์ key-value ์์ ์ ์ฅํฉ๋๋ค.ํด์ ์ถฉ๋์ด ๋ฐ์ํ๋ฉด ๊ฐ์ ๋ฒํท ์์ ์ฌ๋กฏ์ ์ฒด์ด๋(chaining) ํํ๋ก ์ ์ฅํฉ๋๋ค.๋ด๋ถ ๊ตฌ์กฐ ๊ฐ์Go ๋ฐํ์์์ map์ ๋ค์๊ณผ ๊ฐ์ ๊ตฌ์กฐ๋ก ๊ด๋ฆฌ๋ฉ๋๋ค (runtime/map.go ์ฐธ๊ณ ):type hmap struct { count int // ์์ ๊ฐ์ flags u..