8888 r .linked_keys [i ] = i + 1 ;
8989 }
9090 // set the last linked key to 2^32 - 1
91- r .linked_keys [M + 1 ] = 0xFFFFFFFF ;
91+ r .linked_keys [M + 1 ] = 0xFFFFFFFF ;
9292
9393 // populate values based on the sorted keys
9494 // note: self.keys[i] maps to self.values[i+1]
@@ -117,12 +117,9 @@ where
117117 // because `self.keys` is sorted, we can simply validate that
118118 // sorted_keys.sorted[0] < 2^32
119119 // sorted_keys.sorted[N-1] < maximum
120- //ComparisonFuncs::assert_greater_than_or_equal(sorted_keys.sorted[0], 0);
121- //ComparisonFuncs::assert_greater_than_or_equal(_maximum, 0);
122- //ComparisonFuncs::assert_greater_than_or_equal(_maximum, sorted_keys.sorted[M - 1]);
123120
124- // _maximum.assert_max_bit_size::<32>() ;
125- // (_maximum - sorted_keys.sorted[M - 1]).assert_max_bit_size::<32>( );
121+ let val = sorted_keys . sorted [ M - 1 ] ;
122+ assert (_maximum >= sorted_keys .sorted [M - 1 ]);
126123 r .tail_ptr = M + 2 ;
127124 r
128125 }
@@ -183,13 +180,10 @@ where
183180 // `self.keys[found_index] + 1 - found <= idx <= self.keys[found_index + 1 - found] - 1 + found
184181 let lhs = self .keys [lhs_index ];
185182 let rhs = self .keys [rhs_index ];
186- let lhs_condition = idx + found - lhs - 1 ;
187- let rhs_condition = rhs + found - 1 - idx ;
188- //ComparisonFuncs::assert_greater_than_or_equal(lhs_condition, 0);
189- //ComparisonFuncs::assert_greater_than_or_equal(rhs_condition, 0);
190183
191- // lhs_condition.assert_max_bit_size::<32>();
192- // rhs_condition.assert_max_bit_size::<32>();
184+ assert (lhs + 1 - found <= idx );
185+ assert (idx <= rhs + found - 1 );
186+
193187 // lhs points to tail_ptr
194188 // tail_ptr points to rhs
195189 if (found == 0 ) {
@@ -207,7 +201,6 @@ where
207201
208202 fn get (self , idx : u32 ) -> T {
209203 let (found , found_index ) = unsafe { self .search_for_key (idx ) };
210- println (f"f { found} fi { found_index} " );
211204 assert (found * found == found );
212205
213206 let lhs_index = found_index ;
@@ -225,7 +218,7 @@ where
225218 // `self.keys[found_index] + 1 - found <= idx <= self.keys[found_index + 1 - found] - 1 + found
226219 let lhs = self .keys [lhs_index ];
227220 let rhs = self .keys [rhs_index ];
228- let lhs_condition = idx + found - lhs - 1 ;
221+ let lhs_condition = idx + found - lhs - 1 ;
229222 let rhs_condition = rhs + found - 1 - idx ;
230223 //ComparisonFuncs::assert_greater_than_or_equal(lhs_condition, 0);
231224 //ComparisonFuncs::assert_greater_than_or_equal(rhs_condition, 0);
@@ -284,16 +277,16 @@ mod test {
284277 fn test_sparse_lookup_boundary_cases () {
285278 // what about when keys[0] = 0 and keys[N-1] = 2^32 - 1?
286279 let example : MutSparseArray <6 , _ > = MutSparseArray ::create (
287- [0 , 99999 , 7 , 0xffffffff ],
280+ [0 , 99999 , 7 , 0xfffffffe ],
288281 [123 , 101112 , 789 , 456 ],
289282 0xFFFFFFFF ,
290283 );
291284
292285 assert (example .get (0 ) == 123 );
293286 assert (example .get (99999 ) == 101112 );
294287 assert (example .get (7 ) == 789 );
295- assert (example .get (0xffffffff ) == 456 );
296- assert (example .get (0xfffffffe ) == 0 );
288+ assert (example .get (0xfffffffe ) == 456 );
289+ assert (example .get (0xfffffffd ) == 0 );
297290 }
298291
299292 #[test]
@@ -313,25 +306,23 @@ mod test {
313306 assert (example .get (100000 ) == 0 );
314307 }
315308
316- #[test(should_fail_with = "call to assert_max_bit_size" )]
309+ #[test(should_fail )]
317310 fn test_sparse_lookup_overflow () {
318311 let example : MutSparseArray <8 , _ > =
319312 MutSparseArray ::create ([1 , 5 , 7 , 99999 ], [123 , 456 , 789 , 101112 ], 100000 );
320313
321314 assert (example .get (100000 ) == 0 );
322315 }
323316
324- /**
325- #[test(should_fail_with = "call to assert_max_bit_size")]
317+ #[test(should_fail)]
326318 fn test_sparse_lookup_boundary_case_overflow () {
327319 let example : MutSparseArray <4 , _ > =
328320 MutSparseArray ::create ([0 , 5 , 7 , 0xffffffff ], [123 , 456 , 789 , 101112 ], 0xFFFFFFFF );
329321
330322 assert (example .get (0xFFFFFFFF ) == 0 );
331323 }
332- **/
333324
334- #[test(should_fail_with = "call to assert_max_bit_size" )]
325+ #[test(should_fail )]
335326 fn test_sparse_lookup_key_exceeds_maximum () {
336327 let example : MutSparseArray <6 , _ > =
337328 MutSparseArray ::create ([0 , 5 , 7 , 0xffffffff ], [123 , 456 , 789 , 101112 ], 0xffffffff );
0 commit comments