[LLVMdev] Best method for filtering LLVM container types?
atrick at apple.com
Mon Jul 11 10:59:27 PDT 2011
On Jul 9, 2011, at 11:30 AM, Talin wrote:
> I'm using the various LLVM set containers (SmallPtrSet and the like), and something I need to do fairly often is iterate over a set, removing all elements that don't pass a test. Now, doing this on lists is fairly straightforward using the "it = container.erase(it)" idiom so as to keep the iterator valid during the delete. However, the set classes don't have a means to both iterate and mutate the set at the same time. This means that I tend to use SmallVector in a lot of places where I really want to use a set. In other cases I copy from one set to another as I'm filtering, although I'm concerned about the overhead of copying the set.
> What I'm wondering is what's the best practice for these kinds of operations?
I'm not sure if LLVM has a preferred idiom, although I'm sure copying elements is fine in most cases.
Ideally, SmallSet iterators would work just like std::set iterators so the containers would be interchangeable. But I don't see an easy way to implement those semantics. Unless I'm missing something, it seems fairly easy to implement it = container.erase(it) in SmallSet with some care to check for underlying container switches, I'm just not sure what to call it, erase_advance? Alternatively, SmallSet could have an "erase_if" member function.
More information about the llvm-dev