diff options
Diffstat (limited to 'tests/lean/HashmapMain')
-rw-r--r-- | tests/lean/HashmapMain/ExternalFuns.lean | 9 | ||||
-rw-r--r-- | tests/lean/HashmapMain/Funs.lean | 221 | ||||
-rw-r--r-- | tests/lean/HashmapMain/FunsExternal.lean | 17 | ||||
-rw-r--r-- | tests/lean/HashmapMain/FunsExternal_Template.lean | 16 | ||||
-rw-r--r-- | tests/lean/HashmapMain/Opaque.lean | 8 | ||||
-rw-r--r-- | tests/lean/HashmapMain/Types.lean | 5 |
6 files changed, 148 insertions, 128 deletions
diff --git a/tests/lean/HashmapMain/ExternalFuns.lean b/tests/lean/HashmapMain/ExternalFuns.lean deleted file mode 100644 index bc831158..00000000 --- a/tests/lean/HashmapMain/ExternalFuns.lean +++ /dev/null @@ -1,9 +0,0 @@ -import Base -import HashmapMain.Types -import HashmapMain.Opaque - -namespace HashmapMain - -def opaque_defs : OpaqueDefs := by sorry - -end HashmapMain diff --git a/tests/lean/HashmapMain/Funs.lean b/tests/lean/HashmapMain/Funs.lean index 34a0eca1..06929431 100644 --- a/tests/lean/HashmapMain/Funs.lean +++ b/tests/lean/HashmapMain/Funs.lean @@ -2,17 +2,16 @@ -- [hashmap_main]: function definitions import Base import HashmapMain.Types -import HashmapMain.ExternalFuns +import HashmapMain.FunsExternal open Primitives - -namespace HashmapMain +namespace hashmap_main /- [hashmap_main::hashmap::hash_key] -/ -def hashmap_hash_key_fwd (k : Usize) : Result Usize := +def hashmap.hash_key_fwd (k : Usize) : Result Usize := Result.ret k /- [hashmap_main::hashmap::HashMap::{0}::allocate_slots] -/ -divergent def hashmap_hash_map_allocate_slots_loop_fwd +divergent def hashmap.HashMap.allocate_slots_loop_fwd (T : Type) (slots : Vec (hashmap_list_t T)) (n : Usize) : Result (Vec (hashmap_list_t T)) := @@ -21,25 +20,25 @@ divergent def hashmap_hash_map_allocate_slots_loop_fwd do let slots0 ← vec_push_back (hashmap_list_t T) slots hashmap_list_t.Nil let n0 ← n - (Usize.ofInt 1 (by intlit)) - hashmap_hash_map_allocate_slots_loop_fwd T slots0 n0 + hashmap.HashMap.allocate_slots_loop_fwd T slots0 n0 else Result.ret slots /- [hashmap_main::hashmap::HashMap::{0}::allocate_slots] -/ -def hashmap_hash_map_allocate_slots_fwd +def hashmap.HashMap.allocate_slots_fwd (T : Type) (slots : Vec (hashmap_list_t T)) (n : Usize) : Result (Vec (hashmap_list_t T)) := - hashmap_hash_map_allocate_slots_loop_fwd T slots n + hashmap.HashMap.allocate_slots_loop_fwd T slots n /- [hashmap_main::hashmap::HashMap::{0}::new_with_capacity] -/ -def hashmap_hash_map_new_with_capacity_fwd +def hashmap.HashMap.new_with_capacity_fwd (T : Type) (capacity : Usize) (max_load_dividend : Usize) (max_load_divisor : Usize) : Result (hashmap_hash_map_t T) := do let v := vec_new (hashmap_list_t T) - let slots ← hashmap_hash_map_allocate_slots_fwd T v capacity + let slots ← hashmap.HashMap.allocate_slots_fwd T v capacity let i ← capacity * max_load_dividend let i0 ← i / max_load_divisor Result.ret @@ -52,12 +51,12 @@ def hashmap_hash_map_new_with_capacity_fwd } /- [hashmap_main::hashmap::HashMap::{0}::new] -/ -def hashmap_hash_map_new_fwd (T : Type) : Result (hashmap_hash_map_t T) := - hashmap_hash_map_new_with_capacity_fwd T (Usize.ofInt 32 (by intlit)) +def hashmap.HashMap.new_fwd (T : Type) : Result (hashmap_hash_map_t T) := + hashmap.HashMap.new_with_capacity_fwd T (Usize.ofInt 32 (by intlit)) (Usize.ofInt 4 (by intlit)) (Usize.ofInt 5 (by intlit)) /- [hashmap_main::hashmap::HashMap::{0}::clear] -/ -divergent def hashmap_hash_map_clear_loop_fwd_back +divergent def hashmap.HashMap.clear_loop_fwd_back (T : Type) (slots : Vec (hashmap_list_t T)) (i : Usize) : Result (Vec (hashmap_list_t T)) := @@ -68,15 +67,15 @@ divergent def hashmap_hash_map_clear_loop_fwd_back let i1 ← i + (Usize.ofInt 1 (by intlit)) let slots0 ← vec_index_mut_back (hashmap_list_t T) slots i hashmap_list_t.Nil - hashmap_hash_map_clear_loop_fwd_back T slots0 i1 + hashmap.HashMap.clear_loop_fwd_back T slots0 i1 else Result.ret slots /- [hashmap_main::hashmap::HashMap::{0}::clear] -/ -def hashmap_hash_map_clear_fwd_back +def hashmap.HashMap.clear_fwd_back (T : Type) (self : hashmap_hash_map_t T) : Result (hashmap_hash_map_t T) := do let v ← - hashmap_hash_map_clear_loop_fwd_back T self.hashmap_hash_map_slots + hashmap.HashMap.clear_loop_fwd_back T self.hashmap_hash_map_slots (Usize.ofInt 0 (by intlit)) Result.ret { @@ -87,27 +86,27 @@ def hashmap_hash_map_clear_fwd_back } /- [hashmap_main::hashmap::HashMap::{0}::len] -/ -def hashmap_hash_map_len_fwd +def hashmap.HashMap.len_fwd (T : Type) (self : hashmap_hash_map_t T) : Result Usize := Result.ret self.hashmap_hash_map_num_entries /- [hashmap_main::hashmap::HashMap::{0}::insert_in_list] -/ -divergent def hashmap_hash_map_insert_in_list_loop_fwd +divergent def hashmap.HashMap.insert_in_list_loop_fwd (T : Type) (key : Usize) (value : T) (ls : hashmap_list_t T) : Result Bool := match ls with | hashmap_list_t.Cons ckey cvalue tl => if ckey = key then Result.ret false - else hashmap_hash_map_insert_in_list_loop_fwd T key value tl + else hashmap.HashMap.insert_in_list_loop_fwd T key value tl | hashmap_list_t.Nil => Result.ret true /- [hashmap_main::hashmap::HashMap::{0}::insert_in_list] -/ -def hashmap_hash_map_insert_in_list_fwd +def hashmap.HashMap.insert_in_list_fwd (T : Type) (key : Usize) (value : T) (ls : hashmap_list_t T) : Result Bool := - hashmap_hash_map_insert_in_list_loop_fwd T key value ls + hashmap.HashMap.insert_in_list_loop_fwd T key value ls /- [hashmap_main::hashmap::HashMap::{0}::insert_in_list] -/ -divergent def hashmap_hash_map_insert_in_list_loop_back +divergent def hashmap.HashMap.insert_in_list_loop_back (T : Type) (key : Usize) (value : T) (ls : hashmap_list_t T) : Result (hashmap_list_t T) := @@ -117,37 +116,37 @@ divergent def hashmap_hash_map_insert_in_list_loop_back then Result.ret (hashmap_list_t.Cons ckey value tl) else do - let tl0 ← hashmap_hash_map_insert_in_list_loop_back T key value tl + let tl0 ← hashmap.HashMap.insert_in_list_loop_back T key value tl Result.ret (hashmap_list_t.Cons ckey cvalue tl0) | hashmap_list_t.Nil => let l := hashmap_list_t.Nil Result.ret (hashmap_list_t.Cons key value l) /- [hashmap_main::hashmap::HashMap::{0}::insert_in_list] -/ -def hashmap_hash_map_insert_in_list_back +def hashmap.HashMap.insert_in_list_back (T : Type) (key : Usize) (value : T) (ls : hashmap_list_t T) : Result (hashmap_list_t T) := - hashmap_hash_map_insert_in_list_loop_back T key value ls + hashmap.HashMap.insert_in_list_loop_back T key value ls /- [hashmap_main::hashmap::HashMap::{0}::insert_no_resize] -/ -def hashmap_hash_map_insert_no_resize_fwd_back +def hashmap.HashMap.insert_no_resize_fwd_back (T : Type) (self : hashmap_hash_map_t T) (key : Usize) (value : T) : Result (hashmap_hash_map_t T) := do - let hash ← hashmap_hash_key_fwd key + let hash ← hashmap.hash_key_fwd key let i := vec_len (hashmap_list_t T) self.hashmap_hash_map_slots let hash_mod ← hash % i let l ← vec_index_mut_fwd (hashmap_list_t T) self.hashmap_hash_map_slots hash_mod - let inserted ← hashmap_hash_map_insert_in_list_fwd T key value l + let inserted ← hashmap.HashMap.insert_in_list_fwd T key value l if inserted then do let i0 ← self.hashmap_hash_map_num_entries + (Usize.ofInt 1 (by intlit)) - let l0 ← hashmap_hash_map_insert_in_list_back T key value l + let l0 ← hashmap.HashMap.insert_in_list_back T key value l let v ← vec_index_mut_back (hashmap_list_t T) self.hashmap_hash_map_slots hash_mod l0 @@ -159,7 +158,7 @@ def hashmap_hash_map_insert_no_resize_fwd_back } else do - let l0 ← hashmap_hash_map_insert_in_list_back T key value l + let l0 ← hashmap.HashMap.insert_in_list_back T key value l let v ← vec_index_mut_back (hashmap_list_t T) self.hashmap_hash_map_slots hash_mod l0 @@ -171,26 +170,26 @@ def core_num_u32_max_body : Result U32 := def core_num_u32_max_c : U32 := eval_global core_num_u32_max_body (by simp) /- [hashmap_main::hashmap::HashMap::{0}::move_elements_from_list] -/ -divergent def hashmap_hash_map_move_elements_from_list_loop_fwd_back +divergent def hashmap.HashMap.move_elements_from_list_loop_fwd_back (T : Type) (ntable : hashmap_hash_map_t T) (ls : hashmap_list_t T) : Result (hashmap_hash_map_t T) := match ls with | hashmap_list_t.Cons k v tl => do - let ntable0 ← hashmap_hash_map_insert_no_resize_fwd_back T ntable k v - hashmap_hash_map_move_elements_from_list_loop_fwd_back T ntable0 tl + let ntable0 ← hashmap.HashMap.insert_no_resize_fwd_back T ntable k v + hashmap.HashMap.move_elements_from_list_loop_fwd_back T ntable0 tl | hashmap_list_t.Nil => Result.ret ntable /- [hashmap_main::hashmap::HashMap::{0}::move_elements_from_list] -/ -def hashmap_hash_map_move_elements_from_list_fwd_back +def hashmap.HashMap.move_elements_from_list_fwd_back (T : Type) (ntable : hashmap_hash_map_t T) (ls : hashmap_list_t T) : Result (hashmap_hash_map_t T) := - hashmap_hash_map_move_elements_from_list_loop_fwd_back T ntable ls + hashmap.HashMap.move_elements_from_list_loop_fwd_back T ntable ls /- [hashmap_main::hashmap::HashMap::{0}::move_elements] -/ -divergent def hashmap_hash_map_move_elements_loop_fwd_back +divergent def hashmap.HashMap.move_elements_loop_fwd_back (T : Type) (ntable : hashmap_hash_map_t T) (slots : Vec (hashmap_list_t T)) (i : Usize) : Result ((hashmap_hash_map_t T) × (Vec (hashmap_list_t T))) @@ -202,23 +201,23 @@ divergent def hashmap_hash_map_move_elements_loop_fwd_back let l ← vec_index_mut_fwd (hashmap_list_t T) slots i let ls := mem_replace_fwd (hashmap_list_t T) l hashmap_list_t.Nil let ntable0 ← - hashmap_hash_map_move_elements_from_list_fwd_back T ntable ls + hashmap.HashMap.move_elements_from_list_fwd_back T ntable ls let i1 ← i + (Usize.ofInt 1 (by intlit)) let l0 := mem_replace_back (hashmap_list_t T) l hashmap_list_t.Nil let slots0 ← vec_index_mut_back (hashmap_list_t T) slots i l0 - hashmap_hash_map_move_elements_loop_fwd_back T ntable0 slots0 i1 + hashmap.HashMap.move_elements_loop_fwd_back T ntable0 slots0 i1 else Result.ret (ntable, slots) /- [hashmap_main::hashmap::HashMap::{0}::move_elements] -/ -def hashmap_hash_map_move_elements_fwd_back +def hashmap.HashMap.move_elements_fwd_back (T : Type) (ntable : hashmap_hash_map_t T) (slots : Vec (hashmap_list_t T)) (i : Usize) : Result ((hashmap_hash_map_t T) × (Vec (hashmap_list_t T))) := - hashmap_hash_map_move_elements_loop_fwd_back T ntable slots i + hashmap.HashMap.move_elements_loop_fwd_back T ntable slots i /- [hashmap_main::hashmap::HashMap::{0}::try_resize] -/ -def hashmap_hash_map_try_resize_fwd_back +def hashmap.HashMap.try_resize_fwd_back (T : Type) (self : hashmap_hash_map_t T) : Result (hashmap_hash_map_t T) := do let max_usize ← Scalar.cast .Usize core_num_u32_max_c @@ -230,9 +229,9 @@ def hashmap_hash_map_try_resize_fwd_back then do let i2 ← capacity * (Usize.ofInt 2 (by intlit)) - let ntable ← hashmap_hash_map_new_with_capacity_fwd T i2 i i0 + let ntable ← hashmap.HashMap.new_with_capacity_fwd T i2 i i0 let (ntable0, _) ← - hashmap_hash_map_move_elements_fwd_back T ntable + hashmap.HashMap.move_elements_fwd_back T ntable self.hashmap_hash_map_slots (Usize.ofInt 0 (by intlit)) Result.ret { @@ -244,86 +243,86 @@ def hashmap_hash_map_try_resize_fwd_back else Result.ret { self with hashmap_hash_map_max_load_factor := (i, i0) } /- [hashmap_main::hashmap::HashMap::{0}::insert] -/ -def hashmap_hash_map_insert_fwd_back +def hashmap.HashMap.insert_fwd_back (T : Type) (self : hashmap_hash_map_t T) (key : Usize) (value : T) : Result (hashmap_hash_map_t T) := do - let self0 ← hashmap_hash_map_insert_no_resize_fwd_back T self key value - let i ← hashmap_hash_map_len_fwd T self0 + let self0 ← hashmap.HashMap.insert_no_resize_fwd_back T self key value + let i ← hashmap.HashMap.len_fwd T self0 if i > self0.hashmap_hash_map_max_load - then hashmap_hash_map_try_resize_fwd_back T self0 + then hashmap.HashMap.try_resize_fwd_back T self0 else Result.ret self0 /- [hashmap_main::hashmap::HashMap::{0}::contains_key_in_list] -/ -divergent def hashmap_hash_map_contains_key_in_list_loop_fwd +divergent def hashmap.HashMap.contains_key_in_list_loop_fwd (T : Type) (key : Usize) (ls : hashmap_list_t T) : Result Bool := match ls with | hashmap_list_t.Cons ckey t tl => if ckey = key then Result.ret true - else hashmap_hash_map_contains_key_in_list_loop_fwd T key tl + else hashmap.HashMap.contains_key_in_list_loop_fwd T key tl | hashmap_list_t.Nil => Result.ret false /- [hashmap_main::hashmap::HashMap::{0}::contains_key_in_list] -/ -def hashmap_hash_map_contains_key_in_list_fwd +def hashmap.HashMap.contains_key_in_list_fwd (T : Type) (key : Usize) (ls : hashmap_list_t T) : Result Bool := - hashmap_hash_map_contains_key_in_list_loop_fwd T key ls + hashmap.HashMap.contains_key_in_list_loop_fwd T key ls /- [hashmap_main::hashmap::HashMap::{0}::contains_key] -/ -def hashmap_hash_map_contains_key_fwd +def hashmap.HashMap.contains_key_fwd (T : Type) (self : hashmap_hash_map_t T) (key : Usize) : Result Bool := do - let hash ← hashmap_hash_key_fwd key + let hash ← hashmap.hash_key_fwd key let i := vec_len (hashmap_list_t T) self.hashmap_hash_map_slots let hash_mod ← hash % i let l ← vec_index_fwd (hashmap_list_t T) self.hashmap_hash_map_slots hash_mod - hashmap_hash_map_contains_key_in_list_fwd T key l + hashmap.HashMap.contains_key_in_list_fwd T key l /- [hashmap_main::hashmap::HashMap::{0}::get_in_list] -/ -divergent def hashmap_hash_map_get_in_list_loop_fwd +divergent def hashmap.HashMap.get_in_list_loop_fwd (T : Type) (key : Usize) (ls : hashmap_list_t T) : Result T := match ls with | hashmap_list_t.Cons ckey cvalue tl => if ckey = key then Result.ret cvalue - else hashmap_hash_map_get_in_list_loop_fwd T key tl + else hashmap.HashMap.get_in_list_loop_fwd T key tl | hashmap_list_t.Nil => Result.fail Error.panic /- [hashmap_main::hashmap::HashMap::{0}::get_in_list] -/ -def hashmap_hash_map_get_in_list_fwd +def hashmap.HashMap.get_in_list_fwd (T : Type) (key : Usize) (ls : hashmap_list_t T) : Result T := - hashmap_hash_map_get_in_list_loop_fwd T key ls + hashmap.HashMap.get_in_list_loop_fwd T key ls /- [hashmap_main::hashmap::HashMap::{0}::get] -/ -def hashmap_hash_map_get_fwd +def hashmap.HashMap.get_fwd (T : Type) (self : hashmap_hash_map_t T) (key : Usize) : Result T := do - let hash ← hashmap_hash_key_fwd key + let hash ← hashmap.hash_key_fwd key let i := vec_len (hashmap_list_t T) self.hashmap_hash_map_slots let hash_mod ← hash % i let l ← vec_index_fwd (hashmap_list_t T) self.hashmap_hash_map_slots hash_mod - hashmap_hash_map_get_in_list_fwd T key l + hashmap.HashMap.get_in_list_fwd T key l /- [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list] -/ -divergent def hashmap_hash_map_get_mut_in_list_loop_fwd +divergent def hashmap.HashMap.get_mut_in_list_loop_fwd (T : Type) (ls : hashmap_list_t T) (key : Usize) : Result T := match ls with | hashmap_list_t.Cons ckey cvalue tl => if ckey = key then Result.ret cvalue - else hashmap_hash_map_get_mut_in_list_loop_fwd T tl key + else hashmap.HashMap.get_mut_in_list_loop_fwd T tl key | hashmap_list_t.Nil => Result.fail Error.panic /- [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list] -/ -def hashmap_hash_map_get_mut_in_list_fwd +def hashmap.HashMap.get_mut_in_list_fwd (T : Type) (ls : hashmap_list_t T) (key : Usize) : Result T := - hashmap_hash_map_get_mut_in_list_loop_fwd T ls key + hashmap.HashMap.get_mut_in_list_loop_fwd T ls key /- [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list] -/ -divergent def hashmap_hash_map_get_mut_in_list_loop_back +divergent def hashmap.HashMap.get_mut_in_list_loop_back (T : Type) (ls : hashmap_list_t T) (key : Usize) (ret0 : T) : Result (hashmap_list_t T) := @@ -333,47 +332,47 @@ divergent def hashmap_hash_map_get_mut_in_list_loop_back then Result.ret (hashmap_list_t.Cons ckey ret0 tl) else do - let tl0 ← hashmap_hash_map_get_mut_in_list_loop_back T tl key ret0 + let tl0 ← hashmap.HashMap.get_mut_in_list_loop_back T tl key ret0 Result.ret (hashmap_list_t.Cons ckey cvalue tl0) | hashmap_list_t.Nil => Result.fail Error.panic /- [hashmap_main::hashmap::HashMap::{0}::get_mut_in_list] -/ -def hashmap_hash_map_get_mut_in_list_back +def hashmap.HashMap.get_mut_in_list_back (T : Type) (ls : hashmap_list_t T) (key : Usize) (ret0 : T) : Result (hashmap_list_t T) := - hashmap_hash_map_get_mut_in_list_loop_back T ls key ret0 + hashmap.HashMap.get_mut_in_list_loop_back T ls key ret0 /- [hashmap_main::hashmap::HashMap::{0}::get_mut] -/ -def hashmap_hash_map_get_mut_fwd +def hashmap.HashMap.get_mut_fwd (T : Type) (self : hashmap_hash_map_t T) (key : Usize) : Result T := do - let hash ← hashmap_hash_key_fwd key + let hash ← hashmap.hash_key_fwd key let i := vec_len (hashmap_list_t T) self.hashmap_hash_map_slots let hash_mod ← hash % i let l ← vec_index_mut_fwd (hashmap_list_t T) self.hashmap_hash_map_slots hash_mod - hashmap_hash_map_get_mut_in_list_fwd T l key + hashmap.HashMap.get_mut_in_list_fwd T l key /- [hashmap_main::hashmap::HashMap::{0}::get_mut] -/ -def hashmap_hash_map_get_mut_back +def hashmap.HashMap.get_mut_back (T : Type) (self : hashmap_hash_map_t T) (key : Usize) (ret0 : T) : Result (hashmap_hash_map_t T) := do - let hash ← hashmap_hash_key_fwd key + let hash ← hashmap.hash_key_fwd key let i := vec_len (hashmap_list_t T) self.hashmap_hash_map_slots let hash_mod ← hash % i let l ← vec_index_mut_fwd (hashmap_list_t T) self.hashmap_hash_map_slots hash_mod - let l0 ← hashmap_hash_map_get_mut_in_list_back T l key ret0 + let l0 ← hashmap.HashMap.get_mut_in_list_back T l key ret0 let v ← vec_index_mut_back (hashmap_list_t T) self.hashmap_hash_map_slots hash_mod l0 Result.ret { self with hashmap_hash_map_slots := v } /- [hashmap_main::hashmap::HashMap::{0}::remove_from_list] -/ -divergent def hashmap_hash_map_remove_from_list_loop_fwd +divergent def hashmap.HashMap.remove_from_list_loop_fwd (T : Type) (key : Usize) (ls : hashmap_list_t T) : Result (Option T) := match ls with | hashmap_list_t.Cons ckey t tl => @@ -385,16 +384,16 @@ divergent def hashmap_hash_map_remove_from_list_loop_fwd match mv_ls with | hashmap_list_t.Cons i cvalue tl0 => Result.ret (Option.some cvalue) | hashmap_list_t.Nil => Result.fail Error.panic - else hashmap_hash_map_remove_from_list_loop_fwd T key tl + else hashmap.HashMap.remove_from_list_loop_fwd T key tl | hashmap_list_t.Nil => Result.ret Option.none /- [hashmap_main::hashmap::HashMap::{0}::remove_from_list] -/ -def hashmap_hash_map_remove_from_list_fwd +def hashmap.HashMap.remove_from_list_fwd (T : Type) (key : Usize) (ls : hashmap_list_t T) : Result (Option T) := - hashmap_hash_map_remove_from_list_loop_fwd T key ls + hashmap.HashMap.remove_from_list_loop_fwd T key ls /- [hashmap_main::hashmap::HashMap::{0}::remove_from_list] -/ -divergent def hashmap_hash_map_remove_from_list_loop_back +divergent def hashmap.HashMap.remove_from_list_loop_back (T : Type) (key : Usize) (ls : hashmap_list_t T) : Result (hashmap_list_t T) := @@ -410,27 +409,27 @@ divergent def hashmap_hash_map_remove_from_list_loop_back | hashmap_list_t.Nil => Result.fail Error.panic else do - let tl0 ← hashmap_hash_map_remove_from_list_loop_back T key tl + let tl0 ← hashmap.HashMap.remove_from_list_loop_back T key tl Result.ret (hashmap_list_t.Cons ckey t tl0) | hashmap_list_t.Nil => Result.ret hashmap_list_t.Nil /- [hashmap_main::hashmap::HashMap::{0}::remove_from_list] -/ -def hashmap_hash_map_remove_from_list_back +def hashmap.HashMap.remove_from_list_back (T : Type) (key : Usize) (ls : hashmap_list_t T) : Result (hashmap_list_t T) := - hashmap_hash_map_remove_from_list_loop_back T key ls + hashmap.HashMap.remove_from_list_loop_back T key ls /- [hashmap_main::hashmap::HashMap::{0}::remove] -/ -def hashmap_hash_map_remove_fwd +def hashmap.HashMap.remove_fwd (T : Type) (self : hashmap_hash_map_t T) (key : Usize) : Result (Option T) := do - let hash ← hashmap_hash_key_fwd key + let hash ← hashmap.hash_key_fwd key let i := vec_len (hashmap_list_t T) self.hashmap_hash_map_slots let hash_mod ← hash % i let l ← vec_index_mut_fwd (hashmap_list_t T) self.hashmap_hash_map_slots hash_mod - let x ← hashmap_hash_map_remove_from_list_fwd T key l + let x ← hashmap.HashMap.remove_from_list_fwd T key l match x with | Option.none => Result.ret Option.none | Option.some x0 => @@ -440,21 +439,21 @@ def hashmap_hash_map_remove_fwd Result.ret (Option.some x0) /- [hashmap_main::hashmap::HashMap::{0}::remove] -/ -def hashmap_hash_map_remove_back +def hashmap.HashMap.remove_back (T : Type) (self : hashmap_hash_map_t T) (key : Usize) : Result (hashmap_hash_map_t T) := do - let hash ← hashmap_hash_key_fwd key + let hash ← hashmap.hash_key_fwd key let i := vec_len (hashmap_list_t T) self.hashmap_hash_map_slots let hash_mod ← hash % i let l ← vec_index_mut_fwd (hashmap_list_t T) self.hashmap_hash_map_slots hash_mod - let x ← hashmap_hash_map_remove_from_list_fwd T key l + let x ← hashmap.HashMap.remove_from_list_fwd T key l match x with | Option.none => do - let l0 ← hashmap_hash_map_remove_from_list_back T key l + let l0 ← hashmap.HashMap.remove_from_list_back T key l let v ← vec_index_mut_back (hashmap_list_t T) self.hashmap_hash_map_slots hash_mod l0 @@ -463,7 +462,7 @@ def hashmap_hash_map_remove_back do let i0 ← self.hashmap_hash_map_num_entries - (Usize.ofInt 1 (by intlit)) - let l0 ← hashmap_hash_map_remove_from_list_back T key l + let l0 ← hashmap.HashMap.remove_from_list_back T key l let v ← vec_index_mut_back (hashmap_list_t T) self.hashmap_hash_map_slots hash_mod l0 @@ -475,38 +474,37 @@ def hashmap_hash_map_remove_back } /- [hashmap_main::hashmap::test1] -/ -def hashmap_test1_fwd : Result Unit := +def hashmap.test1_fwd : Result Unit := do - let hm ← hashmap_hash_map_new_fwd U64 + let hm ← hashmap.HashMap.new_fwd U64 let hm0 ← - hashmap_hash_map_insert_fwd_back U64 hm (Usize.ofInt 0 (by intlit)) + hashmap.HashMap.insert_fwd_back U64 hm (Usize.ofInt 0 (by intlit)) (U64.ofInt 42 (by intlit)) let hm1 ← - hashmap_hash_map_insert_fwd_back U64 hm0 (Usize.ofInt 128 (by intlit)) + hashmap.HashMap.insert_fwd_back U64 hm0 (Usize.ofInt 128 (by intlit)) (U64.ofInt 18 (by intlit)) let hm2 ← - hashmap_hash_map_insert_fwd_back U64 hm1 (Usize.ofInt 1024 (by intlit)) + hashmap.HashMap.insert_fwd_back U64 hm1 (Usize.ofInt 1024 (by intlit)) (U64.ofInt 138 (by intlit)) let hm3 ← - hashmap_hash_map_insert_fwd_back U64 hm2 (Usize.ofInt 1056 (by intlit)) + hashmap.HashMap.insert_fwd_back U64 hm2 (Usize.ofInt 1056 (by intlit)) (U64.ofInt 256 (by intlit)) - let i ← hashmap_hash_map_get_fwd U64 hm3 (Usize.ofInt 128 (by intlit)) + let i ← hashmap.HashMap.get_fwd U64 hm3 (Usize.ofInt 128 (by intlit)) if not (i = (U64.ofInt 18 (by intlit))) then Result.fail Error.panic else do let hm4 ← - hashmap_hash_map_get_mut_back U64 hm3 (Usize.ofInt 1024 (by intlit)) + hashmap.HashMap.get_mut_back U64 hm3 (Usize.ofInt 1024 (by intlit)) (U64.ofInt 56 (by intlit)) let i0 ← - hashmap_hash_map_get_fwd U64 hm4 (Usize.ofInt 1024 (by intlit)) + hashmap.HashMap.get_fwd U64 hm4 (Usize.ofInt 1024 (by intlit)) if not (i0 = (U64.ofInt 56 (by intlit))) then Result.fail Error.panic else do let x ← - hashmap_hash_map_remove_fwd U64 hm4 - (Usize.ofInt 1024 (by intlit)) + hashmap.HashMap.remove_fwd U64 hm4 (Usize.ofInt 1024 (by intlit)) match x with | Option.none => Result.fail Error.panic | Option.some x0 => @@ -515,39 +513,38 @@ def hashmap_test1_fwd : Result Unit := else do let hm5 ← - hashmap_hash_map_remove_back U64 hm4 + hashmap.HashMap.remove_back U64 hm4 (Usize.ofInt 1024 (by intlit)) let i1 ← - hashmap_hash_map_get_fwd U64 hm5 - (Usize.ofInt 0 (by intlit)) + hashmap.HashMap.get_fwd U64 hm5 (Usize.ofInt 0 (by intlit)) if not (i1 = (U64.ofInt 42 (by intlit))) then Result.fail Error.panic else do let i2 ← - hashmap_hash_map_get_fwd U64 hm5 + hashmap.HashMap.get_fwd U64 hm5 (Usize.ofInt 128 (by intlit)) if not (i2 = (U64.ofInt 18 (by intlit))) then Result.fail Error.panic else do let i3 ← - hashmap_hash_map_get_fwd U64 hm5 + hashmap.HashMap.get_fwd U64 hm5 (Usize.ofInt 1056 (by intlit)) if not (i3 = (U64.ofInt 256 (by intlit))) then Result.fail Error.panic else Result.ret () /- Unit test for [hashmap_main::hashmap::test1] -/ -#assert (hashmap_test1_fwd == .ret ()) +#assert (hashmap.test1_fwd == .ret ()) /- [hashmap_main::insert_on_disk] -/ def insert_on_disk_fwd (key : Usize) (value : U64) (st : State) : Result (State × Unit) := do - let (st0, hm) ← opaque_defs.hashmap_utils_deserialize_fwd st - let hm0 ← hashmap_hash_map_insert_fwd_back U64 hm key value - let (st1, _) ← opaque_defs.hashmap_utils_serialize_fwd hm0 st0 + let (st0, hm) ← hashmap_utils.deserialize_fwd st + let hm0 ← hashmap.HashMap.insert_fwd_back U64 hm key value + let (st1, _) ← hashmap_utils.serialize_fwd hm0 st0 Result.ret (st1, ()) /- [hashmap_main::main] -/ @@ -557,4 +554,4 @@ def main_fwd : Result Unit := /- Unit test for [hashmap_main::main] -/ #assert (main_fwd == .ret ()) -end HashmapMain +end hashmap_main diff --git a/tests/lean/HashmapMain/FunsExternal.lean b/tests/lean/HashmapMain/FunsExternal.lean new file mode 100644 index 00000000..d917b485 --- /dev/null +++ b/tests/lean/HashmapMain/FunsExternal.lean @@ -0,0 +1,17 @@ +-- [hashmap_main]: templates for the external functions. +import Base +import HashmapMain.Types +open Primitives +open hashmap_main + +-- TODO: fill those bodies + +/- [hashmap_main::hashmap_utils::deserialize] -/ +def hashmap_utils.deserialize_fwd + : State → Result (State × (hashmap_hash_map_t U64)) := + fun _ => .fail .panic + +/- [hashmap_main::hashmap_utils::serialize] -/ +def hashmap_utils.serialize_fwd + : hashmap_hash_map_t U64 → State → Result (State × Unit) := + fun _ _ => .fail .panic diff --git a/tests/lean/HashmapMain/FunsExternal_Template.lean b/tests/lean/HashmapMain/FunsExternal_Template.lean new file mode 100644 index 00000000..86286373 --- /dev/null +++ b/tests/lean/HashmapMain/FunsExternal_Template.lean @@ -0,0 +1,16 @@ +-- THIS FILE WAS AUTOMATICALLY GENERATED BY AENEAS +-- [hashmap_main]: external functions. +-- This is a template file: rename it to "FunsExternal.lean" and fill the holes. +import Base +import HashmapMain.Types +open Primitives +open hashmap_main + +/- [hashmap_main::hashmap_utils::deserialize] -/ +axiom hashmap_utils.deserialize_fwd + : State → Result (State × (hashmap_hash_map_t U64)) + +/- [hashmap_main::hashmap_utils::serialize] -/ +axiom hashmap_utils.serialize_fwd + : hashmap_hash_map_t U64 → State → Result (State × Unit) + diff --git a/tests/lean/HashmapMain/Opaque.lean b/tests/lean/HashmapMain/Opaque.lean index 10e4d8bd..abf04c94 100644 --- a/tests/lean/HashmapMain/Opaque.lean +++ b/tests/lean/HashmapMain/Opaque.lean @@ -4,16 +4,16 @@ import Base import HashmapMain.Types open Primitives -namespace HashmapMain +namespace hashmap_main structure OpaqueDefs where /- [hashmap_main::hashmap_utils::deserialize] -/ - hashmap_utils_deserialize_fwd + hashmap_utils.deserialize_fwd : State → Result (State × (hashmap_hash_map_t U64)) /- [hashmap_main::hashmap_utils::serialize] -/ - hashmap_utils_serialize_fwd + hashmap_utils.serialize_fwd : hashmap_hash_map_t U64 → State → Result (State × Unit) -end HashmapMain +end hashmap_main diff --git a/tests/lean/HashmapMain/Types.lean b/tests/lean/HashmapMain/Types.lean index b91ff3a7..16641146 100644 --- a/tests/lean/HashmapMain/Types.lean +++ b/tests/lean/HashmapMain/Types.lean @@ -2,8 +2,7 @@ -- [hashmap_main]: type definitions import Base open Primitives - -namespace HashmapMain +namespace hashmap_main /- [hashmap_main::hashmap::List] -/ inductive hashmap_list_t (T : Type) := @@ -20,4 +19,4 @@ structure hashmap_hash_map_t (T : Type) where /- The state type used in the state-error monad -/ axiom State : Type -end HashmapMain +end hashmap_main |