[llvm] r175449 - Add front/back/erase to MapVector.

Sean Silva silvas at purdue.edu
Tue Feb 19 08:25:05 PST 2013


> Since the map's values are indices into the vector by element number (ie.,
> "the 12th element in the vector"), if you delete from the middle of the
> vector all the map entries which point past it are now wrong.
>
> Please revert this part of the change, or fix it either by leaving behind a
> tombstone in the vector or by doing a scan through the entire map to update
> any out of date entries (and probably rename it the same name with a
> different memory/performance guarantee will be deceptive).

The tombstone approach could lead to unbounded memory growth if
implemented naively (repeated insertion and then deletion would permit
the accumulation of an unbounded number of tombstones).

A possible solution to this is to use an "amortized" approach where
the tombstones are flushed periodically (in analyzing the complexity,
this O(n) tombstone cleanup can notionally be done "when the vector is
resized", and thus incur no overall complexity cost).

Another option which seems better is to have the tombstones form a
"linked list" (a "free list") and maintain a single "pointer" to the
head of that list; the iteration order of the container would remain
deterministic, but not be quite as nice (i.e. not insertion order).

-- Sean Silva



More information about the llvm-commits mailing list