/* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef SRC_TRACE_PROCESSOR_CONTAINERS_ROW_MAP_H_ #define SRC_TRACE_PROCESSOR_CONTAINERS_ROW_MAP_H_ #include <algorithm> #include <cstdint> #include <iterator> #include <numeric> #include <optional> #include <utility> #include <variant> #include <vector> #include "perfetto/base/compiler.h" #include "perfetto/base/logging.h" #include "src/trace_processor/containers/bit_vector.h" namespace perfetto { namespace trace_processor { // Stores a list of row indicies in a space efficient manner. One or more // columns can refer to the same RowMap. The RowMap defines the access pattern // to iterate on rows. // // Naming convention: // // As both the input and output of RowMap is a uint32_t, it can be quite // confusing to reason about what parameters/return values of the functions // of RowMap actually means. To help with this, we define a strict convention // of naming. // // row: input - that is, rows are what are passed into operator[]; named as // such because a "row" number in a table is converted to an index to // lookup in the backing vectors. // index: output - that is, indices are what are returned from operator[]; // named as such because an "index" is what's used to lookup data // from the backing vectors. // // Implementation details: // // Behind the scenes, this class is impelemented using one of three backing // data-structures: // 1. A start and end index (internally named 'range') // 1. BitVector // 2. std::vector<uint32_t> (internally named IndexVector). // // Generally the preference for data structures is range > BitVector > // std::vector<uint32>; this ordering is based mainly on memory efficiency as we // expect RowMaps to be large. // // However, BitVector and std::vector<uint32_t> allow things which are not // possible with the data-structures preferred to them: // * a range (as the name suggests) can only store a compact set of indices // with no holes. A BitVector works around this limitation by storing a 1 at an // index where that row is part of the RowMap and 0 otherwise. // * as soon as ordering or duplicate rows come into play, we cannot use a // BitVector anymore as ordering/duplicate row information cannot be captured // by a BitVector. // // For small, sparse RowMaps, it is possible that a std::vector<uint32_t> is // more efficient than a BitVector; in this case, we will make a best effort // switch to it but the cases where this happens is not precisely defined. class RowMap { … }; } // namespace trace_processor } // namespace perfetto #endif // SRC_TRACE_PROCESSOR_CONTAINERS_ROW_MAP_H_