Rename 'merge' to 'union'
Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
This commit is contained in:
parent
d786e6bf48
commit
6039c1dfab
104
Map.agda
104
Map.agda
|
@ -116,8 +116,8 @@ private module ImplInsert (f : B → B → B) where
|
||||||
... | yes _ = (k' , f v v') ∷ xs
|
... | yes _ = (k' , f v v') ∷ xs
|
||||||
... | no _ = x ∷ insert k v xs
|
... | no _ = x ∷ insert k v xs
|
||||||
|
|
||||||
merge : List (A × B) → List (A × B) → List (A × B)
|
union : List (A × B) → List (A × B) → List (A × B)
|
||||||
merge m₁ m₂ = foldr insert m₂ m₁
|
union m₁ m₂ = foldr insert m₂ m₁
|
||||||
|
|
||||||
insert-keys-∈ : ∀ {k : A} {v : B} {l : List (A × B)} →
|
insert-keys-∈ : ∀ {k : A} {v : B} {l : List (A × B)} →
|
||||||
k ∈k l → keys l ≡ keys (insert k v l)
|
k ∈k l → keys l ≡ keys (insert k v l)
|
||||||
|
@ -146,11 +146,11 @@ private module ImplInsert (f : B → B → B) where
|
||||||
... | yes k∈kl rewrite insert-keys-∈ {v = v} k∈kl = u
|
... | yes k∈kl rewrite insert-keys-∈ {v = v} k∈kl = u
|
||||||
... | no k∉kl rewrite sym (insert-keys-∉ {v = v} k∉kl) = Unique-append k∉kl u
|
... | no k∉kl rewrite sym (insert-keys-∉ {v = v} k∉kl) = Unique-append k∉kl u
|
||||||
|
|
||||||
merge-preserves-Unique : ∀ (l₁ l₂ : List (A × B)) →
|
union-preserves-Unique : ∀ (l₁ l₂ : List (A × B)) →
|
||||||
Unique (keys l₂) → Unique (keys (merge l₁ l₂))
|
Unique (keys l₂) → Unique (keys (union l₁ l₂))
|
||||||
merge-preserves-Unique [] l₂ u₂ = u₂
|
union-preserves-Unique [] l₂ u₂ = u₂
|
||||||
merge-preserves-Unique ((k₁ , v₁) ∷ xs₁) l₂ u₂ =
|
union-preserves-Unique ((k₁ , v₁) ∷ xs₁) l₂ u₂ =
|
||||||
insert-preserves-Unique (merge-preserves-Unique xs₁ l₂ u₂)
|
insert-preserves-Unique (union-preserves-Unique xs₁ l₂ u₂)
|
||||||
|
|
||||||
insert-fresh : ∀ {k : A} {v : B} {l : List (A × B)} →
|
insert-fresh : ∀ {k : A} {v : B} {l : List (A × B)} →
|
||||||
¬ k ∈k l → (k , v) ∈ insert k v l
|
¬ k ∈k l → (k , v) ∈ insert k v l
|
||||||
|
@ -174,13 +174,13 @@ private module ImplInsert (f : B → B → B) where
|
||||||
... | no k'≢k'' | there k∈kxs = insert-preserves-∉k k≢k'
|
... | no k'≢k'' | there k∈kxs = insert-preserves-∉k k≢k'
|
||||||
(λ k∈kxs → k∉kl (there k∈kxs)) k∈kxs
|
(λ k∈kxs → k∉kl (there k∈kxs)) k∈kxs
|
||||||
|
|
||||||
merge-preserves-∉ : ∀ {k : A} {l₁ l₂ : List (A × B)} →
|
union-preserves-∉ : ∀ {k : A} {l₁ l₂ : List (A × B)} →
|
||||||
¬ k ∈k l₁ → ¬ k ∈k l₂ → ¬ k ∈k merge l₁ l₂
|
¬ k ∈k l₁ → ¬ k ∈k l₂ → ¬ k ∈k union l₁ l₂
|
||||||
merge-preserves-∉ {l₁ = []} _ k∉kl₂ = k∉kl₂
|
union-preserves-∉ {l₁ = []} _ k∉kl₂ = k∉kl₂
|
||||||
merge-preserves-∉ {k} {(k' , v') ∷ xs₁} k∉kl₁ k∉kl₂
|
union-preserves-∉ {k} {(k' , v') ∷ xs₁} k∉kl₁ k∉kl₂
|
||||||
with ≡-dec-A k k'
|
with ≡-dec-A k k'
|
||||||
... | yes k≡k' = absurd (k∉kl₁ (here k≡k'))
|
... | yes k≡k' = absurd (k∉kl₁ (here k≡k'))
|
||||||
... | no k≢k' = insert-preserves-∉k k≢k' (merge-preserves-∉ (λ k∈kxs₁ → k∉kl₁ (there k∈kxs₁)) k∉kl₂)
|
... | no k≢k' = insert-preserves-∉k k≢k' (union-preserves-∉ (λ k∈kxs₁ → k∉kl₁ (there k∈kxs₁)) k∉kl₂)
|
||||||
|
|
||||||
insert-preserves-∈ : ∀ {k k' : A} {v v' : B} {l : List (A × B)} →
|
insert-preserves-∈ : ∀ {k k' : A} {v v' : B} {l : List (A × B)} →
|
||||||
¬ k ≡ k' → (k , v) ∈ l → (k , v) ∈ insert k' v' l
|
¬ k ≡ k' → (k , v) ∈ l → (k , v) ∈ insert k' v' l
|
||||||
|
@ -199,27 +199,27 @@ private module ImplInsert (f : B → B → B) where
|
||||||
let (v , k,v∈l) = locate k∈kl
|
let (v , k,v∈l) = locate k∈kl
|
||||||
in ∈-cong proj₁ (insert-preserves-∈ k≢k' k,v∈l)
|
in ∈-cong proj₁ (insert-preserves-∈ k≢k' k,v∈l)
|
||||||
|
|
||||||
merge-preserves-∈₁ : ∀ {k : A} {v : B} {l₁ l₂ : List (A × B)} →
|
union-preserves-∈₁ : ∀ {k : A} {v : B} {l₁ l₂ : List (A × B)} →
|
||||||
¬ k ∈k l₁ → (k , v) ∈ l₂ → (k , v) ∈ merge l₁ l₂
|
¬ k ∈k l₁ → (k , v) ∈ l₂ → (k , v) ∈ union l₁ l₂
|
||||||
merge-preserves-∈₁ {l₁ = []} _ k,v∈l₂ = k,v∈l₂
|
union-preserves-∈₁ {l₁ = []} _ k,v∈l₂ = k,v∈l₂
|
||||||
merge-preserves-∈₁ {l₁ = (k' , v') ∷ xs₁} k∉kl₁ k,v∈l₂ =
|
union-preserves-∈₁ {l₁ = (k' , v') ∷ xs₁} k∉kl₁ k,v∈l₂ =
|
||||||
let recursion = merge-preserves-∈₁ (λ k∈xs₁ → k∉kl₁ (there k∈xs₁)) k,v∈l₂
|
let recursion = union-preserves-∈₁ (λ k∈xs₁ → k∉kl₁ (there k∈xs₁)) k,v∈l₂
|
||||||
in insert-preserves-∈ (λ k≡k' → k∉kl₁ (here k≡k')) recursion
|
in insert-preserves-∈ (λ k≡k' → k∉kl₁ (here k≡k')) recursion
|
||||||
|
|
||||||
merge-preserves-∈₂ : ∀ {k : A} {v : B} {l₁ l₂ : List (A × B)} →
|
union-preserves-∈₂ : ∀ {k : A} {v : B} {l₁ l₂ : List (A × B)} →
|
||||||
Unique (keys l₁) → (k , v) ∈ l₁ → ¬ k ∈k l₂ → (k , v) ∈ merge l₁ l₂
|
Unique (keys l₁) → (k , v) ∈ l₁ → ¬ k ∈k l₂ → (k , v) ∈ union l₁ l₂
|
||||||
merge-preserves-∈₂ {k} {v} {(k' , v') ∷ xs₁} (push k'≢xs₁ uxs₁) (there k,v∈xs₁) k∉kl₂ =
|
union-preserves-∈₂ {k} {v} {(k' , v') ∷ xs₁} (push k'≢xs₁ uxs₁) (there k,v∈xs₁) k∉kl₂ =
|
||||||
insert-preserves-∈ k≢k' k,v∈mxs₁l
|
insert-preserves-∈ k≢k' k,v∈mxs₁l
|
||||||
where
|
where
|
||||||
k,v∈mxs₁l = merge-preserves-∈₂ uxs₁ k,v∈xs₁ k∉kl₂
|
k,v∈mxs₁l = union-preserves-∈₂ uxs₁ k,v∈xs₁ k∉kl₂
|
||||||
|
|
||||||
k≢k' : ¬ k ≡ k'
|
k≢k' : ¬ k ≡ k'
|
||||||
k≢k' with ≡-dec-A k k'
|
k≢k' with ≡-dec-A k k'
|
||||||
... | yes k≡k' rewrite k≡k' = absurd (All¬-¬Any k'≢xs₁ (∈-cong proj₁ k,v∈xs₁))
|
... | yes k≡k' rewrite k≡k' = absurd (All¬-¬Any k'≢xs₁ (∈-cong proj₁ k,v∈xs₁))
|
||||||
... | no k≢k' = k≢k'
|
... | no k≢k' = k≢k'
|
||||||
merge-preserves-∈₂ {l₁ = (k' , v') ∷ xs₁} (push k'≢xs₁ uxs₁) (here k,v≡k',v') k∉kl₂
|
union-preserves-∈₂ {l₁ = (k' , v') ∷ xs₁} (push k'≢xs₁ uxs₁) (here k,v≡k',v') k∉kl₂
|
||||||
rewrite cong proj₁ k,v≡k',v' rewrite cong proj₂ k,v≡k',v' =
|
rewrite cong proj₁ k,v≡k',v' rewrite cong proj₂ k,v≡k',v' =
|
||||||
insert-fresh (merge-preserves-∉ (All¬-¬Any k'≢xs₁) k∉kl₂)
|
insert-fresh (union-preserves-∉ (All¬-¬Any k'≢xs₁) k∉kl₂)
|
||||||
|
|
||||||
insert-combines : ∀ {k : A} {v v' : B} {l : List (A × B)} →
|
insert-combines : ∀ {k : A} {v v' : B} {l : List (A × B)} →
|
||||||
Unique (keys l) → (k , v') ∈ l → (k , f v v') ∈ (insert k v l)
|
Unique (keys l) → (k , v') ∈ l → (k , f v v') ∈ (insert k v l)
|
||||||
|
@ -233,14 +233,14 @@ private module ImplInsert (f : B → B → B) where
|
||||||
... | yes k≡k' rewrite k≡k' = absurd (All¬-¬Any k'≢xs (∈-cong proj₁ k,v'∈xs))
|
... | yes k≡k' rewrite k≡k' = absurd (All¬-¬Any k'≢xs (∈-cong proj₁ k,v'∈xs))
|
||||||
... | no k≢k' = there (insert-combines uxs k,v'∈xs)
|
... | no k≢k' = there (insert-combines uxs k,v'∈xs)
|
||||||
|
|
||||||
merge-combines : ∀ {k : A} {v₁ v₂ : B} {l₁ l₂ : List (A × B)} →
|
union-combines : ∀ {k : A} {v₁ v₂ : B} {l₁ l₂ : List (A × B)} →
|
||||||
Unique (keys l₁) → Unique (keys l₂) →
|
Unique (keys l₁) → Unique (keys l₂) →
|
||||||
(k , v₁) ∈ l₁ → (k , v₂) ∈ l₂ → (k , f v₁ v₂) ∈ merge l₁ l₂
|
(k , v₁) ∈ l₁ → (k , v₂) ∈ l₂ → (k , f v₁ v₂) ∈ union l₁ l₂
|
||||||
merge-combines {l₁ = (k' , v) ∷ xs₁} {l₂} (push k'≢xs₁ uxs₁) ul₂ (here k,v₁≡k',v) k,v₂∈l₂
|
union-combines {l₁ = (k' , v) ∷ xs₁} {l₂} (push k'≢xs₁ uxs₁) ul₂ (here k,v₁≡k',v) k,v₂∈l₂
|
||||||
rewrite cong proj₁ (sym (k,v₁≡k',v)) rewrite cong proj₂ (sym (k,v₁≡k',v)) =
|
rewrite cong proj₁ (sym (k,v₁≡k',v)) rewrite cong proj₂ (sym (k,v₁≡k',v)) =
|
||||||
insert-combines (merge-preserves-Unique xs₁ l₂ ul₂) (merge-preserves-∈₁ (All¬-¬Any k'≢xs₁) k,v₂∈l₂)
|
insert-combines (union-preserves-Unique xs₁ l₂ ul₂) (union-preserves-∈₁ (All¬-¬Any k'≢xs₁) k,v₂∈l₂)
|
||||||
merge-combines {k} {l₁ = (k' , v) ∷ xs₁} (push k'≢xs₁ uxs₁) ul₂ (there k,v₁∈xs₁) k,v₂∈l₂ =
|
union-combines {k} {l₁ = (k' , v) ∷ xs₁} (push k'≢xs₁ uxs₁) ul₂ (there k,v₁∈xs₁) k,v₂∈l₂ =
|
||||||
insert-preserves-∈ k≢k' (merge-combines uxs₁ ul₂ k,v₁∈xs₁ k,v₂∈l₂)
|
insert-preserves-∈ k≢k' (union-combines uxs₁ ul₂ k,v₁∈xs₁ k,v₂∈l₂)
|
||||||
where
|
where
|
||||||
k≢k' : ¬ k ≡ k'
|
k≢k' : ¬ k ≡ k'
|
||||||
k≢k' with ≡-dec-A k k'
|
k≢k' with ≡-dec-A k k'
|
||||||
|
@ -268,40 +268,40 @@ data Provenance (k : A) (m₁ m₂ : Map) : Set (a ⊔ b) where
|
||||||
module _ (f : B → B → B) where
|
module _ (f : B → B → B) where
|
||||||
open ImplInsert f renaming
|
open ImplInsert f renaming
|
||||||
( insert to insert-impl
|
( insert to insert-impl
|
||||||
; merge to merge-impl
|
; union to union-impl
|
||||||
)
|
)
|
||||||
|
|
||||||
insert : A → B → Map → Map
|
insert : A → B → Map → Map
|
||||||
insert k v (kvs , uks) = (insert-impl k v kvs , insert-preserves-Unique uks)
|
insert k v (kvs , uks) = (insert-impl k v kvs , insert-preserves-Unique uks)
|
||||||
|
|
||||||
merge : Map → Map → Map
|
union : Map → Map → Map
|
||||||
merge (kvs₁ , _) (kvs₂ , uks₂) = (merge-impl kvs₁ kvs₂ , merge-preserves-Unique kvs₁ kvs₂ uks₂)
|
union (kvs₁ , _) (kvs₂ , uks₂) = (union-impl kvs₁ kvs₂ , union-preserves-Unique kvs₁ kvs₂ uks₂)
|
||||||
|
|
||||||
MergeResult : {k : A} {m₁ m₂ : Map} → Provenance k m₁ m₂ → Set (a ⊔ b)
|
MergeResult : {k : A} {m₁ m₂ : Map} → Provenance k m₁ m₂ → Set (a ⊔ b)
|
||||||
MergeResult {k} {m₁} {m₂} (both v₁ v₂ _ _) = (k , f v₁ v₂) ∈ merge m₁ m₂
|
MergeResult {k} {m₁} {m₂} (both v₁ v₂ _ _) = (k , f v₁ v₂) ∈ union m₁ m₂
|
||||||
MergeResult {k} {m₁} {m₂} (in₁ v₁ _ _) = (k , v₁) ∈ merge m₁ m₂
|
MergeResult {k} {m₁} {m₂} (in₁ v₁ _ _) = (k , v₁) ∈ union m₁ m₂
|
||||||
MergeResult {k} {m₁} {m₂} (in₂ v₂ _ _) = (k , v₂) ∈ merge m₁ m₂
|
MergeResult {k} {m₁} {m₂} (in₂ v₂ _ _) = (k , v₂) ∈ union m₁ m₂
|
||||||
|
|
||||||
merge-provenance : ∀ (m₁ m₂ : Map) (k : A) → k ∈k merge m₁ m₂ → Σ (Provenance k m₁ m₂) MergeResult
|
union-provenance : ∀ (m₁ m₂ : Map) (k : A) → k ∈k union m₁ m₂ → Σ (Provenance k m₁ m₂) MergeResult
|
||||||
merge-provenance m₁@(l₁ , u₁) m₂@(l₂ , u₂) k k∈km₁m₂
|
union-provenance m₁@(l₁ , u₁) m₂@(l₂ , u₂) k k∈km₁m₂
|
||||||
with ∈k-dec k l₁ | ∈k-dec k l₂
|
with ∈k-dec k l₁ | ∈k-dec k l₂
|
||||||
... | yes k∈kl₁ | yes k∈kl₂ =
|
... | yes k∈kl₁ | yes k∈kl₂ =
|
||||||
let
|
let
|
||||||
(v₁ , k,v₁∈l₁) = locate k∈kl₁
|
(v₁ , k,v₁∈l₁) = locate k∈kl₁
|
||||||
(v₂ , k,v₂∈l₂) = locate k∈kl₂
|
(v₂ , k,v₂∈l₂) = locate k∈kl₂
|
||||||
in
|
in
|
||||||
(both v₁ v₂ k,v₁∈l₁ k,v₂∈l₂ , merge-combines u₁ u₂ k,v₁∈l₁ k,v₂∈l₂)
|
(both v₁ v₂ k,v₁∈l₁ k,v₂∈l₂ , union-combines u₁ u₂ k,v₁∈l₁ k,v₂∈l₂)
|
||||||
... | yes k∈kl₁ | no k∉kl₂ =
|
... | yes k∈kl₁ | no k∉kl₂ =
|
||||||
let
|
let
|
||||||
(v₁ , k,v₁∈l₁) = locate k∈kl₁
|
(v₁ , k,v₁∈l₁) = locate k∈kl₁
|
||||||
in
|
in
|
||||||
(in₁ v₁ k,v₁∈l₁ k∉kl₂ , merge-preserves-∈₂ u₁ k,v₁∈l₁ k∉kl₂)
|
(in₁ v₁ k,v₁∈l₁ k∉kl₂ , union-preserves-∈₂ u₁ k,v₁∈l₁ k∉kl₂)
|
||||||
... | no k∉kl₁ | yes k∈kl₂ =
|
... | no k∉kl₁ | yes k∈kl₂ =
|
||||||
let
|
let
|
||||||
(v₂ , k,v₂∈l₂) = locate k∈kl₂
|
(v₂ , k,v₂∈l₂) = locate k∈kl₂
|
||||||
in
|
in
|
||||||
(in₂ v₂ k∉kl₁ k,v₂∈l₂ , merge-preserves-∈₁ k∉kl₁ k,v₂∈l₂)
|
(in₂ v₂ k∉kl₁ k,v₂∈l₂ , union-preserves-∈₁ k∉kl₁ k,v₂∈l₂)
|
||||||
... | no k∉kl₁ | no k∉kl₂ = absurd (merge-preserves-∉ k∉kl₁ k∉kl₂ k∈km₁m₂)
|
... | no k∉kl₁ | no k∉kl₂ = absurd (union-preserves-∉ k∉kl₁ k∉kl₂ k∈km₁m₂)
|
||||||
|
|
||||||
module _ (_≈_ : B → B → Set b) where
|
module _ (_≈_ : B → B → Set b) where
|
||||||
open ImplRelation _≈_ renaming (subset to subset-impl)
|
open ImplRelation _≈_ renaming (subset to subset-impl)
|
||||||
|
@ -314,19 +314,19 @@ module _ (_≈_ : B → B → Set b) where
|
||||||
|
|
||||||
module _ (f : B → B → B) where
|
module _ (f : B → B → B) where
|
||||||
module _ (f-comm : ∀ (b₁ b₂ : B) → f b₁ b₂ ≡ f b₂ b₁) where
|
module _ (f-comm : ∀ (b₁ b₂ : B) → f b₁ b₂ ≡ f b₂ b₁) where
|
||||||
merge-comm : ∀ (m₁ m₂ : Map) → lift (_≡_) (merge f m₁ m₂) (merge f m₂ m₁)
|
union-comm : ∀ (m₁ m₂ : Map) → lift (_≡_) (union f m₁ m₂) (union f m₂ m₁)
|
||||||
merge-comm m₁ m₂ = (merge-comm-subset m₁ m₂ , merge-comm-subset m₂ m₁)
|
union-comm m₁ m₂ = (union-comm-subset m₁ m₂ , union-comm-subset m₂ m₁)
|
||||||
where
|
where
|
||||||
merge-comm-subset : ∀ (m₁ m₂ : Map) → subset (_≡_) (merge f m₁ m₂) (merge f m₂ m₁)
|
union-comm-subset : ∀ (m₁ m₂ : Map) → subset (_≡_) (union f m₁ m₂) (union f m₂ m₁)
|
||||||
merge-comm-subset m₁@(l₁ , u₁) m₂@(l₂ , u₂) k v k,v∈m₁m₂
|
union-comm-subset m₁@(l₁ , u₁) m₂@(l₂ , u₂) k v k,v∈m₁m₂
|
||||||
with merge-provenance f m₁ m₂ k (∈-cong proj₁ k,v∈m₁m₂)
|
with union-provenance f m₁ m₂ k (∈-cong proj₁ k,v∈m₁m₂)
|
||||||
... | (both v₁ v₂ v₁∈m₁ v₂∈m₂ , v₁v₂∈m₁m₂)
|
... | (both v₁ v₂ v₁∈m₁ v₂∈m₂ , v₁v₂∈m₁m₂)
|
||||||
rewrite Map-functional {m = merge f m₁ m₂} k,v∈m₁m₂ v₁v₂∈m₁m₂ =
|
rewrite Map-functional {m = union f m₁ m₂} k,v∈m₁m₂ v₁v₂∈m₁m₂ =
|
||||||
(f v₂ v₁ , (f-comm v₁ v₂ , ImplInsert.merge-combines f u₂ u₁ v₂∈m₂ v₁∈m₁))
|
(f v₂ v₁ , (f-comm v₁ v₂ , ImplInsert.union-combines f u₂ u₁ v₂∈m₂ v₁∈m₁))
|
||||||
|
|
||||||
... | (in₁ v₁ v₁∈m₁ k∉km₂ , v₁∈m₁m₂)
|
... | (in₁ v₁ v₁∈m₁ k∉km₂ , v₁∈m₁m₂)
|
||||||
rewrite Map-functional {m = merge f m₁ m₂} k,v∈m₁m₂ v₁∈m₁m₂ =
|
rewrite Map-functional {m = union f m₁ m₂} k,v∈m₁m₂ v₁∈m₁m₂ =
|
||||||
(v₁ , (refl , ImplInsert.merge-preserves-∈₁ f k∉km₂ v₁∈m₁))
|
(v₁ , (refl , ImplInsert.union-preserves-∈₁ f k∉km₂ v₁∈m₁))
|
||||||
... | (in₂ v₂ k∉km₁ v₂∈m₂ , v₂∈m₁m₂)
|
... | (in₂ v₂ k∉km₁ v₂∈m₂ , v₂∈m₁m₂)
|
||||||
rewrite Map-functional {m = merge f m₁ m₂} k,v∈m₁m₂ v₂∈m₁m₂ =
|
rewrite Map-functional {m = union f m₁ m₂} k,v∈m₁m₂ v₂∈m₁m₂ =
|
||||||
(v₂ , (refl , ImplInsert.merge-preserves-∈₂ f u₂ v₂∈m₂ k∉km₁))
|
(v₂ , (refl , ImplInsert.union-preserves-∈₂ f u₂ v₂∈m₂ k∉km₁))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user