tp: rename SparseVector -> NullableVector

Given that the container can be both dense and sparse, it makes sense to
rename to better reflect its true purpose.

Change-Id: I4b558cf46819a34559e489c293bc4bc7eacd0368
diff --git a/Android.bp b/Android.bp
index dfb1249..886f6a3 100644
--- a/Android.bp
+++ b/Android.bp
@@ -6481,8 +6481,8 @@
   srcs: [
     "src/trace_processor/containers/bit_vector.cc",
     "src/trace_processor/containers/bit_vector_iterators.cc",
+    "src/trace_processor/containers/nullable_vector.cc",
     "src/trace_processor/containers/row_map.cc",
-    "src/trace_processor/containers/sparse_vector.cc",
     "src/trace_processor/containers/string_pool.cc",
   ],
 }
@@ -6493,8 +6493,8 @@
   srcs: [
     "src/trace_processor/containers/bit_vector_unittest.cc",
     "src/trace_processor/containers/null_term_string_view_unittest.cc",
+    "src/trace_processor/containers/nullable_vector_unittest.cc",
     "src/trace_processor/containers/row_map_unittest.cc",
-    "src/trace_processor/containers/sparse_vector_unittest.cc",
     "src/trace_processor/containers/string_pool_unittest.cc",
   ],
 }
diff --git a/BUILD b/BUILD
index 6479dbb..a5ca692 100644
--- a/BUILD
+++ b/BUILD
@@ -692,10 +692,10 @@
         "src/trace_processor/containers/bit_vector_iterators.cc",
         "src/trace_processor/containers/bit_vector_iterators.h",
         "src/trace_processor/containers/null_term_string_view.h",
+        "src/trace_processor/containers/nullable_vector.cc",
+        "src/trace_processor/containers/nullable_vector.h",
         "src/trace_processor/containers/row_map.cc",
         "src/trace_processor/containers/row_map.h",
-        "src/trace_processor/containers/sparse_vector.cc",
-        "src/trace_processor/containers/sparse_vector.h",
         "src/trace_processor/containers/string_pool.cc",
         "src/trace_processor/containers/string_pool.h",
     ],
diff --git a/src/trace_processor/containers/BUILD.gn b/src/trace_processor/containers/BUILD.gn
index f9f1466..836ab22 100644
--- a/src/trace_processor/containers/BUILD.gn
+++ b/src/trace_processor/containers/BUILD.gn
@@ -21,10 +21,10 @@
     "bit_vector_iterators.cc",
     "bit_vector_iterators.h",
     "null_term_string_view.h",
+    "nullable_vector.cc",
+    "nullable_vector.h",
     "row_map.cc",
     "row_map.h",
-    "sparse_vector.cc",
-    "sparse_vector.h",
     "string_pool.cc",
     "string_pool.h",
   ]
@@ -41,8 +41,8 @@
   sources = [
     "bit_vector_unittest.cc",
     "null_term_string_view_unittest.cc",
+    "nullable_vector_unittest.cc",
     "row_map_unittest.cc",
-    "sparse_vector_unittest.cc",
     "string_pool_unittest.cc",
   ]
   deps = [
@@ -62,8 +62,8 @@
     ]
     sources = [
       "bit_vector_benchmark.cc",
+      "nullable_vector_benchmark.cc",
       "row_map_benchmark.cc",
-      "sparse_vector_benchmark.cc",
     ]
   }
 }
diff --git a/src/trace_processor/containers/sparse_vector.cc b/src/trace_processor/containers/nullable_vector.cc
similarity index 86%
rename from src/trace_processor/containers/sparse_vector.cc
rename to src/trace_processor/containers/nullable_vector.cc
index ec78c6b..7c4cd68 100644
--- a/src/trace_processor/containers/sparse_vector.cc
+++ b/src/trace_processor/containers/nullable_vector.cc
@@ -14,12 +14,12 @@
  * limitations under the License.
  */
 
-#include "src/trace_processor/containers/sparse_vector.h"
+#include "src/trace_processor/containers/nullable_vector.h"
 
 namespace perfetto {
 namespace trace_processor {
 
-SparseVectorBase::~SparseVectorBase() = default;
+NullableVectorBase::~NullableVectorBase() = default;
 
 }  // namespace trace_processor
 }  // namespace perfetto
diff --git a/src/trace_processor/containers/sparse_vector.h b/src/trace_processor/containers/nullable_vector.h
similarity index 70%
rename from src/trace_processor/containers/sparse_vector.h
rename to src/trace_processor/containers/nullable_vector.h
index afd7047..b9932d2 100644
--- a/src/trace_processor/containers/sparse_vector.h
+++ b/src/trace_processor/containers/nullable_vector.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef SRC_TRACE_PROCESSOR_CONTAINERS_SPARSE_VECTOR_H_
-#define SRC_TRACE_PROCESSOR_CONTAINERS_SPARSE_VECTOR_H_
+#ifndef SRC_TRACE_PROCESSOR_CONTAINERS_NULLABLE_VECTOR_H_
+#define SRC_TRACE_PROCESSOR_CONTAINERS_NULLABLE_VECTOR_H_
 
 #include <stdint.h>
 
