(***************************************)
(***************************************)
(* Constructions of last_key and fresh *)
(***************************************)
(***************************************)
Variable A : Type.
Implicit Type h : natmap A.
Definition last_key h := last 0 (dom h).
Definition fresh h := (last_key h).+1.

(* Specifications: *)
Lemma lastkey_undef : last_key um_undef = 0.
Lemma dom_lastkey0P h : last_key h = 0 <-> dom h = [::].
Lemma dom_lastkey h :  valid h -> ~~ empb h -> last_key h \in dom h.
Lemma dom_lastkeyE h a : a < last_key h -> last_key h \in dom h.
Lemma lastkey_max h x : x \in dom h -> x <= last_key h.
Lemma max_lastkey h x :
x \in dom h -> {in dom h, forall y, y <= x} -> last_key h = x.
Lemma lastkeyPt (x : nat) v : x != 0 -> last_key (x \-> v) = x.
Lemma lastkey_mono h1 h2 :
{subset dom h1 <= dom h2} -> last_key h1 <= last_key h2.
Lemma lastkeyUn0 h1 h2 :
valid (h1 \+ h2) ->
last_key h1 = last_key h2 -> (h1 = Unit) * (h2 = Unit).
Lemma lastkeyUn h1 h2 :
last_key (h1 \+ h2) =
if valid (h1 \+ h2) then maxn (last_key h1) (last_key h2) else 0.
Lemma lastkeyPtUn h t u :
valid h -> last_key h < t -> valid (t \-> u \+ h).