summaryrefslogtreecommitdiff
path: root/Common
diff options
context:
space:
mode:
authorAndreas Grois <andi@grois.info>2024-01-10 21:01:38 +0100
committerAndreas Grois <andi@grois.info>2024-01-10 21:01:38 +0100
commit6627e81d169ed73a3f714cceedcd10ae58b26803 (patch)
treec2c730b6da2aa9135a66da17de67865c232d86d2 /Common
parent80e1def1496699497b5babf05e8db7cc73288e32 (diff)
Implement actual BinaryHeap.insert function.
Diffstat (limited to 'Common')
-rw-r--r--Common/BinaryHeap.lean6
1 files changed, 6 insertions, 0 deletions
diff --git a/Common/BinaryHeap.lean b/Common/BinaryHeap.lean
index 5f08b43..c2f1901 100644
--- a/Common/BinaryHeap.lean
+++ b/Common/BinaryHeap.lean
@@ -344,6 +344,12 @@ theorem BalancedTree.heapInsertIsHeap {elem : α} {heap : BalancedTree α o} {lt
case inr.zero => contradiction
case inr.succ => simp[h₈]
+def BinaryHeap.insert {α : Type u} {lt : α → α → Bool} {n : Nat} : α → BinaryHeap α lt n → BinaryHeap α lt (n+1)
+| elem, BinaryHeap.mk tree valid wellDefinedLt =>
+ let valid := tree.heapInsertIsHeap valid wellDefinedLt
+ let tree := tree.heapInsert lt elem
+ {tree, valid, wellDefinedLt}
+
/--Helper function for BalancedTree.indexOf.-/
def BalancedTree.indexOfAux {α : Type u} [BEq α] (elem : α) (heap : BalancedTree α o) (currentIndex : Nat) : Option (Fin (o+currentIndex)) :=
match o, heap with