Skip to content

Commit 96de208

Browse files
committed
chore: remove some partial
1 parent 8a5febf commit 96de208

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

src/Std/Data/BinomialHeap.lean

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def singleton (a : α) : Heap α :=
5151

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

6870
@[specialize] def merge (le : α → α → Bool) : Heap α → Heap α → Heap α
6971
| heap h₁, heap h₂ => heap (mergeNodes le h₁ h₂)

src/Std/Data/HashMap.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ def contains [BEq α] [Hashable α] (m : HashMapImp α β) (a : α) : Bool :=
7676
let ⟨i, h⟩ := mkIdx buckets.property (hash a |>.toUSize)
7777
(buckets.val.uget i h).contains a
7878

79-
-- TODO: remove `partial` by using well-founded recursion
80-
partial def moveEntries [Hashable α] (i : Nat) (source : Array (AssocList α β)) (target : HashMapBucket α β) : HashMapBucket α β :=
79+
def moveEntries [Hashable α] (i : Nat) (source : Array (AssocList α β)) (target : HashMapBucket α β) : HashMapBucket α β :=
8180
if h : i < source.size then
8281
let idx : Fin source.size := ⟨i, h⟩
8382
let es : AssocList α β := source.get idx
@@ -86,6 +85,7 @@ partial def moveEntries [Hashable α] (i : Nat) (source : Array (AssocList α β
8685
let target := es.foldl (reinsertAux hash) target
8786
moveEntries (i+1) source target
8887
else target
88+
termination_by _ i source _ => source.size - i
8989

9090
def expand [Hashable α] (size : Nat) (buckets : HashMapBucket α β) : HashMapImp α β :=
9191
let nbuckets := buckets.val.size * 2

src/Std/Data/HashSet.lean

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,17 @@ def contains [BEq α] [Hashable α] (m : HashSetImp α) (a : α) : Bool :=
5858
let ⟨i, h⟩ := mkIdx buckets.property (hash a |>.toUSize)
5959
(buckets.val.uget i h).contains a
6060

61-
-- TODO: remove `partial` by using well-founded recursion
62-
partial def moveEntries [Hashable α] (i : Nat) (source : Array (List α)) (target : HashSetBucket α) : HashSetBucket α :=
61+
def moveEntries [Hashable α] (i : Nat) (source : Array (List α)) (target : HashSetBucket α) : HashSetBucket α :=
6362
if h : i < source.size then
6463
let idx : Fin source.size := ⟨i, h⟩
6564
let es : List α := source.get idx
6665
-- We remove `es` from `source` to make sure we can reuse its memory cells when performing es.foldl
6766
let source := source.set idx []
6867
let target := es.foldl (reinsertAux hash) target
6968
moveEntries (i+1) source target
70-
else target
69+
else
70+
target
71+
termination_by _ i source _ => source.size - i
7172

7273
def expand [Hashable α] (size : Nat) (buckets : HashSetBucket α) : HashSetImp α :=
7374
let nbuckets := buckets.val.size * 2

0 commit comments

Comments
 (0)