공부/C++

    [C++] vector [], at 속도차이와 고찰

    C++ 에서 Vector 컨테이너는 index를 조회하는 두가지 함수를 제공한다. 아래 두개가 그 예시이다. v.at(index); v[index]; 이것의 차이점은 그러면 무엇일까? 우선 인터넷을 찾아보면 쉽게 알수 있는 정보는 다음과 같다. v.at(index)를 사용하면, 범위를 점검하기에 안전하고, v[index]는 범위를 점검하지 않기에 빠르다. 범위를 점검한다? 도대체 무슨 범위를 점검 하는 것일까? 한번 좀더 디테일하게 살펴보도록 하자. 실제로 vector header의 at method를 살펴보면, (line 1557~) input으로 들어온 index가 벡터의 사이즈를 초과하면, throw 하게 되어있음을 확인 할 수 있다. 당연히 이러한 범위 체크 과정이 들어가기에 속도는 느릴 수 밖에..

    [C++] map과 defaultdict

    https://www.geeksforgeeks.org/default-values-in-a-map-in-c-stl/ Default values in a Map in C++ STL - GeeksforGeeks A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions. www.geeksforgeeks.org C++에서 map자료구조는 처음 선언 될 때는 empty하다. 하지만, [] 등으로 조회..