Fabric: Small improvements in Differentiator/TinyMap

Summary:
What's changed:
 * `end()` now returns the pointer to the imaginary element after the very last one (which is aligned with STL);
 * `erase()` now swaps the removing and the last elements and shrinks the size of an array.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D19965405

fbshipit-source-id: 92eedf38d55be35a0d9ab6120634b51c8d6e4674
This commit is contained in:
Valentin Shergin
2020-03-02 23:03:01 -08:00
committed by Facebook Github Bot
parent c2de99662e
commit b41307af77
@@ -45,11 +45,11 @@ class TinyMap final {
using Iterator = Pair *;
inline Iterator begin() {
return (Pair *)vector_;
return &vector_.front();
}
inline Iterator end() {
return nullptr;
return &vector_.back() + 1;
}
inline Iterator find(KeyT key) {
@@ -68,11 +68,8 @@ class TinyMap final {
}
inline void erase(Iterator iterator) {
static_assert(
std::is_same<KeyT, Tag>::value,
"The collection is designed to store only `Tag`s as keys.");
// Zero is a invalid tag.
iterator->first = 0;
*iterator = vector_.at(vector_.size() - 1);
vector_.pop_back();
}
private: