1
- //! Implements a map from allocation ranges to data.
2
- //! This is somewhat similar to RangeMap, but the ranges
3
- //! and data are discrete and non-splittable. An allocation in the
4
- //! map will always have the same range until explicitly removed
1
+ //! Implements a map from allocation ranges to data. This is somewhat similar to RangeMap, but the
2
+ //! ranges and data are discrete and non-splittable -- they represent distinct "objects". An
3
+ //! allocation in the map will always have the same range until explicitly removed
5
4
6
5
use rustc_target:: abi:: Size ;
7
6
use std:: ops:: { Index , IndexMut , Range } ;
@@ -20,7 +19,7 @@ struct Elem<T> {
20
19
type Position = usize ;
21
20
22
21
#[ derive( Clone , Debug ) ]
23
- pub struct AllocationMap < T > {
22
+ pub struct RangeObjectMap < T > {
24
23
v : Vec < Elem < T > > ,
25
24
}
26
25
@@ -34,7 +33,7 @@ pub enum AccessType {
34
33
ImperfectlyOverlapping ( Range < Position > ) ,
35
34
}
36
35
37
- impl < T > AllocationMap < T > {
36
+ impl < T > RangeObjectMap < T > {
38
37
pub fn new ( ) -> Self {
39
38
Self { v : Vec :: new ( ) }
40
39
}
@@ -135,15 +134,15 @@ impl<T> AllocationMap<T> {
135
134
}
136
135
}
137
136
138
- impl < T > Index < Position > for AllocationMap < T > {
137
+ impl < T > Index < Position > for RangeObjectMap < T > {
139
138
type Output = T ;
140
139
141
140
fn index ( & self , pos : Position ) -> & Self :: Output {
142
141
& self . v [ pos] . data
143
142
}
144
143
}
145
144
146
- impl < T > IndexMut < Position > for AllocationMap < T > {
145
+ impl < T > IndexMut < Position > for RangeObjectMap < T > {
147
146
fn index_mut ( & mut self , pos : Position ) -> & mut Self :: Output {
148
147
& mut self . v [ pos] . data
149
148
}
@@ -159,7 +158,7 @@ mod tests {
159
158
fn empty_map ( ) {
160
159
// FIXME: make Size::from_bytes const
161
160
let four = Size :: from_bytes ( 4 ) ;
162
- let map = AllocationMap :: < ( ) > :: new ( ) ;
161
+ let map = RangeObjectMap :: < ( ) > :: new ( ) ;
163
162
164
163
// Correctly tells where we should insert the first element (at position 0)
165
164
assert_eq ! ( map. find_offset( Size :: from_bytes( 3 ) ) , Err ( 0 ) ) ;
@@ -173,7 +172,7 @@ mod tests {
173
172
fn no_overlapping_inserts ( ) {
174
173
let four = Size :: from_bytes ( 4 ) ;
175
174
176
- let mut map = AllocationMap :: < & str > :: new ( ) ;
175
+ let mut map = RangeObjectMap :: < & str > :: new ( ) ;
177
176
178
177
// |_|_|_|_|#|#|#|#|_|_|_|_|...
179
178
// 0 1 2 3 4 5 6 7 8 9 a b c d
@@ -187,7 +186,7 @@ mod tests {
187
186
fn boundaries ( ) {
188
187
let four = Size :: from_bytes ( 4 ) ;
189
188
190
- let mut map = AllocationMap :: < & str > :: new ( ) ;
189
+ let mut map = RangeObjectMap :: < & str > :: new ( ) ;
191
190
192
191
// |#|#|#|#|_|_|...
193
192
// 0 1 2 3 4 5
@@ -215,7 +214,7 @@ mod tests {
215
214
fn perfectly_overlapping ( ) {
216
215
let four = Size :: from_bytes ( 4 ) ;
217
216
218
- let mut map = AllocationMap :: < & str > :: new ( ) ;
217
+ let mut map = RangeObjectMap :: < & str > :: new ( ) ;
219
218
220
219
// |#|#|#|#|_|_|...
221
220
// 0 1 2 3 4 5
@@ -241,7 +240,7 @@ mod tests {
241
240
fn straddling ( ) {
242
241
let four = Size :: from_bytes ( 4 ) ;
243
242
244
- let mut map = AllocationMap :: < & str > :: new ( ) ;
243
+ let mut map = RangeObjectMap :: < & str > :: new ( ) ;
245
244
246
245
// |_|_|_|_|#|#|#|#|_|_|_|_|...
247
246
// 0 1 2 3 4 5 6 7 8 9 a b c d
0 commit comments