Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: src/processor/range_map.h

Issue 2029953003: Adding support for overlapping ranges to RangeMap. (Closed) Base URL: https://chromium.googlesource.com/breakpad/breakpad.git@master
Patch Set: Addressing code review comments Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2006, Google Inc. 1 // Copyright (c) 2006, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 45
46 46
47 namespace google_breakpad { 47 namespace google_breakpad {
48 48
49 // Forward declarations (for later friend declarations of specialized template). 49 // Forward declarations (for later friend declarations of specialized template).
50 template<class, class> class RangeMapSerializer; 50 template<class, class> class RangeMapSerializer;
51 51
52 template<typename AddressType, typename EntryType> 52 template<typename AddressType, typename EntryType>
53 class RangeMap { 53 class RangeMap {
54 public: 54 public:
55 RangeMap() : map_() {} 55 RangeMap() : enable_shrink_down_(false), map_() {}
56
57 // |enable_shrink_down| tells whether overlapping ranges can be shrunk down.
58 // If true, then adding a new range that overlaps with an existing one can
59 // be a successful operation. The range which ends at the higher address
60 // will be shrunk down by moving its start position to a higher address so
61 // that it does not overlap anymore.
62 void SetEnableShrinkDown(bool enable_shrink_down);
56 63
57 // Inserts a range into the map. Returns false for a parameter error, 64 // Inserts a range into the map. Returns false for a parameter error,
58 // or if the location of the range would conflict with a range already 65 // or if the location of the range would conflict with a range already
59 // stored in the map. 66 // stored in the map. If enable_shrink_down is true and there is an overlap
60 bool StoreRange(const AddressType &base, 67 // between the current range and some other range (already in the map),
61 const AddressType &size, 68 // shrink down the range which ends at a hugher address.
mmandlis 2016/06/02 23:50:59 typo - higher
ivanpe 2016/06/03 03:56:56 Done.
69 bool StoreRange(const AddressType &base, const AddressType &size,
62 const EntryType &entry); 70 const EntryType &entry);
63 71
64 // Locates the range encompassing the supplied address. If there is 72 // Locates the range encompassing the supplied address. If there is no such
65 // no such range, returns false. entry_base and entry_size, if non-NULL, 73 // range, returns false. entry_base, entry_delta, and entry_size, if
66 // are set to the base and size of the entry's range. 74 // non-NULL, are set to the base, delta, and size of the entry's range.
mmandlis 2016/06/02 23:50:59 could you, please, add comment on what entry_delta
ivanpe 2016/06/03 03:56:55 Done.
67 bool RetrieveRange(const AddressType &address, EntryType *entry, 75 bool RetrieveRange(const AddressType &address, EntryType *entry,
68 AddressType *entry_base, AddressType *entry_size) const; 76 AddressType *entry_base, AddressType *entry_delta,
77 AddressType *entry_size) const;
69 78
70 // Locates the range encompassing the supplied address, if one exists. 79 // Locates the range encompassing the supplied address, if one exists.
71 // If no range encompasses the supplied address, locates the nearest range 80 // If no range encompasses the supplied address, locates the nearest range
72 // to the supplied address that is lower than the address. Returns false 81 // to the supplied address that is lower than the address. Returns false
73 // if no range meets these criteria. entry_base and entry_size, if 82 // if no range meets these criteria. entry_base, entry_delta, and entry_size,
74 // non-NULL, are set to the base and size of the entry's range. 83 // if non-NULL, are set to the base, delta, and size of the entry's range.
75 bool RetrieveNearestRange(const AddressType &address, EntryType *entry, 84 bool RetrieveNearestRange(const AddressType &address, EntryType *entry,
76 AddressType *entry_base, AddressType *entry_size) 85 AddressType *entry_base, AddressType *entry_delta,
77 const; 86 AddressType *entry_size) const;
78 87
79 // Treating all ranges as a list ordered by the address spaces that they 88 // Treating all ranges as a list ordered by the address spaces that they
80 // occupy, locates the range at the index specified by index. Returns 89 // occupy, locates the range at the index specified by index. Returns
81 // false if index is larger than the number of ranges stored. entry_base 90 // false if index is larger than the number of ranges stored. entry_base,
82 // and entry_size, if non-NULL, are set to the base and size of the entry's 91 // entry_delta, and entry_size, if non-NULL, are set to the base, delta, and
83 // range. 92 // size of the entry's range.
84 // 93 //
85 // RetrieveRangeAtIndex is not optimized for speedy operation. 94 // RetrieveRangeAtIndex is not optimized for speedy operation.
86 bool RetrieveRangeAtIndex(int index, EntryType *entry, 95 bool RetrieveRangeAtIndex(int index, EntryType *entry,
87 AddressType *entry_base, AddressType *entry_size) 96 AddressType *entry_base, AddressType *entry_delta,
88 const; 97 AddressType *entry_size) const;
mmandlis 2016/06/02 23:50:59 optional - probably not worth doing, but just smth
ivanpe 2016/06/03 03:56:55 Acknowledged.
89 98
90 // Returns the number of ranges stored in the RangeMap. 99 // Returns the number of ranges stored in the RangeMap.
91 int GetCount() const; 100 int GetCount() const;
92 101
93 // Empties the range map, restoring it to the state it was when it was 102 // Empties the range map, restoring it to the state it was when it was
94 // initially created. 103 // initially created.
95 void Clear(); 104 void Clear();
96 105
97 private: 106 private:
98 // Friend declarations. 107 // Friend declarations.
99 friend class ModuleComparer; 108 friend class ModuleComparer;
100 friend class RangeMapSerializer<AddressType, EntryType>; 109 friend class RangeMapSerializer<AddressType, EntryType>;
101 110
111 // Same a StoreRange() with the only exception that the |delta| can be
112 // passed in.
113 bool StoreRangeInternal(const AddressType &base, const AddressType &delta,
114 const AddressType &size, const EntryType &entry);
115
102 class Range { 116 class Range {
103 public: 117 public:
104 Range(const AddressType &base, const EntryType &entry) 118 Range(const AddressType &base, const AddressType &delta,
105 : base_(base), entry_(entry) {} 119 const EntryType &entry)
120 : base_(base), delta_(delta), entry_(entry) {}
106 121
107 AddressType base() const { return base_; } 122 AddressType base() const { return base_; }
123 AddressType delta() const { return delta_; }
108 EntryType entry() const { return entry_; } 124 EntryType entry() const { return entry_; }
109 125
110 private: 126 private:
111 // The base address of the range. The high address does not need to 127 // The base address of the range. The high address does not need to
112 // be stored, because RangeMap uses it as the key to the map. 128 // be stored, because RangeMap uses it as the key to the map.
113 const AddressType base_; 129 const AddressType base_;
114 130
131 // The delta when the range is shrunk down.
132 const AddressType delta_;
133
115 // The entry corresponding to a range. 134 // The entry corresponding to a range.
116 const EntryType entry_; 135 const EntryType entry_;
117 }; 136 };
118 137
119 // Convenience types. 138 // Convenience types.
120 typedef std::map<AddressType, Range> AddressToRangeMap; 139 typedef std::map<AddressType, Range> AddressToRangeMap;
121 typedef typename AddressToRangeMap::const_iterator MapConstIterator; 140 typedef typename AddressToRangeMap::const_iterator MapConstIterator;
122 typedef typename AddressToRangeMap::value_type MapValue; 141 typedef typename AddressToRangeMap::value_type MapValue;
123 142
143 // Whether overlapping ranges can be shrunk down.
144 bool enable_shrink_down_;
145
124 // Maps the high address of each range to a EntryType. 146 // Maps the high address of each range to a EntryType.
125 AddressToRangeMap map_; 147 AddressToRangeMap map_;
126 }; 148 };
127 149
128 150
129 } // namespace google_breakpad 151 } // namespace google_breakpad
130 152
131 153
132 #endif // PROCESSOR_RANGE_MAP_H__ 154 #endif // PROCESSOR_RANGE_MAP_H__
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698