diff options
author | Son Ho | 2023-07-12 15:58:38 +0200 |
---|---|---|
committer | Son Ho | 2023-07-12 15:58:38 +0200 |
commit | e010c10fb9a1e2d88b52a4f6b4a0865448276013 (patch) | |
tree | bb33eccde0143f2faf2174a4ede025cb41c398af /tests/lean/Hashmap | |
parent | 59e4a06480b5365f48dc68de80f44841f94094ed (diff) |
Make the `by inlit` implicit
Diffstat (limited to 'tests/lean/Hashmap')
-rw-r--r-- | tests/lean/Hashmap/Funs.lean | 81 |
1 files changed, 33 insertions, 48 deletions
diff --git a/tests/lean/Hashmap/Funs.lean b/tests/lean/Hashmap/Funs.lean index 5e11ffdd..870693b5 100644 --- a/tests/lean/Hashmap/Funs.lean +++ b/tests/lean/Hashmap/Funs.lean @@ -12,11 +12,11 @@ def hash_key (k : Usize) : Result Usize := /- [hashmap::HashMap::{0}::allocate_slots]: loop 0: forward function -/ divergent def HashMap.allocate_slots_loop (T : Type) (slots : Vec (List T)) (n : Usize) : Result (Vec (List T)) := - if n > (Usize.ofInt 0 (by intlit)) + if n > (Usize.ofInt 0) then do let slots0 ← Vec.push (List T) slots List.Nil - let n0 ← n - (Usize.ofInt 1 (by intlit)) + let n0 ← n - (Usize.ofInt 1) HashMap.allocate_slots_loop T slots0 n0 else Result.ret slots @@ -38,7 +38,7 @@ def HashMap.new_with_capacity let i0 ← i / max_load_divisor Result.ret { - num_entries := (Usize.ofInt 0 (by intlit)), + num_entries := (Usize.ofInt 0), max_load_factor := (max_load_dividend, max_load_divisor), max_load := i0, slots := slots @@ -46,8 +46,7 @@ def HashMap.new_with_capacity /- [hashmap::HashMap::{0}::new]: forward function -/ def HashMap.new (T : Type) : Result (HashMap T) := - HashMap.new_with_capacity T (Usize.ofInt 32 (by intlit)) - (Usize.ofInt 4 (by intlit)) (Usize.ofInt 5 (by intlit)) + HashMap.new_with_capacity T (Usize.ofInt 32) (Usize.ofInt 4) (Usize.ofInt 5) /- [hashmap::HashMap::{0}::clear]: loop 0: merged forward/backward function (there is a single backward function, and the forward function returns ()) -/ @@ -57,7 +56,7 @@ divergent def HashMap.clear_loop if i < i0 then do - let i1 ← i + (Usize.ofInt 1 (by intlit)) + let i1 ← i + (Usize.ofInt 1) let slots0 ← Vec.index_mut_back (List T) slots i List.Nil HashMap.clear_loop T slots0 i1 else Result.ret slots @@ -66,9 +65,8 @@ divergent def HashMap.clear_loop (there is a single backward function, and the forward function returns ()) -/ def HashMap.clear (T : Type) (self : HashMap T) : Result (HashMap T) := do - let v ← HashMap.clear_loop T self.slots (Usize.ofInt 0 (by intlit)) - Result.ret - { self with num_entries := (Usize.ofInt 0 (by intlit)), slots := v } + let v ← HashMap.clear_loop T self.slots (Usize.ofInt 0) + Result.ret { self with num_entries := (Usize.ofInt 0), slots := v } /- [hashmap::HashMap::{0}::len]: forward function -/ def HashMap.len (T : Type) (self : HashMap T) : Result Usize := @@ -123,7 +121,7 @@ def HashMap.insert_no_resize if inserted then do - let i0 ← self.num_entries + (Usize.ofInt 1 (by intlit)) + let i0 ← self.num_entries + (Usize.ofInt 1) let l0 ← HashMap.insert_in_list_back T key value l let v ← Vec.index_mut_back (List T) self.slots hash_mod l0 Result.ret { self with num_entries := i0, slots := v } @@ -134,8 +132,7 @@ def HashMap.insert_no_resize Result.ret { self with slots := v } /- [core::num::u32::{9}::MAX] -/ -def core_num_u32_max_body : Result U32 := - Result.ret (U32.ofInt 4294967295 (by intlit)) +def core_num_u32_max_body : Result U32 := Result.ret (U32.ofInt 4294967295) def core_num_u32_max_c : U32 := eval_global core_num_u32_max_body (by simp) /- [hashmap::HashMap::{0}::move_elements_from_list]: loop 0: merged forward/backward function @@ -168,7 +165,7 @@ divergent def HashMap.move_elements_loop let l ← Vec.index_mut (List T) slots i let ls := mem.replace (List T) l List.Nil let ntable0 ← HashMap.move_elements_from_list T ntable ls - let i1 ← i + (Usize.ofInt 1 (by intlit)) + let i1 ← i + (Usize.ofInt 1) let l0 := mem.replace_back (List T) l List.Nil let slots0 ← Vec.index_mut_back (List T) slots i l0 HashMap.move_elements_loop T ntable0 slots0 i1 @@ -188,16 +185,16 @@ def HashMap.try_resize (T : Type) (self : HashMap T) : Result (HashMap T) := do let max_usize ← Scalar.cast .Usize core_num_u32_max_c let capacity := Vec.len (List T) self.slots - let n1 ← max_usize / (Usize.ofInt 2 (by intlit)) + let n1 ← max_usize / (Usize.ofInt 2) let (i, i0) := self.max_load_factor let i1 ← n1 / i if capacity <= i1 then do - let i2 ← capacity * (Usize.ofInt 2 (by intlit)) + let i2 ← capacity * (Usize.ofInt 2) let ntable ← HashMap.new_with_capacity T i2 i i0 let (ntable0, _) ← - HashMap.move_elements T ntable self.slots (Usize.ofInt 0 (by intlit)) + HashMap.move_elements T ntable self.slots (Usize.ofInt 0) Result.ret { ntable0 @@ -377,7 +374,7 @@ def HashMap.remove | Option.none => Result.ret Option.none | Option.some x0 => do - let _ ← self.num_entries - (Usize.ofInt 1 (by intlit)) + let _ ← self.num_entries - (Usize.ofInt 1) Result.ret (Option.some x0) /- [hashmap::HashMap::{0}::remove]: backward function 0 -/ @@ -397,7 +394,7 @@ def HashMap.remove_back Result.ret { self with slots := v } | Option.some x0 => do - let i0 ← self.num_entries - (Usize.ofInt 1 (by intlit)) + let i0 ← self.num_entries - (Usize.ofInt 1) let l0 ← HashMap.remove_from_list_back T key l let v ← Vec.index_mut_back (List T) self.slots hash_mod l0 Result.ret { self with num_entries := i0, slots := v } @@ -406,55 +403,43 @@ def HashMap.remove_back def test1 : Result Unit := do let hm ← HashMap.new U64 - let hm0 ← - HashMap.insert U64 hm (Usize.ofInt 0 (by intlit)) - (U64.ofInt 42 (by intlit)) - let hm1 ← - HashMap.insert U64 hm0 (Usize.ofInt 128 (by intlit)) - (U64.ofInt 18 (by intlit)) - let hm2 ← - HashMap.insert U64 hm1 (Usize.ofInt 1024 (by intlit)) - (U64.ofInt 138 (by intlit)) - let hm3 ← - HashMap.insert U64 hm2 (Usize.ofInt 1056 (by intlit)) - (U64.ofInt 256 (by intlit)) - let i ← HashMap.get U64 hm3 (Usize.ofInt 128 (by intlit)) - if not (i = (U64.ofInt 18 (by intlit))) + let hm0 ← HashMap.insert U64 hm (Usize.ofInt 0) (U64.ofInt 42) + let hm1 ← HashMap.insert U64 hm0 (Usize.ofInt 128) (U64.ofInt 18) + let hm2 ← HashMap.insert U64 hm1 (Usize.ofInt 1024) (U64.ofInt 138) + let hm3 ← HashMap.insert U64 hm2 (Usize.ofInt 1056) (U64.ofInt 256) + let i ← HashMap.get U64 hm3 (Usize.ofInt 128) + if not (i = (U64.ofInt 18)) then Result.fail Error.panic else do let hm4 ← - HashMap.get_mut_back U64 hm3 (Usize.ofInt 1024 (by intlit)) - (U64.ofInt 56 (by intlit)) - let i0 ← HashMap.get U64 hm4 (Usize.ofInt 1024 (by intlit)) - if not (i0 = (U64.ofInt 56 (by intlit))) + HashMap.get_mut_back U64 hm3 (Usize.ofInt 1024) (U64.ofInt 56) + let i0 ← HashMap.get U64 hm4 (Usize.ofInt 1024) + if not (i0 = (U64.ofInt 56)) then Result.fail Error.panic else do - let x ← HashMap.remove U64 hm4 (Usize.ofInt 1024 (by intlit)) + let x ← HashMap.remove U64 hm4 (Usize.ofInt 1024) match x with | Option.none => Result.fail Error.panic | Option.some x0 => - if not (x0 = (U64.ofInt 56 (by intlit))) + if not (x0 = (U64.ofInt 56)) then Result.fail Error.panic else do - let hm5 ← - HashMap.remove_back U64 hm4 (Usize.ofInt 1024 (by intlit)) - let i1 ← HashMap.get U64 hm5 (Usize.ofInt 0 (by intlit)) - if not (i1 = (U64.ofInt 42 (by intlit))) + let hm5 ← HashMap.remove_back U64 hm4 (Usize.ofInt 1024) + let i1 ← HashMap.get U64 hm5 (Usize.ofInt 0) + if not (i1 = (U64.ofInt 42)) then Result.fail Error.panic else do - let i2 ← - HashMap.get U64 hm5 (Usize.ofInt 128 (by intlit)) - if not (i2 = (U64.ofInt 18 (by intlit))) + let i2 ← HashMap.get U64 hm5 (Usize.ofInt 128) + if not (i2 = (U64.ofInt 18)) then Result.fail Error.panic else do - let i3 ← - HashMap.get U64 hm5 (Usize.ofInt 1056 (by intlit)) - if not (i3 = (U64.ofInt 256 (by intlit))) + let i3 ← HashMap.get U64 hm5 (Usize.ofInt 1056) + if not (i3 = (U64.ofInt 256)) then Result.fail Error.panic else Result.ret () |