• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1.. _module-pw_containers-sets:
2
3====
4Sets
5====
6.. pigweed-module-subpage::
7   :name: pw_containers
8
9A set is an unordered collection of items. Pigweed provides implementations that
10can insert, find, and remove items in logarithmic time.
11
12.. _module-pw_containers-intrusive_set:
13
14----------------
15pw::IntrusiveSet
16----------------
17``pw::IntrusiveSet`` provides an embedded-friendly, tree-based, intrusive
18set implementation. The intrusive aspect of the set is very similar to that of
19:ref:`module-pw_containers-intrusive_list`.
20
21See also :ref:`module-pw_containers-multiple_containers`.
22
23Example
24=======
25.. literalinclude:: examples/intrusive_set.cc
26   :language: cpp
27   :linenos:
28   :start-after: [pw_containers-intrusive_set]
29   :end-before: [pw_containers-intrusive_set]
30
31If you need to add this item to containers of more than one type, see
32:ref:`module-pw_containers-multiple_containers`,
33
34API reference
35=============
36This class is similar to ``std::set<T>``. Items to be added must derive from
37``pw::IntrusiveSet<T>::Item`` or an equivalent type.
38
39.. doxygenclass:: pw::IntrusiveSet
40   :members:
41
42---------------------
43pw::IntrusiveMultiSet
44---------------------
45``pw::IntrusiveMultiSet`` provides an embedded-friendly, tree-based, intrusive
46multiset implementation. This is very similar to
47:ref:`module-pw_containers-intrusive_set`, except that the tree may contain
48multiple items with equivalent keys.
49
50See also :ref:`module-pw_containers-multiple_containers`.
51
52Example
53=======
54.. literalinclude:: examples/intrusive_multiset.cc
55   :language: cpp
56   :linenos:
57   :start-after: [pw_containers-intrusive_multiset]
58   :end-before: [pw_containers-intrusive_multiset]
59
60If you need to add this item to containers of more than one type, see
61:ref:`module-pw_containers-multiple_containers`,
62
63API reference
64=============
65This class is similar to ``std::multiset<T>``. Items to be added must derive
66from ``pw::IntrusiveMultiSet<T>::Item`` or an equivalent type.
67
68.. doxygenclass:: pw::IntrusiveMultiSet
69   :members:
70
71Size reports
72------------
73The tables below illustrate the following scenarios:
74
75* Scenarios related to ``IntrusiveSet``:
76
77  * The memory and code size cost incurred by a adding a single
78    ``IntrusiveSet``.
79  * The memory and code size cost incurred by adding another ``IntrusiveSet``
80    with a different type. As ``IntrusiveSet`` is templated on type, this
81    results in additional code being generated.
82
83* Scenarios related to ``IntrusiveMultiSet``:
84
85  * The memory and code size cost incurred by a adding a single
86    ``IntrusiveMultiSet``.
87  * The memory and code size cost incurred by adding another
88    ``IntrusiveMultiSet`` with a different type. As ``IntrusiveMultiSet`` is
89    templated on type, this results in additional code being generated.
90
91* The memory and code size cost incurred by a adding both an ``IntrusiveSet``
92  and an ``IntrusiveMultiSet`` of the same type. These types reuse code, so the
93  combined sum is less than the sum of its parts.
94
95.. TODO: b/388905812 - Re-enable the size report.
96.. .. include:: sets_size_report
97.. include:: ../size_report_notice
98