[PATCH] D121817: [llvm][ADT] Add a method to MapVector for erasing a range of elements.

Alexandros Lamprineas via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 16 08:58:42 PDT 2022


labrinea created this revision.
labrinea added reviewers: ChuanqiXu, efriedma, dexonsmith, rnk.
Herald added a project: All.
labrinea requested review of this revision.
Herald added a project: LLVM.

We currently support two ways to erase elements in MapVector: either erase a single element in linear time, which is rather expensive, or erase multiple elements based on a predicate. However, we may want to erase a range of contiguous elements. Here's a motivating example, where the current API is suboptimal:

  MapVector.remove_if([&MapVector, N](const auto &Entry) {
    auto Iter = MapVector.find(Entry.first);
    return std::distance(Iter, MapVector.end()) > N;
  });

Instead we could do:

  N = MapVector.size() - N;
  MapVector.erase(MapVector.begin(), MapVector.begin() + N);


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121817

Files:
  llvm/include/llvm/ADT/MapVector.h
  llvm/unittests/ADT/MapVectorTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121817.415849.patch
Type: text/x-patch
Size: 3650 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220316/747939ed/attachment.bin>


More information about the llvm-commits mailing list