chore: remove some partial

This commit is contained in:
Leonardo de Moura 2022-03-23 09:20:32 -07:00
parent 8a5febf130
commit 96de208a6b
3 changed files with 9 additions and 6 deletions

View file

@ -51,7 +51,7 @@ def singleton (a : α) : Heap α :=
-- Merge two forests of binomial trees. The forests are assumed to be ordered
-- by rank and `mergeNodes` maintains this invariant.
@[specialize] partial def mergeNodes (le : αα → Bool) : List (HeapNode α) → List (HeapNode α) → List (HeapNode α)
@[specialize] def mergeNodes (le : αα → Bool) : List (HeapNode α) → List (HeapNode α) → List (HeapNode α)
| [], h => h
| h, [] => h
| f@(h₁ :: t₁), s@(h₂ :: t₂) =>
@ -64,6 +64,8 @@ def singleton (a : α) : Heap α :=
if r != hRank t₂ then merged :: mergeNodes le t₁ t₂ else mergeNodes le (merged :: t₁) t₂
else
if r != hRank t₂ then mergeNodes le t₁ (merged :: t₂) else merged :: mergeNodes le t₁ t₂
termination_by _ h₁ h₂ => h₁.length + h₂.length
decreasing_by simp_wf; simp_arith [*]
@[specialize] def merge (le : αα → Bool) : Heap α → Heap α → Heap α
| heap h₁, heap h₂ => heap (mergeNodes le h₁ h₂)

View file

@ -76,8 +76,7 @@ def contains [BEq α] [Hashable α] (m : HashMapImp α β) (a : α) : Bool :=
let ⟨i, h⟩ := mkIdx buckets.property (hash a |>.toUSize)
(buckets.val.uget i h).contains a
-- TODO: remove `partial` by using well-founded recursion
partial def moveEntries [Hashable α] (i : Nat) (source : Array (AssocList α β)) (target : HashMapBucket α β) : HashMapBucket α β :=
def moveEntries [Hashable α] (i : Nat) (source : Array (AssocList α β)) (target : HashMapBucket α β) : HashMapBucket α β :=
if h : i < source.size then
let idx : Fin source.size := ⟨i, h⟩
let es : AssocList α β := source.get idx
@ -86,6 +85,7 @@ partial def moveEntries [Hashable α] (i : Nat) (source : Array (AssocList α β
let target := es.foldl (reinsertAux hash) target
moveEntries (i+1) source target
else target
termination_by _ i source _ => source.size - i
def expand [Hashable α] (size : Nat) (buckets : HashMapBucket α β) : HashMapImp α β :=
let nbuckets := buckets.val.size * 2

View file

@ -58,8 +58,7 @@ def contains [BEq α] [Hashable α] (m : HashSetImp α) (a : α) : Bool :=
let ⟨i, h⟩ := mkIdx buckets.property (hash a |>.toUSize)
(buckets.val.uget i h).contains a
-- TODO: remove `partial` by using well-founded recursion
partial def moveEntries [Hashable α] (i : Nat) (source : Array (List α)) (target : HashSetBucket α) : HashSetBucket α :=
def moveEntries [Hashable α] (i : Nat) (source : Array (List α)) (target : HashSetBucket α) : HashSetBucket α :=
if h : i < source.size then
let idx : Fin source.size := ⟨i, h⟩
let es : List α := source.get idx
@ -67,7 +66,9 @@ partial def moveEntries [Hashable α] (i : Nat) (source : Array (List α)) (targ
let source := source.set idx []
let target := es.foldl (reinsertAux hash) target
moveEntries (i+1) source target
else target
else
target
termination_by _ i source _ => source.size - i
def expand [Hashable α] (size : Nat) (buckets : HashSetBucket α) : HashSetImp α :=
let nbuckets := buckets.val.size * 2