LinkedHashSet
-
Set에 대하여 2 : 주요 구현체개발 나누고 더하기/자바, 스프링 2023. 6. 25. 22:59
이전 글(https://baby-care-dev.tistory.com/47)에서는 Set의 구조와 메서드에 대해 알아봤다. 메서드 동작은 알았지만 구현체별로 어떻게 내부가 처리되는지도 궁금하다. 예를 들면 TreeSet이나 LinkedHashSet은 어떻게 순서를 보장하는지 등 말이다. 이번에는 구현체별 특징과 공통점/차이점에 대해 알아보자. Set 상속 구조 위 그림에 나온 구현체들 보다 많은 구현 클래스들이 존재하는데, 일단 이정도만 알아도 될 듯 싶다. 모두 공통적으로 AbstractSet이라는 추상 클래스를 상속받고 있다. 이 AbstractSet에서 추상화된 공통점을 파악할 수 있으니 먼저 알아보자. AbstractSet 제공하는 메서드는 equals, hashCode, removeAll이다. ..
-
Set에 대하여 1 : 구조와 주요 메서드개발 나누고 더하기/자바, 스프링 2023. 6. 23. 23:39
Set은 내가 좋아하는 자료구조이다. 중복없이 원소들을 담아놓은 집합체이고, 용도도 중복 검사로 주로 쓰이는 아주 군더더기 없는 구성이라 뭔가 깔끔하다. 그런데 이번에 Set을 org.springframework.cache.annotation.Cacheable에 사용하다 버그를 만들어냈다. 왜 그렇게 생각했는지 모르겠는데 레디스가 Set을 지원하니 key에 사용되는 타입도 Set을 지원할 줄 알았다. 하지만 Key는 정직하게 스트링 값으로만 비교를 했고, 의도치 않게 여러가지 버전의 캐시를 만들어 내고 말았다. 대략 아래 코드와 같았다. List로 할까 고민했었는데, 좀 안일했었다. 로컬과 개발(인스턴스 2대) 환경에서 테스트해도 문제가 없었지만 운영환경에서 몇십대(정확한 대수는 공개하기 민감하므로^^)..