File indexing completed on 2024-12-17 02:43:53
0001 #ifndef PerfTools_AllocMonitor_mea_AllocMap_h
0002 #define PerfTools_AllocMonitor_mea_AllocMap_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022 #include <vector>
0023 #include <cassert>
0024
0025
0026
0027
0028
0029 namespace edm::service::moduleEventAlloc {
0030 class AllocMap {
0031 public:
0032 AllocMap() = default;
0033 AllocMap(AllocMap const&) = default;
0034 AllocMap& operator=(AllocMap const&) = default;
0035 AllocMap(AllocMap&&) = default;
0036 AllocMap& operator=(AllocMap&&) = default;
0037
0038
0039 std::size_t size() const { return keys_.size(); }
0040
0041
0042 std::size_t findOffset(void const* iKey) const {
0043 auto bound = std::lower_bound(keys_.begin(), keys_.end(), iKey);
0044 if (bound == keys_.end() or *bound != iKey) {
0045 return size();
0046 }
0047 return bound - keys_.begin();
0048 }
0049
0050 std::vector<std::size_t> const& allocationSizes() const { return values_; }
0051
0052
0053
0054 void insert(void const* iKey, std::size_t iValue) {
0055 auto offset = insertOffset(iKey);
0056 if (offset != size() and keys_[offset] == iKey) {
0057 values_[offset] = iValue;
0058 return;
0059 }
0060 keys_.insert(keys_.begin() + offset, iKey);
0061 values_.insert(values_.begin() + offset, iValue);
0062 }
0063
0064 std::size_t erase(void const* iKey) {
0065 assert(keys_.size() == values_.size());
0066 auto offset = findOffset(iKey);
0067 if (offset == size()) {
0068 return 0;
0069 }
0070 auto v = values_[offset];
0071 values_.erase(values_.begin() + offset);
0072 keys_.erase(keys_.begin() + offset);
0073
0074 return v;
0075 }
0076 void clearSizes() {
0077 values_.clear();
0078 values_.shrink_to_fit();
0079 }
0080
0081 void clear() {
0082 clearSizes();
0083 keys_.clear();
0084 keys_.shrink_to_fit();
0085 }
0086
0087 private:
0088
0089 std::size_t insertOffset(void const* key) const {
0090 auto bound = std::lower_bound(keys_.begin(), keys_.end(), key);
0091 return bound - keys_.begin();
0092 }
0093
0094 std::vector<void const*> keys_;
0095 std::vector<std::size_t> values_;
0096 };
0097 }
0098 #endif