[C++ STL] set

์˜ค์ ผยท2022๋…„ 10์›” 7์ผ
0

[C++ STL]

๋ชฉ๋ก ๋ณด๊ธฐ
3/11

template <typename Key,							   // set::key_type/value_type
		  typename Compare = std::less<Key>,	   // set::key_compare/value_compare
		  typename Alloc = std::allocator<Key> // set::allocator_type
		  > class set;

Description

  • Sets are containers that store unique elements following a specific order.

    ๐Ÿ‘‰ set์€ unique element๋ฅผ ๊ฐ€์ง€๊ณ  ํŠน์ • ์ˆœ์„œ์— ๋”ฐ๋ผ ์ €์žฅํ•˜๋Š” ์ปจํ…Œ์ด๋„ˆ

  • The value of the elements in a set cannot be modified once in the container (the elements are always const), but they can be inserted or removed from the container.

    ๐Ÿ‘‰ set์˜ element๋Š” const์ž„. ์ˆ˜์ •๋  ์ˆ˜ ์—†์Œ. ๋Œ€์‹  ์ปจํ…Œ์ด๋„ˆ์—์„œ ์‚ฝ์ž…๋˜๊ฑฐ๋‚˜ ์‚ญ์ œ๋  ์ˆ˜๋Š” ์žˆ์Œ.

  • Sets are typically implemented as binary search trees.
    ๐Ÿ‘‰ set์€ ์ผ๋ฐ˜์ ์œผ๋กœ bst๋กœ ๊ตฌํ˜„๋œ๋‹ค. gcc์˜ ๊ฒฝ์šฐ rbtree๋กœ ๊ตฌํ˜„๋ผ์žˆ์Œ.

Member types

  • map๊ณผ ๋‹ค๋ฅธ ์ ์€ key_type๊ณผ value_type์ด ๊ฐ™๋‹ค๋Š” ๊ฒƒ. pair๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค๋Š” ๊ฒƒ.
  • value_compare๋„ ๊ทธ๋ƒฅ key_compare๋กœ ์‚ฌ์šฉํ•ด์ฃผ๋ฉด ๋œ๋‹ค๋Š” ๊ฒƒ.

Member functions

  • https://cplusplus.com/reference/set/set/
  • ๊ฑ map์ด๋ž‘ ๊ฑฐ์˜ ๋น„์Šทํ•จ.
    map ์„ค๋ช… ๐Ÿ‘‰ https://velog.io/@zhy2on/C-STL-map
  • ๋‹ค๋ฅธ ์  1. operator[]์ด ์—†์Œ. ์™œ๋ƒ๋ฉด set์€ key ์ž์ฒด๊ฐ€ ๊ณง value๋‹ˆ๊นŒ.
  • ๋‹ค๋ฅธ ์  2. rbDelete ์‚ฌ์šฉํ•  ๋•Œ ์ธ์ž๋กœ ๋„˜๊ฒจ์ฃผ๋Š” node_ptr์„ const_cast ํ•ด์ค˜์•ผ ํ•จ.

0๊ฐœ์˜ ๋Œ“๊ธ€