@@ -28,18 +28,18 @@
 namespace perfetto {
 namespace trace_processor {
 
-// Base class for SparseVector which allows type erasure to be implemented (e.g.
-// allows for std::unique_ptr<SparseVectorBase>).
-class SparseVectorBase {
+// Base class for NullableVector which allows type erasure to be implemented
+// (e.g. allows for std::unique_ptr<NullableVectorBase>).
+class NullableVectorBase {
  public:
-  SparseVectorBase() = default;
-  virtual ~SparseVectorBase();
+  NullableVectorBase() = default;
+  virtual ~NullableVectorBase();
 
-  SparseVectorBase(const SparseVectorBase&) = delete;
-  SparseVectorBase& operator=(const SparseVectorBase&) = delete;
+  NullableVectorBase(const NullableVectorBase&) = delete;
+  NullableVectorBase& operator=(const NullableVectorBase&) = delete;
 
-  SparseVectorBase(SparseVectorBase&&) = default;
-  SparseVectorBase& operator=(SparseVectorBase&&) noexcept = default;
+  NullableVectorBase(NullableVectorBase&&) = default;
+  NullableVectorBase& operator=(NullableVectorBase&&) noexcept = default;
 };
 
 // A data structure which compactly stores a list of possibly nullable data.
@@ -49,11 +49,8 @@
 // By default, for each null value, it only uses a single bit inside the
 // BitVector at a slight cost (searching the BitVector to find the index into
 // the std::deque) when looking up the data.
-//
-// TODO(lalitm): rename this class (probably to NullableVector) to better
-// reflect that we can also store null entries densely.
 template <typename T>
-class SparseVector : public SparseVectorBase {
+class NullableVector : public NullableVectorBase {
  private:
   enum class Mode {
     // Sparse mode is the default mode and ensures that nulls are stored using
@@ -69,18 +66,21 @@
   };
 
  public:
-  // Creates an empty SparseVector.
-  SparseVector() : SparseVector<T>(Mode::kSparse) {}
-  ~SparseVector() override = default;
+  // Creates an empty NullableVector.
+  NullableVector() : NullableVector<T>(Mode::kSparse) {}
+  ~NullableVector() override = default;
 
-  explicit SparseVector(const SparseVector&) = delete;
-  SparseVector& operator=(const SparseVector&) = delete;
+  explicit NullableVector(const NullableVector&) = delete;
+  NullableVector& operator=(const NullableVector&) = delete;
 
-  SparseVector(SparseVector&&) = default;
-  SparseVector& operator=(SparseVector&&) noexcept = default;
+  NullableVector(NullableVector&&) = default;
+  NullableVector& operator=(NullableVector&&) noexcept = default;
 
-  // Creates a dense sparse vector
-  static SparseVector<T> Dense() { return SparseVector<T>(Mode::kDense); }
+  // Creates a sparse nullable vector
+  static NullableVector<T> Sparse() { return NullableVector<T>(Mode::kSparse); }
+
+  // Creates a dense nullable vector
+  static NullableVector<T> Dense() { return NullableVector<T>(Mode::kDense); }
 
   // Returns the optional value at |idx| or base::nullopt if the value is null.
   base::Optional<T> Get(uint32_t idx) const {
@@ -111,13 +111,13 @@
     return data_[ordinal];
   }
 
-  // Adds the given value to the SparseVector.
+  // Adds the given value to the NullableVector.
   void Append(T val) {
     data_.emplace_back(val);
     valid_.Insert(size_++);
   }
 
-  // Adds a null value to the SparseVector.
+  // Adds a null value to the NullableVector.
   void AppendNull() {
     if (mode_ == Mode::kDense) {
       data_.emplace_back();
@@ -125,7 +125,7 @@
     size_++;
   }
 
-  // Adds the given optional value to the SparseVector.
+  // Adds the given optional value to the NullableVector.
   void Append(base::Optional<T> val) {
     if (val) {
       Append(*val);
@@ -158,14 +158,14 @@
     }
   }
 
-  // Returns the size of the SparseVector; this includes any null values.
+  // Returns the size of the NullableVector; this includes any null values.
   uint32_t size() const { return size_; }
 
-  // Returns whether data in this SparseVector is stored densely.
+  // Returns whether data in this NullableVector is stored densely.
   bool IsDense() const { return mode_ == Mode::kDense; }
 
  private:
-  SparseVector(Mode mode) : mode_(mode) {}
+  NullableVector(Mode mode) : mode_(mode) {}
 
   Mode mode_ = Mode::kSparse;
 
@@ -177,4 +177,4 @@
 }  // namespace trace_processor
 }  // namespace perfetto
 
-#endif  // SRC_TRACE_PROCESSOR_CONTAINERS_SPARSE_VECTOR_H_
+#endif  // SRC_TRACE_PROCESSOR_CONTAINERS_NULLABLE_VECTOR_H_
diff --git a/src/trace_processor/containers/sparse_vector_benchmark.cc b/src/trace_processor/containers/nullable_vector_benchmark.cc
similarity index 81%
rename from src/trace_processor/containers/sparse_vector_benchmark.cc
rename to src/trace_processor/containers/nullable_vector_benchmark.cc
index 626b738..d5f1a39 100644
--- a/src/trace_processor/containers/sparse_vector_benchmark.cc
+++ b/src/trace_processor/containers/nullable_vector_benchmark.cc
@@ -16,7 +16,7 @@
 
 #include <benchmark/benchmark.h>
 
-#include "src/trace_processor/containers/sparse_vector.h"
+#include "src/trace_processor/containers/nullable_vector.h"
 
 namespace {
 
@@ -25,7 +25,7 @@
 
 }  // namespace
 
-static void BM_SparseVectorAppendNonNull(benchmark::State& state) {
+static void BM_NullableVectorAppendNonNull(benchmark::State& state) {
   std::vector<uint8_t> data_pool(kPoolSize);
 
   static constexpr uint32_t kRandomSeed = 42;
@@ -34,7 +34,7 @@
     data_pool[i] = rnd_engine() % std::numeric_limits<uint8_t>::max();
   }
 
-  perfetto::trace_processor::SparseVector<uint8_t> sv;
+  perfetto::trace_processor::NullableVector<uint8_t> sv;
   uint32_t pool_idx = 0;
   for (auto _ : state) {
     sv.Append(data_pool[pool_idx]);
@@ -42,12 +42,12 @@
     benchmark::ClobberMemory();
   }
 }
-BENCHMARK(BM_SparseVectorAppendNonNull);
+BENCHMARK(BM_NullableVectorAppendNonNull);
 
-static void BM_SparseVectorGetNonNull(benchmark::State& state) {
+static void BM_NullableVectorGetNonNull(benchmark::State& state) {
   std::vector<uint32_t> idx_pool(kPoolSize);
 
-  perfetto::trace_processor::SparseVector<uint8_t> sv;
+  perfetto::trace_processor::NullableVector<uint8_t> sv;
   static constexpr uint32_t kRandomSeed = 42;
   std::minstd_rand0 rnd_engine(kRandomSeed);
   for (uint32_t i = 0; i < kSize; ++i) {
@@ -63,4 +63,4 @@
     pool_idx = (pool_idx + 1) % kPoolSize;
   }
 }
-BENCHMARK(BM_SparseVectorGetNonNull);
+BENCHMARK(BM_NullableVectorGetNonNull);
diff --git a/src/trace_processor/containers/sparse_vector_unittest.cc b/src/trace_processor/containers/nullable_vector_unittest.cc
similarity index 86%
rename from src/trace_processor/containers/sparse_vector_unittest.cc
rename to src/trace_processor/containers/nullable_vector_unittest.cc
index 2f85fbd..e9aabbe 100644
--- a/src/trace_processor/containers/sparse_vector_unittest.cc
+++ b/src/trace_processor/containers/nullable_vector_unittest.cc
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include "src/trace_processor/containers/sparse_vector.h"
+#include "src/trace_processor/containers/nullable_vector.h"
 
 #include "test/gtest_and_gmock.h"
 
@@ -22,8 +22,8 @@
 namespace trace_processor {
 namespace {
 
-TEST(SparseVector, Append) {
-  SparseVector<int64_t> sv;
+TEST(NullableVector, Append) {
+  NullableVector<int64_t> sv;
   sv.Append(10);
   sv.Append(20);
   sv.AppendNull();
@@ -37,8 +37,8 @@
   ASSERT_EQ(sv.Get(3), base::Optional<int64_t>(40));
 }
 
-TEST(SparseVector, Set) {
-  SparseVector<int64_t> sv;
+TEST(NullableVector, Set) {
+  NullableVector<int64_t> sv;
   sv.Append(10);
   sv.Append(20);
   sv.AppendNull();
@@ -55,8 +55,8 @@
   ASSERT_EQ(*sv.Get(4), 40);
 }
 
-TEST(SparseVector, SetNonNull) {
-  SparseVector<int64_t> sv;
+TEST(NullableVector, SetNonNull) {
+  NullableVector<int64_t> sv;
   sv.Append(1);
   sv.Append(2);
   sv.Append(3);
@@ -70,8 +70,8 @@
   ASSERT_EQ(sv.Get(3), base::Optional<int64_t>(4));
 }
 
-TEST(SparseVector, Dense) {
-  auto sv = SparseVector<int64_t>::Dense();
+TEST(NullableVector, Dense) {
+  auto sv = NullableVector<int64_t>::Dense();
 
   sv.Append(0);
   sv.AppendNull();
diff --git a/src/trace_processor/db/column.cc b/src/trace_processor/db/column.cc
index 1c94799..c2452bd 100644
--- a/src/trace_processor/db/column.cc
+++ b/src/trace_processor/db/column.cc
@@ -32,8 +32,8 @@
              table,
              col_idx,
              row_map_idx,
-             column.sparse_vector_,
-             column.owned_sparse_vector_) {}
+             column.nullable_vector_,
+             column.owned_nullable_vector_) {}
 
 Column::Column(const char* name,
                ColumnType type,
@@ -41,11 +41,11 @@
                Table* table,
                uint32_t col_idx_in_table,
                uint32_t row_map_idx,
-               SparseVectorBase* sv,
-               std::shared_ptr<SparseVectorBase> owned_sparse_vector)
-    : owned_sparse_vector_(owned_sparse_vector),
+               NullableVectorBase* nv,
+               std::shared_ptr<NullableVectorBase> owned_nullable_vector)
+    : owned_nullable_vector_(owned_nullable_vector),
       type_(type),
-      sparse_vector_(sv),
+      nullable_vector_(nv),
       name_(name),
       flags_(flags),
       table_(table),
@@ -54,19 +54,19 @@
       string_pool_(table->string_pool_) {
   switch (type_) {
     case ColumnType::kInt32:
-      PERFETTO_CHECK(sparse_vector<int32_t>().IsDense() == IsDense());
+      PERFETTO_CHECK(nullable_vector<int32_t>().IsDense() == IsDense());
       break;
     case ColumnType::kUint32:
-      PERFETTO_CHECK(sparse_vector<uint32_t>().IsDense() == IsDense());
+      PERFETTO_CHECK(nullable_vector<uint32_t>().IsDense() == IsDense());
       break;
     case ColumnType::kInt64:
-      PERFETTO_CHECK(sparse_vector<int64_t>().IsDense() == IsDense());
+      PERFETTO_CHECK(nullable_vector<int64_t>().IsDense() == IsDense());
       break;
     case ColumnType::kDouble:
-      PERFETTO_CHECK(sparse_vector<double>().IsDense() == IsDense());
+      PERFETTO_CHECK(nullable_vector<double>().IsDense() == IsDense());
       break;
     case ColumnType::kString:
-      PERFETTO_CHECK(sparse_vector<StringPool::Id>().IsDense() == IsDense());
+      PERFETTO_CHECK(nullable_vector<StringPool::Id>().IsDense() == IsDense());
       break;
     case ColumnType::kId:
       break;
@@ -143,7 +143,7 @@
     PERFETTO_DCHECK(value.is_null());
     if (is_nullable) {
       row_map().FilterInto(rm, [this](uint32_t row) {
-        return !sparse_vector<T>().Get(row).has_value();
+        return !nullable_vector<T>().Get(row).has_value();
       });
     } else {
       rm->Intersect(RowMap());
@@ -153,7 +153,7 @@
     PERFETTO_DCHECK(value.is_null());
     if (is_nullable) {
       row_map().FilterInto(rm, [this](uint32_t row) {
-        return sparse_vector<T>().Get(row).has_value();
+        return nullable_vector<T>().Get(row).has_value();
       });
     }
     return;
@@ -211,55 +211,55 @@
     case FilterOp::kLt:
       row_map().FilterInto(rm, [this, &cmp](uint32_t idx) {
         if (is_nullable) {
-          auto opt_value = sparse_vector<T>().Get(idx);
+          auto opt_value = nullable_vector<T>().Get(idx);
           return opt_value && cmp(*opt_value) < 0;
         }
-        return cmp(sparse_vector<T>().GetNonNull(idx)) < 0;
+        return cmp(nullable_vector<T>().GetNonNull(idx)) < 0;
       });
       break;
     case FilterOp::kEq:
       row_map().FilterInto(rm, [this, &cmp](uint32_t idx) {
         if (is_nullable) {
-          auto opt_value = sparse_vector<T>().Get(idx);
+          auto opt_value = nullable_vector<T>().Get(idx);
           return opt_value && cmp(*opt_value) == 0;
         }
-        return cmp(sparse_vector<T>().GetNonNull(idx)) == 0;
+        return cmp(nullable_vector<T>().GetNonNull(idx)) == 0;
       });
       break;
     case FilterOp::kGt:
       row_map().FilterInto(rm, [this, &cmp](uint32_t idx) {
         if (is_nullable) {
-          auto opt_value = sparse_vector<T>().Get(idx);
+          auto opt_value = nullable_vector<T>().Get(idx);
           return opt_value && cmp(*opt_value) > 0;
         }
-        return cmp(sparse_vector<T>().GetNonNull(idx)) > 0;
+        return cmp(nullable_vector<T>().GetNonNull(idx)) > 0;
       });
       break;
     case FilterOp::kNe:
       row_map().FilterInto(rm, [this, &cmp](uint32_t idx) {
         if (is_nullable) {
-          auto opt_value = sparse_vector<T>().Get(idx);
+          auto opt_value = nullable_vector<T>().Get(idx);
           return opt_value && cmp(*opt_value) != 0;
         }
-        return cmp(sparse_vector<T>().GetNonNull(idx)) != 0;
+        return cmp(nullable_vector<T>().GetNonNull(idx)) != 0;
       });
       break;
     case FilterOp::kLe:
       row_map().FilterInto(rm, [this, &cmp](uint32_t idx) {
         if (is_nullable) {
-          auto opt_value = sparse_vector<T>().Get(idx);
+          auto opt_value = nullable_vector<T>().Get(idx);
           return opt_value && cmp(*opt_value) <= 0;
         }
-        return cmp(sparse_vector<T>().GetNonNull(idx)) <= 0;
+        return cmp(nullable_vector<T>().GetNonNull(idx)) <= 0;
       });
       break;
     case FilterOp::kGe:
       row_map().FilterInto(rm, [this, &cmp](uint32_t idx) {
         if (is_nullable) {
-          auto opt_value = sparse_vector<T>().Get(idx);
+          auto opt_value = nullable_vector<T>().Get(idx);
           return opt_value && cmp(*opt_value) >= 0;
         }
-        return cmp(sparse_vector<T>().GetNonNull(idx)) >= 0;
+        return cmp(nullable_vector<T>().GetNonNull(idx)) >= 0;
       });
       break;
     case FilterOp::kIsNull:
@@ -451,17 +451,17 @@
   PERFETTO_DCHECK(IsNullable() == is_nullable);
   PERFETTO_DCHECK(ToColumnType<T>() == type_);
 
-  const auto& sv = sparse_vector<T>();
-  row_map().StableSort(out, [&sv](uint32_t a_idx, uint32_t b_idx) {
+  const auto& nv = nullable_vector<T>();
+  row_map().StableSort(out, [&nv](uint32_t a_idx, uint32_t b_idx) {
     if (is_nullable) {
-      auto a_val = sv.Get(a_idx);
-      auto b_val = sv.Get(b_idx);
+      auto a_val = nv.Get(a_idx);
+      auto b_val = nv.Get(b_idx);
 
       int res = compare::NullableNumeric(a_val, b_val);
       return desc ? res > 0 : res < 0;
     }
-    auto a_val = sv.GetNonNull(a_idx);
-    auto b_val = sv.GetNonNull(b_idx);
+    auto a_val = nv.GetNonNull(a_idx);
+    auto b_val = nv.GetNonNull(b_idx);
 
     return desc ? compare::Numeric(a_val, b_val) > 0
                 : compare::Numeric(a_val, b_val) < 0;
diff --git a/src/trace_processor/db/column.h b/src/trace_processor/db/column.h
index c16d28c..a256cc1 100644
--- a/src/trace_processor/db/column.h
+++ b/src/trace_processor/db/column.h
@@ -22,8 +22,8 @@
 #include "perfetto/base/logging.h"
 #include "perfetto/ext/base/optional.h"
 #include "perfetto/trace_processor/basic_types.h"
+#include "src/trace_processor/containers/nullable_vector.h"
 #include "src/trace_processor/containers/row_map.h"
-#include "src/trace_processor/containers/sparse_vector.h"
 #include "src/trace_processor/containers/string_pool.h"
 #include "src/trace_processor/db/compare.h"
 
@@ -88,12 +88,12 @@
     // up filtering and skip sorting.
     kSorted = 1 << 0,
 
-    // Indicates the data in the column is non-null. That is, the SparseVector
+    // Indicates the data in the column is non-null. That is, the NullableVector
     // passed in will never have any null entries. This is only used for
     // numeric columns (string columns and id columns both have special
     // handling which ignores this flag).
     //
-    // This is used to speed up filters as we can safely index SparseVector
+    // This is used to speed up filters as we can safely index NullableVector
     // directly if this flag is set.
     kNonNull = 1 << 1,
 
@@ -116,7 +116,7 @@
 
   template <typename T>
   Column(const char* name,
-         SparseVector<T>* storage,
+         NullableVector<T>* storage,
          /* Flag */ uint32_t flags,
          Table* table,
          uint32_t col_idx_in_table,
@@ -143,12 +143,12 @@
 
   template <typename T>
   static Column WithOwnedStorage(const char* name,
-                                 std::unique_ptr<SparseVector<T>> storage,
+                                 std::unique_ptr<NullableVector<T>> storage,
                                  /* Flag */ uint32_t flags,
                                  Table* table,
                                  uint32_t col_idx_in_table,
                                  uint32_t row_map_idx) {
-    SparseVector<T>* ptr = storage.get();
+    NullableVector<T>* ptr = storage.get();
     return Column(name, ToColumnType<T>(), flags, table, col_idx_in_table,
                   row_map_idx, ptr, std::move(storage));
   }
@@ -192,22 +192,22 @@
     PERFETTO_CHECK(value.type == type());
     switch (type_) {
       case ColumnType::kInt32: {
-        mutable_sparse_vector<int32_t>()->Set(
+        mutable_nullable_vector<int32_t>()->Set(
             row, static_cast<int32_t>(value.long_value));
         break;
       }
       case ColumnType::kUint32: {
-        mutable_sparse_vector<uint32_t>()->Set(
+        mutable_nullable_vector<uint32_t>()->Set(
             row, static_cast<uint32_t>(value.long_value));
         break;
       }
       case ColumnType::kInt64: {
-        mutable_sparse_vector<int64_t>()->Set(
+        mutable_nullable_vector<int64_t>()->Set(
             row, static_cast<int64_t>(value.long_value));
         break;
       }
       case ColumnType::kDouble: {
-        mutable_sparse_vector<double>()->Set(row, value.double_value);
+        mutable_nullable_vector<double>()->Set(row, value.double_value);
         break;
       }
       case ColumnType::kString: {
@@ -348,17 +348,17 @@
   // Returns the backing sparse vector cast to contain data of type T.
   // Should only be called when |type_| == ToColumnType<T>().
   template <typename T>
-  SparseVector<T>* mutable_sparse_vector() {
+  NullableVector<T>* mutable_nullable_vector() {
     PERFETTO_DCHECK(ToColumnType<T>() == type_);
-    return static_cast<SparseVector<T>*>(sparse_vector_);
+    return static_cast<NullableVector<T>*>(nullable_vector_);
   }
 
   // Returns the backing sparse vector cast to contain data of type T.
   // Should only be called when |type_| == ToColumnType<T>().
   template <typename T>
-  const SparseVector<T>& sparse_vector() const {
+  const NullableVector<T>& nullable_vector() const {
     PERFETTO_DCHECK(ToColumnType<T>() == type_);
-    return *static_cast<const SparseVector<T>*>(sparse_vector_);
+    return *static_cast<const NullableVector<T>*>(nullable_vector_);
   }
 
   // Returns the type of this Column in terms of SqlValue::Type.
@@ -434,8 +434,8 @@
          Table* table,
          uint32_t col_idx_in_table,
          uint32_t row_map_idx,
-         SparseVectorBase* sparse_vector,
-         std::shared_ptr<SparseVectorBase> owned_sparse_vector);
+         NullableVectorBase* nullable_vector,
+         std::shared_ptr<NullableVectorBase> owned_nullable_vector);
 
   Column(const Column&) = delete;
   Column& operator=(const Column&) = delete;
@@ -444,19 +444,19 @@
   SqlValue GetAtIdx(uint32_t idx) const {
     switch (type_) {
       case ColumnType::kInt32: {
-        auto opt_value = sparse_vector<int32_t>().Get(idx);
+        auto opt_value = nullable_vector<int32_t>().Get(idx);
         return opt_value ? SqlValue::Long(*opt_value) : SqlValue();
       }
       case ColumnType::kUint32: {
-        auto opt_value = sparse_vector<uint32_t>().Get(idx);
+        auto opt_value = nullable_vector<uint32_t>().Get(idx);
         return opt_value ? SqlValue::Long(*opt_value) : SqlValue();
       }
       case ColumnType::kInt64: {
-        auto opt_value = sparse_vector<int64_t>().Get(idx);
+        auto opt_value = nullable_vector<int64_t>().Get(idx);
         return opt_value ? SqlValue::Long(*opt_value) : SqlValue();
       }
       case ColumnType::kDouble: {
-        auto opt_value = sparse_vector<double>().Get(idx);
+        auto opt_value = nullable_vector<double>().Get(idx);
         return opt_value ? SqlValue::Double(*opt_value) : SqlValue();
       }
       case ColumnType::kString: {
@@ -583,17 +583,17 @@
   // Should only be called when |type_| == ColumnType::kString.
   NullTermStringView GetStringPoolStringAtIdx(uint32_t idx) const {
     PERFETTO_DCHECK(type_ == ColumnType::kString);
-    return string_pool_->Get(sparse_vector<StringPool::Id>().GetNonNull(idx));
+    return string_pool_->Get(nullable_vector<StringPool::Id>().GetNonNull(idx));
   }
 
   // Only filled for columns which own the data inside them. Generally this is
   // only true for columns which are dynamically generated at runtime.
-  // Keep this before |sparse_vector_|.
-  std::shared_ptr<SparseVectorBase> owned_sparse_vector_;
+  // Keep this before |nullable_vector_|.
+  std::shared_ptr<NullableVectorBase> owned_nullable_vector_;
 
-  // type_ is used to cast sparse_vector_ to the correct type.
+  // type_ is used to cast nullable_vector_ to the correct type.
   ColumnType type_ = ColumnType::kInt64;
-  SparseVectorBase* sparse_vector_ = nullptr;
+  NullableVectorBase* nullable_vector_ = nullptr;
 
   const char* name_ = nullptr;
   uint32_t flags_ = Flag::kNoFlag;
diff --git a/src/trace_processor/db/table.h b/src/trace_processor/db/table.h
index 771770d..bc515cd 100644
--- a/src/trace_processor/db/table.h
+++ b/src/trace_processor/db/table.h
@@ -152,7 +152,7 @@
 
   template <typename T>
   Table ExtendWithColumn(const char* name,
-                         std::unique_ptr<SparseVector<T>> sv,
+                         std::unique_ptr<NullableVector<T>> sv,
                          uint32_t flags) const {
     PERFETTO_DCHECK(sv->size() == row_count_);
     uint32_t size = sv->size();
diff --git a/src/trace_processor/db/table_unittest.cc b/src/trace_processor/db/table_unittest.cc
index 21e0c80..bc2ca8f 100644
--- a/src/trace_processor/db/table_unittest.cc
+++ b/src/trace_processor/db/table_unittest.cc
@@ -27,8 +27,9 @@
 
 constexpr uint32_t kColumnCount = 1024;
 
-std::unique_ptr<SparseVector<int64_t>> Column() {
-  auto c = std::unique_ptr<SparseVector<int64_t>>(new SparseVector<int64_t>());
+std::unique_ptr<NullableVector<int64_t>> Column() {
+  auto c =
+      std::unique_ptr<NullableVector<int64_t>>(new NullableVector<int64_t>());
   for (int64_t i = 0; i < kColumnCount; ++i)
     c->Append(i);
   return c;
diff --git a/src/trace_processor/db/typed_column.h b/src/trace_processor/db/typed_column.h
index d445029..2bef075 100644
--- a/src/trace_processor/db/typed_column.h
+++ b/src/trace_processor/db/typed_column.h
@@ -66,13 +66,13 @@
   using Serializer = tc_internal::Serializer<non_optional_type>;
 
  public:
-  // The type which should be stored in the SparseVector.
-  // Used by the macro code when actually constructing the SparseVectors.
+  // The type which should be stored in the NullableVector.
+  // Used by the macro code when actually constructing the NullableVectors.
   using serialized_type = typename Serializer::serialized_type;
 
   get_type operator[](uint32_t row) const {
     return Serializer::Deserialize(
-        TH::Get(sparse_vector(), row_map().Get(row)));
+        TH::Get(nullable_vector(), row_map().Get(row)));
   }
 
   // Special function only for string types to allow retrieving the string
@@ -80,18 +80,18 @@
   template <bool is_string = TH::is_string>
   typename std::enable_if<is_string, NullTermStringView>::type GetString(
       uint32_t row) const {
-    return string_pool().Get(sparse_vector().GetNonNull(row_map().Get(row)));
+    return string_pool().Get(nullable_vector().GetNonNull(row_map().Get(row)));
   }
 
   // Sets the data in the column at index |row|.
   void Set(uint32_t row, non_optional_type v) {
     auto serialized = Serializer::Serialize(v);
-    mutable_sparse_vector()->Set(row_map().Get(row), serialized);
+    mutable_nullable_vector()->Set(row_map().Get(row), serialized);
   }
 
   // Inserts the value at the end of the column.
   void Append(T v) {
-    mutable_sparse_vector()->Append(Serializer::Serialize(v));
+    mutable_nullable_vector()->Append(Serializer::Serialize(v));
   }
 
   // Returns the row containing the given value in the Column.
@@ -147,11 +147,11 @@
     return SqlValue::String(value.c_str());
   }
 
-  const SparseVector<serialized_type>& sparse_vector() const {
-    return Column::sparse_vector<serialized_type>();
+  const NullableVector<serialized_type>& nullable_vector() const {
+    return Column::nullable_vector<serialized_type>();
   }
-  SparseVector<serialized_type>* mutable_sparse_vector() {
-    return Column::mutable_sparse_vector<serialized_type>();
+  NullableVector<serialized_type>* mutable_nullable_vector() {
+    return Column::mutable_nullable_vector<serialized_type>();
   }
 };
 
diff --git a/src/trace_processor/db/typed_column_internal.h b/src/trace_processor/db/typed_column_internal.h
index 07c8e8a..128dd80 100644
--- a/src/trace_processor/db/typed_column_internal.h
+++ b/src/trace_processor/db/typed_column_internal.h
@@ -24,7 +24,7 @@
 namespace tc_internal {
 
 // Serializer converts between the "public" type used by the rest of trace
-// processor and the type we store in the SparseVector.
+// processor and the type we store in the NullableVector.
 template <typename T, typename Enabled = void>
 struct Serializer {
   using serialized_type = T;
@@ -70,7 +70,7 @@
   static serialized_type Serialize(base::Optional<StringPool::Id> value) {
     // Since StringPool::Id == 0 is always treated as null, rewrite
     // base::nullopt -> 0 to remove an extra check at filter time for
-    // base::nullopt. Instead, that code can assume that the SparseVector
+    // base::nullopt. Instead, that code can assume that the NullableVector
     // layer always returns a valid id and can handle the nullability at the
     // stringpool level.
     // TODO(lalitm): remove this special casing if we migrate all tables over
@@ -97,9 +97,9 @@
   static constexpr bool is_string = false;
 
   template <typename SerializedType>
-  static SerializedType Get(const SparseVector<SerializedType>& sv,
+  static SerializedType Get(const NullableVector<SerializedType>& nv,
                             uint32_t idx) {
-    return sv.GetNonNull(idx);
+    return nv.GetNonNull(idx);
   }
 
   static bool Equals(T a, T b) {
@@ -122,9 +122,9 @@
 
   template <typename SerializedType>
   static base::Optional<SerializedType> Get(
-      const SparseVector<SerializedType>& sv,
+      const NullableVector<SerializedType>& nv,
       uint32_t idx) {
-    return sv.Get(idx);
+    return nv.Get(idx);
   }
 
   static bool Equals(base::Optional<T> a, base::Optional<T> b) {
@@ -150,9 +150,9 @@
   static constexpr bool is_optional = false;
   static constexpr bool is_string = true;
 
-  static StringPool::Id Get(const SparseVector<StringPool::Id>& sv,
+  static StringPool::Id Get(const NullableVector<StringPool::Id>& nv,
                             uint32_t idx) {
-    return sv.GetNonNull(idx);
+    return nv.GetNonNull(idx);
   }
 
   static bool Equals(StringPool::Id a, StringPool::Id b) { return a == b; }
@@ -173,9 +173,9 @@
   static constexpr bool is_string = true;
 
   static base::Optional<StringPool::Id> Get(
-      const SparseVector<StringPool::Id>& sv,
+      const NullableVector<StringPool::Id>& nv,
       uint32_t idx) {
-    StringPool::Id id = sv.GetNonNull(idx);
+    StringPool::Id id = nv.GetNonNull(idx);
     return id.is_null() ? base::nullopt : base::make_optional(id);
   }
 
diff --git a/src/trace_processor/dynamic/experimental_counter_dur_generator.cc b/src/trace_processor/dynamic/experimental_counter_dur_generator.cc
index b5db405..5f1e47c 100644
--- a/src/trace_processor/dynamic/experimental_counter_dur_generator.cc
+++ b/src/trace_processor/dynamic/experimental_counter_dur_generator.cc
@@ -57,18 +57,18 @@
   }
   Table table = counter_table_->Filter(constraints);
 
-  std::unique_ptr<SparseVector<int64_t>> dur_column(
-      new SparseVector<int64_t>(ComputeDurColumn(table)));
+  std::unique_ptr<NullableVector<int64_t>> dur_column(
+      new NullableVector<int64_t>(ComputeDurColumn(table)));
   return std::unique_ptr<Table>(new Table(table.ExtendWithColumn(
       "dur", std::move(dur_column), TypedColumn<int64_t>::default_flags())));
 }
 
 // static
-SparseVector<int64_t> ExperimentalCounterDurGenerator::ComputeDurColumn(
+NullableVector<int64_t> ExperimentalCounterDurGenerator::ComputeDurColumn(
     const Table& table) {
   // Keep track of the last seen row for each track id.
   std::unordered_map<TrackId, uint32_t> last_row_for_track_id;
-  SparseVector<int64_t> dur;
+  NullableVector<int64_t> dur;
 
   const auto* ts_col =
       TypedColumn<int64_t>::FromColumn(table.GetColumnByName("ts"));
diff --git a/src/trace_processor/dynamic/experimental_counter_dur_generator.h b/src/trace_processor/dynamic/experimental_counter_dur_generator.h
index 6e88762..b20ca22 100644
--- a/src/trace_processor/dynamic/experimental_counter_dur_generator.h
+++ b/src/trace_processor/dynamic/experimental_counter_dur_generator.h
@@ -38,7 +38,7 @@
                                       const std::vector<Order>&) override;
 
   // public + static for testing
-  static SparseVector<int64_t> ComputeDurColumn(const Table& table);
+  static NullableVector<int64_t> ComputeDurColumn(const Table& table);
 
  private:
   const tables::CounterTable* counter_table_ = nullptr;
diff --git a/src/trace_processor/dynamic/experimental_slice_layout_generator.cc b/src/trace_processor/dynamic/experimental_slice_layout_generator.cc
index 3ba16b5..132d7dc 100644
--- a/src/trace_processor/dynamic/experimental_slice_layout_generator.cc
+++ b/src/trace_processor/dynamic/experimental_slice_layout_generator.cc
@@ -253,10 +253,10 @@
   }
 
   // Step 3: Add the two new columns layout_depth and filter_track_ids:
-  std::unique_ptr<SparseVector<int64_t>> layout_depth_column(
-      new SparseVector<int64_t>());
-  std::unique_ptr<SparseVector<StringPool::Id>> filter_column(
-      new SparseVector<StringPool::Id>());
+  std::unique_ptr<NullableVector<int64_t>> layout_depth_column(
+      new NullableVector<int64_t>());
+  std::unique_ptr<NullableVector<StringPool::Id>> filter_column(
+      new NullableVector<StringPool::Id>());
 
   for (uint32_t i = 0; i < table.row_count(); ++i) {
     TrackId track_id = track_id_col[i];
diff --git a/src/trace_processor/tables/macros_internal.h b/src/trace_processor/tables/macros_internal.h
index 42f02d0..de468af 100644
--- a/src/trace_processor/tables/macros_internal.h
+++ b/src/trace_processor/tables/macros_internal.h
@@ -122,7 +122,7 @@
   //
   // Only relevant for parentless tables. Will be empty and unreferenced by
   // tables with parents.
-  SparseVector<StringPool::Id> type_;
+  NullableVector<StringPool::Id> type_;
 
  private:
   const char* name_ = nullptr;
@@ -203,7 +203,7 @@
 
 // Defines the member variable in the Table.
 #define PERFETTO_TP_TABLE_MEMBER(type, name, ...) \
-  SparseVector<TypedColumn<type>::serialized_type> name##_;
+  NullableVector<TypedColumn<type>::serialized_type> name##_;
 
 #define PERFETTO_TP_COLUMN_FLAG_HAS_FLAG_COL(type, name, flags) \
   case ColumnIndex::name:                                       \
@@ -222,10 +222,11 @@
   (__VA_ARGS__)
 
 // Creates the sparse vector with the given flags.
-#define PERFETTO_TP_TABLE_CONSTRUCTOR_SV(type, name, ...)                   \
-  name##_ = (FlagsForColumn(ColumnIndex::name) & Column::Flag::kDense)      \
-                ? SparseVector<TypedColumn<type>::serialized_type>::Dense() \
-                : SparseVector<TypedColumn<type>::serialized_type>();
+#define PERFETTO_TP_TABLE_CONSTRUCTOR_SV(type, name, ...)               \
+  name##_ =                                                             \
+      (FlagsForColumn(ColumnIndex::name) & Column::Flag::kDense)        \
+          ? NullableVector<TypedColumn<type>::serialized_type>::Dense() \
+          : NullableVector<TypedColumn<type>::serialized_type>::Sparse();
 
 // Invokes the chosen column constructor by passing the given args.
 #define PERFETTO_TP_TABLE_CONSTRUCTOR_COLUMN(type, name, ...)               \
@@ -341,7 +342,7 @@
           parent_(parent) {                                                   \
       /*                                                                      \
        * Expands to                                                           \
-       * col1_ = SparseVector<col1_type>(mode)                                \
+       * col1_ = NullableVector<col1_type>(mode)                              \
        * ...                                                                  \
        */                                                                     \
       PERFETTO_TP_TABLE_COLUMNS(DEF, PERFETTO_TP_TABLE_CONSTRUCTOR_SV);       \
@@ -432,8 +433,8 @@
                                                                               \
     /*                                                                        \
      * Expands to                                                             \
-     * SparseVector<col1_type> col1_;                                         \
-     * SparseVector<col2_type> col2_;                                         \
+     * NullableVector<col1_type> col1_;                                       \
+     * NullableVector<col2_type> col2_;                                       \
      * ...                                                                    \
      */                                                                       \
     PERFETTO_TP_TABLE_COLUMNS(DEF, PERFETTO_TP_TABLE_MEMBER)                  \