2022-09-28 23:04:00 +00:00
|
|
|
module Map where
|
|
|
|
|
|
|
|
-- not really used yet
|
|
|
|
|
2022-10-01 05:17:39 +00:00
|
|
|
open import Agda.Builtin.List
|
|
|
|
open import Agda.Builtin.Maybe
|
|
|
|
open import Agda.Builtin.Nat
|
|
|
|
open import Agda.Builtin.String
|
|
|
|
open import Data.Nat.Show
|
|
|
|
|
|
|
|
open import Show
|
|
|
|
open import Util
|
|
|
|
|
2022-09-28 04:12:48 +00:00
|
|
|
record Map (K V : Set) : Set where
|
|
|
|
constructor mapOf
|
|
|
|
field
|
|
|
|
keys : List K
|
|
|
|
values : List V
|
|
|
|
|
|
|
|
showMap : {V : Set} → (V → String) → Map String V → String
|
2022-10-01 05:17:39 +00:00
|
|
|
showMap f m = primStringAppend "map: " (showList ident (zip (Map.keys m) (map f (Map.values m))))
|
2022-09-28 04:12:48 +00:00
|
|
|
|
2022-10-01 05:17:39 +00:00
|
|
|
findMap : Map Nat Nat → Nat → Maybe Nat
|
|
|
|
findMap m k with findIndex 0 k (Map.keys m)
|
|
|
|
... | just n = takeIndex (Map.values m) n
|
|
|
|
... | nothing = nothing
|
2022-09-28 04:12:48 +00:00
|
|
|
|
|
|
|
showNatMap : Map String Nat → String
|
|
|
|
showNatMap m = showMap show m
|