KSH

Mar 12, 2021 - 1 minute read - csharp

Dictionary

Dictionary? Key, Value 값을 가진 Collection. (Hashtable로 구현 됨) 특징 해시함수를 통해 나온 키값을 bucket이라는 array에 저장한다. 이때, 해시는 고유하지 않으므로 충돌(Collision)이 날 수 있다. -> Collision Resolution을 통해 빈 버켓을 찾음) Collision Resolution C#은 Chaining 방식으로 충돌을 해결한다. Time Complexity 시간복잡도가 O(1)에 가까운게 bucket array 해시값으로 바로 접근하기 때문에 가능. TryGetValue() 구현을 보면 아래와 같다. public bool TryGetValue(TKey key, out TValue value) { int i = FindEntry(key); if (i >= 0) { value = entries[i].

Mar 10, 2021 - 1 minute read - csharp

Hashcode

목적 Hashtable, DictionaryBase 등 해시 기반 컬렉션에 개체 삽입 및 식별하는데 사용 A hash code is a numeric value that is used to insert and identify an object in a hash-based collection such as the Dictionary<TKey,TValue> class, the Hashtable class, or a type derived from the DictionaryBase class. 특징 Hash code는 유니크하지 않다. 고유 식별자로 사용하면 안된다. 동일한 해시 코드가 동일한 값을 보장하지도 않는다. -> 오브젝트의 equals 여부를 해시코드로 비교하면 안된다.