본문 바로가기

컴퓨터 과학 & 영상처리 관련/C# / .NET / JAVA

C# hashset<int> 이게 뭐여

Hashtable 과 Dictionary 는 둘 다 IDictionary 를 구현하고 있다.

다만 Hashtable 은 제너릭을 지원하지 않고, Dictionary<TKey, TValue> 는 제너릭을 지원한다.


HashSet<T> 은 제너릭은 지원하지만 키를 사용자에게 입력받지 않고

값을 이용하여 해시코드를 구한다.

이걸 어디에 쓸까 싶었지만, 중복값제거에 용의한듯하다.


참고 : http://chaoskcuf.com/191


출처 : http://hsj0511.tistory.com/325


 HashSet<string> set = new HashSet<string>();

            using (TextReader reader = File.OpenText("test.txt"))
            {
                string line = reader.ReadLine();
                while (string.IsNullOrEmpty(line) == false)
                {
                    set.Add(line);
                    line = reader.ReadLine();
                }
            }

            foreach (string setItem in set)
            {
                Console.WriteLine(setItem);
            }

위와 같이 쓰면 line으로 입력받은 문자 중 중복되는 것들은 hashset에서 같은 hash같으로 나와서 하나만 처리되는 듯


Accord.NET에서 SVM의 ActiveExamples가 HashSet<int> 형태로 제공됨


HashSet<int> hash = smo.ActiveExamples; Console.WriteLine(hash.Count.ToString()); foreach (int i in hash) { Console.WriteLine(i.ToString()); }

위와 같이 그냥 중복되는 값 제거되고 값 얻는 정도인가

아 씹팔 이런걸 좀 공부하고 써먹고 싶었는데 졸업할라면 따른데서 뺑이쳐야되니...