[PATCH] D48504: [WIP] Add InsertionOrderSet, with constant-time insertion and removal.

George Burgess IV via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 22 12:58:28 PDT 2018


george.burgess.iv added a comment.

Thinking out loud: I wonder how often people ask for insertion order but only actually care about having a consistent order.

If the primary use-case we care about is "I inserted X, Y, Z, A, and removed Z. I expect to iterate over X, Y, and A in some order that's consistent across reruns regardless of what these hashed to/etc, but I don't actually care that X comes before Y and A," then we can probably be clever to save some space:

  void remove(ValueT value) {
    auto MapFind = Map.find(value);
    if (MapFind != Map.end()) {
      size_t Index = MapFind->second;
      Map.erase(MapFind);
      if (Index != size() - 1) {
        swap(Vec[Index], Vec.back());
        Map.find(Vec[Index])->second = I;
      }
      Vec.pop_back();
    }
  }

...Which would also let us get rid of the Optional.


Repository:
  rL LLVM

https://reviews.llvm.org/D48504





More information about the llvm-commits mailing list