Does the C++ STL set data structure have a set difference operator?
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- C#中 public virtual string Category { get; }这么写会报错:
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
The chosen answer is correct, but has some syntax errors.
Instead of
use
Instead of
use
All of the answers I see here are O(n). Wouldn't this be better?:
That seems to do the right thing. I'm not sure how to deal with the case that
Compare
's type doesn't fully specify its behavior, as in ifCompare
is astd::function<bool(int,int)>
, but aside from that, this seems to work right and should be like O((num overlapping) • log(lhs.size()
)).In the case that
lhs
doesn't contain*i
, it's probably possible to optimize further by doing an O(log(rhs.size()
)) search for the next element ofrhs
that's >= the next element oflhs
. That would optimize the case thatlhs = {0, 1000}
andrhs = {1, 2, ..., 999}
to do the subtraction in log time.Not as a method but there's the external algorithm function set_difference
http://www.sgi.com/tech/stl/set_difference.html
can we just use
Apparently, it does.
SGI - set_difference
Yes there is, it is in
<algorithm>
and is called:std::set_difference
. The usage is:In the end, the set
result
will contain thes1-s2
.