@@ -48,7 +48,7 @@ pub struct MutSparseArray<let N: u32, T> {
4848pub struct SparseArray <let N : u32 , T > {
4949 keys : [u32 ; N + 2 ],
5050 values : [T ; N + 3 ],
51- maximum : u32 , // can be up to 2^32
51+ maximum : u32 , // can be up to 2^32 - 1
5252}
5353impl <let N : u32 , T > SparseArray <N , T >
5454where
5959 * @brief construct a SparseArray
6060 **/
6161 pub (crate ) fn create (_keys : [u32 ; N ], _values : [T ; N ], size : u32 ) -> Self {
62+ assert (size >= 1 );
6263 let _maximum = size - 1 ;
6364 let mut r : Self =
6465 SparseArray { keys : [0 ; N + 2 ], values : [T ::default (); N + 3 ], maximum : _maximum };
@@ -150,12 +151,8 @@ where
150151 // `self.keys[found_index] + 1 - found <= idx <= self.keys[found_index + 1 - found] - 1 + found
151152 let lhs = self .keys [found_index ];
152153 let rhs = self .keys [found_index + 1 - found ];
153- //let lhs_condition = idx - lhs - 1 + found;
154154 assert (lhs + 1 - found <= idx );
155155 assert (idx <= rhs + found - 1 );
156- //let rhs_condition = rhs - 1 + found - idx;
157- //lhs_condition.assert_max_bit_size::<32>();
158- //rhs_condition.assert_max_bit_size::<32>();
159156
160157 // self.keys[i] maps to self.values[i+1]
161158 // however...if we did not find a non-sparse entry, we want to return self.values[0] (the default value)
0 commit comments