trace_processor: move all containers to new subfolder Moving them to their own folder makes more sense as there is a clear grouping to them which does not necessarily have to involve db code. Context: go/perfetto-tp-refactor Bug: 135177627 Change-Id: Id71adb66a3ae1c4268aa9d9a2d9ba408b9bd6844
diff --git a/src/trace_processor/containers/bit_vector.cc b/src/trace_processor/containers/bit_vector.cc new file mode 100644 index 0000000..0ec5bcc --- /dev/null +++ b/src/trace_processor/containers/bit_vector.cc
@@ -0,0 +1,73 @@ +/* + * 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. + */ + +#include "src/trace_processor/containers/bit_vector.h" + +#include "src/trace_processor/containers/bit_vector_iterators.h" + +namespace perfetto { +namespace trace_processor { + +BitVector::BitVector() = default; + +BitVector::BitVector(std::initializer_list<bool> init) { + for (bool x : init) { + if (x) { + AppendTrue(); + } else { + AppendFalse(); + } + } +} + +BitVector::BitVector(uint32_t count, bool value) { + Resize(count, value); +} + +BitVector::BitVector(std::vector<Block> blocks, + std::vector<uint32_t> counts, + uint32_t size) + : size_(size), counts_(std::move(counts)), blocks_(std::move(blocks)) {} + +BitVector BitVector::Copy() const { + return BitVector(blocks_, counts_, size_); +} + +BitVector::AllBitsIterator BitVector::IterateAllBits() const { + return AllBitsIterator(this); +} + +BitVector::SetBitsIterator BitVector::IterateSetBits() const { + return SetBitsIterator(this); +} + +void BitVector::UpdateSetBits(const BitVector& other) { + PERFETTO_DCHECK(other.size() == GetNumBitsSet()); + + // For each set bit in this bitvector, we lookup whether |other| has the + // bit set. If not, we clear the bit. + for (auto it = IterateSetBits(); it; it.Next()) { + if (!other.IsSet(it.ordinal())) + it.Clear(); + } + + // After the loop, we should have precisely the same number of bits + // set as |other|. + PERFETTO_DCHECK(GetNumBitsSet() == other.GetNumBitsSet()); +} + +} // namespace trace_processor +} // namespace perfetto