Deleted Added
sdiff udiff text old ( 12776:410b60d8a397 ) new ( 12777:70526b89f66e )
full compact
1/*
2 * Copyright (c) 2012, 2018 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software

--- 40 unchanged lines hidden (view full) ---

49
50#include "base/addr_range.hh"
51
52/**
53 * The AddrRangeMap uses an STL map to implement an interval tree for
54 * address decoding. The value stored is a template type and can be
55 * e.g. a port identifier, or a pointer.
56 */
57template
58class AddrRangeMap
59{
60 private:
61 typedef std::map<AddrRange, V> RangeMap;
62
63 public:
64 typedef typename RangeMap::iterator iterator;
65 typedef typename RangeMap::const_iterator const_iterator;

--- 53 unchanged lines hidden (view full) ---

119 return tree.end();
120
121 return tree.insert(std::make_pair(r, d)).first;
122 }
123
124 void
125 erase(iterator p)
126 {
127 tree.erase(p);
128 }
129
130 void
131 erase(iterator p, iterator q)
132 {
133 tree.erase(p,q);
134 }
135
136 void
137 clear()
138 {
139 tree.erase(tree.begin(), tree.end());
140 }
141
142 const_iterator
143 begin() const
144 {
145 return tree.begin();
146 }

--- 25 unchanged lines hidden (view full) ---

172 bool
173 empty() const
174 {
175 return tree.empty();
176 }
177
178 private:
179 /**
180 * Find entry that satisfies a condition on an address range
181 *
182 * Searches through the ranges in the address map and returns an
183 * iterator to the entry that satisfies the input conidition on
184 * the input address range. Returns end() if none found.
185 *
186 * @param r An input address range
187 * @param f A condition on an address range
188 * @return An iterator that contains the input address range
189 */
190 const_iterator
191 find(const AddrRange &r, std::function<bool(const AddrRange)> cond) const
192 {
193 const_iterator next = tree.upper_bound(r);
194 if (next != end() && cond(next->first)) {
195 return next;
196 }
197 if (next == begin())
198 return end();
199 next--;
200
201 const_iterator i;
202 do {
203 i = next;
204 if (cond(i->first)) {
205 return i;
206 }
207 // Keep looking if the next range merges with the current one.
208 } while (next != begin() &&
209 (--next)->first.mergesWith(i->first));
210
211 return end();
212 }
213
214 RangeMap tree;
215};
216
217#endif //__BASE_ADDR_RANGE_MAP_HH__