@@ -7,7 +7,7 @@ const DEFAULT_INITIAL_VEC_CAPACITY: usize = 5;
7
7
8
8
#[ derive( Debug , Clone , PartialEq ) ]
9
9
/// A hybrid vector that starts with a fixed-size array and grows dynamically with a vector.
10
- pub struct GrowableArray <
10
+ pub ( crate ) struct GrowableArray <
11
11
T : Default + Clone + PartialEq ,
12
12
const MAX_STACK_CAPACITY : usize = DEFAULT_MAX_STACK_CAPACITY ,
13
13
const INITIAL_VEC_CAPACITY : usize = DEFAULT_INITIAL_VEC_CAPACITY ,
@@ -39,12 +39,12 @@ impl<
39
39
> GrowableArray < T , MAX_STACK_CAPACITY , INITIAL_VEC_CAPACITY >
40
40
{
41
41
/// Creates a new `GrowableArray` with the default initial capacity.
42
- pub fn new ( ) -> Self {
42
+ pub ( crate ) fn new ( ) -> Self {
43
43
Self :: default ( )
44
44
}
45
45
46
46
/// Pushes a value into the `GrowableArray`.
47
- pub fn push ( & mut self , value : T ) {
47
+ pub ( crate ) fn push ( & mut self , value : T ) {
48
48
if self . count < MAX_STACK_CAPACITY {
49
49
self . initial [ self . count ] = value;
50
50
self . count += 1 ;
58
58
}
59
59
60
60
/// Gets a reference to the value at the specified index.
61
- pub fn get ( & self , index : usize ) -> Option < & T > {
61
+ pub ( crate ) fn get ( & self , index : usize ) -> Option < & T > {
62
62
if index < self . count {
63
63
Some ( & self . initial [ index] )
64
64
} else if let Some ( ref additional) = self . additional {
@@ -69,12 +69,12 @@ impl<
69
69
}
70
70
71
71
/// Returns the number of elements in the `GrowableArray`.
72
- pub fn len ( & self ) -> usize {
72
+ pub ( crate ) fn len ( & self ) -> usize {
73
73
self . count + self . additional . as_ref ( ) . map_or ( 0 , Vec :: len)
74
74
}
75
75
76
76
/// Returns an iterator over the elements in the `GrowableArray`.
77
- pub fn iter ( & self ) -> GrowableArrayIter < ' _ , T , MAX_STACK_CAPACITY > {
77
+ pub ( crate ) fn iter ( & self ) -> GrowableArrayIter < ' _ , T , MAX_STACK_CAPACITY > {
78
78
if self . additional . is_none ( ) || self . additional . as_ref ( ) . unwrap ( ) . is_empty ( ) {
79
79
GrowableArrayIter :: StackOnly {
80
80
iter : self . initial . iter ( ) . take ( self . count ) ,
86
86
}
87
87
}
88
88
}
89
-
90
- /// Checks if the `GrowableArray` contains the specified value.
91
- pub fn contains ( & self , value : & T ) -> bool {
92
- self . initial [ ..self . count ] . contains ( value)
93
- || self
94
- . additional
95
- . as_ref ( )
96
- . map_or ( false , |vec| vec. contains ( value) )
97
- }
98
-
99
- /// Maps each element to a new `GrowableArray` using the provided function.
100
- pub fn map < U : Default + Clone + PartialEq , F > (
101
- & self ,
102
- mut f : F ,
103
- ) -> GrowableArray < U , MAX_STACK_CAPACITY >
104
- where
105
- F : FnMut ( & T ) -> U ,
106
- {
107
- let mut new_vec = GrowableArray :: < U , MAX_STACK_CAPACITY > :: new ( ) ;
108
-
109
- for i in 0 ..self . count {
110
- new_vec. push ( f ( & self . initial [ i] ) ) ;
111
- }
112
- if let Some ( ref additional) = self . additional {
113
- for value in additional {
114
- new_vec. push ( f ( value) ) ;
115
- }
116
- }
117
-
118
- new_vec
119
- }
120
89
}
121
90
122
91
// Implement `IntoIterator` for `GrowableArray`
@@ -142,7 +111,8 @@ impl<T: Default + Clone + PartialEq, const INITIAL_CAPACITY: usize> IntoIterator
142
111
143
112
#[ derive( Debug ) ]
144
113
/// Iterator for consuming a `GrowableArray`.
145
- pub enum GrowableArrayIntoIter < T : Default + Clone + PartialEq , const INITIAL_CAPACITY : usize > {
114
+ pub ( crate ) enum GrowableArrayIntoIter < T : Default + Clone + PartialEq , const INITIAL_CAPACITY : usize >
115
+ {
146
116
/// stackonly
147
117
StackOnly {
148
118
/// iter
@@ -196,7 +166,7 @@ impl<'a, T: Default + Clone + PartialEq + 'a, const INITIAL_CAPACITY: usize> Int
196
166
197
167
#[ derive( Debug ) ]
198
168
/// Iterator for referencing elements in a `GrowableArray`.
199
- pub enum GrowableArrayIter < ' a , T : Default , const INITIAL_CAPACITY : usize > {
169
+ pub ( crate ) enum GrowableArrayIter < ' a , T : Default , const INITIAL_CAPACITY : usize > {
200
170
/// stackonly
201
171
StackOnly {
202
172
/// iter
@@ -319,17 +289,4 @@ mod tests {
319
289
assert_eq ! ( iter. next( ) , Some ( KeyValuePair ( key2, value2) ) ) ;
320
290
assert_eq ! ( iter. next( ) , None ) ;
321
291
}
322
-
323
- #[ test]
324
- fn test_contains ( ) {
325
- let mut collection = GrowableArray :: < i32 > :: new ( ) ;
326
- for i in 0 ..10 {
327
- collection. push ( i) ;
328
- }
329
- assert ! ( collection. contains( & 5 ) ) ;
330
- assert ! ( !collection. contains( & 15 ) ) ;
331
-
332
- collection. push ( 15 ) ;
333
- assert ! ( collection. contains( & 15 ) ) ;
334
- }
335
292
}
0 commit comments