| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Keys for AVL trees -- the original key type extended with a new |
| 5 |
-- minimum and maximum. |
| 6 |
------------------------------------------------------------------------ |
| 7 |
|
| 8 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 9 |
|
| 10 |
open import Relation.Binary.Bundles |
| 11 |
using (StrictTotalOrder; StrictPartialOrder) |
| 12 |
|
| 13 |
module Data.Tree.AVL.Key |
| 14 |
{a ℓ₁ ℓ₂} (sto : StrictTotalOrder a ℓ₁ ℓ₂) |
| 15 |
where |
| 16 |
|
| 17 |
open import Level using (Level; _⊔_) |
| 18 |
open import Data.Product.Base using (_×_; _,_) |
| 19 |
open import Relation.Binary.Definitions using (Reflexive) |
| 20 |
open import Relation.Binary.PropositionalEquality.Core using (_≡_ ; refl) |
| 21 |
open import Relation.Nullary.Negation.Core using (¬_) |
| 22 |
open import Relation.Nullary.Construct.Add.Extrema |
| 23 |
as AddExtremaToSet using (_±) |
| 24 |
import Relation.Binary.Construct.Add.Extrema.Equality |
| 25 |
as AddExtremaToEquality |
| 26 |
import Relation.Binary.Construct.Add.Extrema.Strict |
| 27 |
as AddExtremaToOrder |
| 28 |
|
| 29 |
open StrictTotalOrder sto renaming (Carrier to Key) |
| 30 |
using (_≈_; _<_; trans; irrefl; module Eq) |
| 31 |
|
| 32 |
------------------------------------------------------------------------ |
| 33 |
-- Keys are augmented with new extrema (i.e. an artificial minimum and |
| 34 |
-- maximum) |
| 35 |
|
| 36 |
Key⁺ : Set a |
| 37 |
Key⁺ = Key ± |
| 38 |
|
| 39 |
open AddExtremaToSet public |
| 40 |
using ([_]; [_]-injective) |
| 41 |
renaming |
| 42 |
( ⊥± to ⊥⁺ |
| 43 |
; ⊤± to ⊤⁺ |
| 44 |
) |
| 45 |
|
| 46 |
------------------------------------------------------------------------ |
| 47 |
-- The equality is extended in a corresponding manner |
| 48 |
|
| 49 |
open AddExtremaToEquality _≈_ public |
| 50 |
using () |
| 51 |
renaming |
| 52 |
( _≈±_ to _≈⁺_ |
| 53 |
; [_] to [_]ᴱ |
| 54 |
) |
| 55 |
|
| 56 |
------------------------------------------------------------------------ |
| 57 |
-- The order is extended in a corresponding manner |
| 58 |
|
| 59 |
open AddExtremaToOrder _<_ public |
| 60 |
using () renaming |
| 61 |
(_<±_ to _<⁺_ |
| 62 |
; [_] to [_]ᴿ |
| 63 |
; ⊥±<⊤± to ⊥⁺<⊤⁺ |
| 64 |
; [_]<⊤± to [_]<⊤⁺ |
| 65 |
; ⊥±<[_] to ⊥⁺<[_] |
| 66 |
) |
| 67 |
|
| 68 |
-- A pair of ordering constraints. |
| 69 |
|
| 70 |
infix 4 _<_<_ |
| 71 |
|
| 72 |
_<_<_ : Key⁺ → Key → Key⁺ → Set (a ⊔ ℓ₂) |
| 73 |
l < x < u = l <⁺ [ x ] × [ x ] <⁺ u |
| 74 |
|
| 75 |
-- Properties |
| 76 |
|
| 77 |
⊥⁺<[_]<⊤⁺ : ∀ k → ⊥⁺ < k < ⊤⁺ |
| 78 |
⊥⁺<[ k ]<⊤⁺ = ⊥⁺<[ k ] , [ k ]<⊤⁺ |
| 79 |
|
| 80 |
refl⁺ : Reflexive _≈⁺_ |
| 81 |
refl⁺ = AddExtremaToEquality.≈±-refl _≈_ Eq.refl |
| 82 |
|
| 83 |
sym⁺ : ∀ {l u} → l ≈⁺ u → u ≈⁺ l |
| 84 |
sym⁺ = AddExtremaToEquality.≈±-sym _≈_ Eq.sym |
| 85 |
|
| 86 |
trans⁺ : ∀ l {m u} → l <⁺ m → m <⁺ u → l <⁺ u |
| 87 |
trans⁺ l = AddExtremaToOrder.<±-trans _<_ trans |
| 88 |
|
| 89 |
irrefl⁺ : ∀ k → ¬ (k <⁺ k) |
| 90 |
irrefl⁺ k = AddExtremaToOrder.<±-irrefl _<_ irrefl refl⁺ |
| 91 |
|
| 92 |
-- Bundle |
| 93 |
|
| 94 |
strictPartialOrder : StrictPartialOrder _ _ _ |
| 95 |
strictPartialOrder = record |
| 96 |
{ isStrictPartialOrder = AddExtremaToOrder.<±-isStrictPartialOrder STO._<_ STO.isStrictPartialOrder |
| 97 |
} where module STO = StrictTotalOrder sto |
| 98 |
|
| 99 |
strictTotalOrder : StrictTotalOrder _ _ _ |
| 100 |
strictTotalOrder = record |
| 101 |
{ isStrictTotalOrder = AddExtremaToOrder.<±-isStrictTotalOrder STO._<_ STO.isStrictTotalOrder |
| 102 |
} where module STO = StrictTotalOrder sto |