Despite what others have written here, I don't think that “index” or “position” makes sense with respect to recruitment. In mathematical terms, a set provides only its members and, possibly, its power. The only significant operations include testing whether an element is a member of a set, and combining or subtracting sets to obtain new sets.
Some people talk about sets as data structures in weaker terms, the facets of “ordered” or “disordered,” and whether they allow duplication or application of uniqueness. In the previous aspect, an array with O (n) insert protection is allocated, where an attempt to insert an element first checks existing elements to see if a new element exists, and if not, inserts a new element at the end and hash a table that can only maintain such an order in bucket chain. A tree, such as the Red-Black Tree used by std::set , is somewhere in the middle; its traversal order is deterministic with respect to the strict weak order superimposed by the predicate of the comparator, but, unlike the array described above, it does not preserve the insertion order.
Another facet - regardless of whether the set allows duplicate elements - is meaningless in mathematics and more accurately described as a bag. Such a structure recognizes the difference between identity and value-based “identity”.
Your problem may be to take care of some position; it is not clear what this position means, but I expect that you will need some kind of data structure other than std::set in order to model it correctly. Perhaps this will make std::map map from your set of elements to each position. This does not guarantee that the positions are unique.
It can also help clarify the problem, to think about how you could model it as a relationship, for example, in a relational database. What does the key include? What parts of entities can change independently?
seh
source share