cardano-data-1.2.3.1: Specialized data for Cardano project
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.OMap.Strict

Synopsis

Documentation

class Ord k ⇒ HasOKey k v | v → k where Source #

Class of types that can be mapped by a lens or a projection to an Ord type.

For a type V, defines a lens from V to and Ord type K.

Methods

okeyLLens' v k Source #

data OMap k v where Source #

A general-purpose finite, insert-ordered, map that is strict in its keys and values.

The strictness is enforced by the underlying strict Map that can be looked-up by a projection or lens. and the ordering is maintained by the constructing functions, leveraging StrictSeq to hold the insert-order of the keys.

TODO: DecShareCBOR instance

Bundled Patterns

pattern EmptyOMap k v

\(O(1)\)

pattern (:<|:) ∷ (HasOKey k v, Ord k) ⇒ v → OMap k v → OMap k v infixr 5

\(O(\log n)\).

pattern (:|>:) ∷ (HasOKey k v, Ord k) ⇒ OMap k v → v → OMap k v infixl 5

\(O(\log n)\).

Instances

Instances details
Ord k ⇒ Foldable (OMap k) Source # 
Instance details

Defined in Data.OMap.Strict

Methods

foldMonoid m ⇒ OMap k m → m Source #

foldMapMonoid m ⇒ (a → m) → OMap k a → m Source #

foldMap'Monoid m ⇒ (a → m) → OMap k a → m Source #

foldr ∷ (a → b → b) → b → OMap k a → b Source #

foldr' ∷ (a → b → b) → b → OMap k a → b Source #

foldl ∷ (b → a → b) → b → OMap k a → b Source #

foldl' ∷ (b → a → b) → b → OMap k a → b Source #

foldr1 ∷ (a → a → a) → OMap k a → a Source #

foldl1 ∷ (a → a → a) → OMap k a → a Source #

toListOMap k a → [a] Source #

nullOMap k a → Bool Source #

lengthOMap k a → Int Source #

elemEq a ⇒ a → OMap k a → Bool Source #

maximumOrd a ⇒ OMap k a → a Source #

minimumOrd a ⇒ OMap k a → a Source #

sumNum a ⇒ OMap k a → a Source #

productNum a ⇒ OMap k a → a Source #

(HasOKey k v, ToJSON v) ⇒ ToJSON (OMap k v) Source # 
Instance details

Defined in Data.OMap.Strict

Methods

toJSONOMap k v → Value Source #

toEncodingOMap k v → Encoding Source #

toJSONList ∷ [OMap k v] → Value Source #

toEncodingList ∷ [OMap k v] → Encoding Source #

omitFieldOMap k v → Bool Source #

HasOKey k v ⇒ Monoid (OMap k v) Source # 
Instance details

Defined in Data.OMap.Strict

Methods

memptyOMap k v Source #

mappendOMap k v → OMap k v → OMap k v Source #

mconcat ∷ [OMap k v] → OMap k v Source #

HasOKey k v ⇒ Semigroup (OMap k v) Source # 
Instance details

Defined in Data.OMap.Strict

Methods

(<>)OMap k v → OMap k v → OMap k v Source #

sconcatNonEmpty (OMap k v) → OMap k v Source #

stimesIntegral b ⇒ b → OMap k v → OMap k v Source #

HasOKey k v ⇒ IsList (OMap k v) Source # 
Instance details

Defined in Data.OMap.Strict

Associated Types

type Item (OMap k v) Source #

Methods

fromList ∷ [Item (OMap k v)] → OMap k v Source #

fromListNInt → [Item (OMap k v)] → OMap k v Source #

toListOMap k v → [Item (OMap k v)] Source #

Generic (OMap k v) Source # 
Instance details

Defined in Data.OMap.Strict

Associated Types

type Rep (OMap k v) ∷ TypeType Source #

Methods

fromOMap k v → Rep (OMap k v) x Source #

toRep (OMap k v) x → OMap k v Source #

(Show v, Ord k, Show k) ⇒ Show (OMap k v) Source # 
Instance details

Defined in Data.OMap.Strict

Methods

showsPrecIntOMap k v → ShowS Source #

showOMap k v → String Source #

showList ∷ [OMap k v] → ShowS Source #

(Typeable k, HasOKey k v, DecCBOR v, Eq v) ⇒ DecCBOR (OMap k v) Source # 
Instance details

Defined in Data.OMap.Strict

Methods

decCBORDecoder s (OMap k v) Source #

dropCBORProxy (OMap k v) → Decoder s () Source #

labelProxy (OMap k v) → Text Source #

(Typeable k, EncCBOR v, Ord k) ⇒ EncCBOR (OMap k v) Source # 
Instance details

Defined in Data.OMap.Strict

Methods

encCBOROMap k v → Encoding Source #

encodedSizeExpr ∷ (∀ t. EncCBOR t ⇒ Proxy t → Size) → Proxy (OMap k v) → Size Source #

encodedListSizeExpr ∷ (∀ t. EncCBOR t ⇒ Proxy t → Size) → Proxy [OMap k v] → Size Source #

Default (OMap k v) Source # 
Instance details

Defined in Data.OMap.Strict

Methods

defOMap k v Source #

(NFData k, NFData v) ⇒ NFData (OMap k v) Source # 
Instance details

Defined in Data.OMap.Strict

Methods

rnfOMap k v → () Source #

(Eq k, Eq v) ⇒ Eq (OMap k v) Source # 
Instance details

Defined in Data.OMap.Strict

Methods

(==)OMap k v → OMap k v → Bool Source #

(/=)OMap k v → OMap k v → Bool Source #

(NoThunks k, NoThunks v) ⇒ NoThunks (OMap k v) Source # 
Instance details

Defined in Data.OMap.Strict

type Item (OMap k v) Source # 
Instance details

Defined in Data.OMap.Strict

type Item (OMap k v) = v
type Rep (OMap k v) Source # 
Instance details

Defined in Data.OMap.Strict

type Rep (OMap k v) = D1 ('MetaData "OMap" "Data.OMap.Strict" "cardano-data-1.2.3.1-inplace" 'False) (C1 ('MetaCons "OMap" 'PrefixI 'True) (S1 ('MetaSel ('Just "omSSeq") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (StrictSeq k)) :*: S1 ('MetaSel ('Just "omMap") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 (Map k v))))

nullOMap k v → Bool Source #

\(O(1)\).

sizeOMap k v → Int Source #

\(O(1)\).

emptyOMap k v Source #

\(O(1)\).

singletonHasOKey k v ⇒ v → OMap k v Source #

\(O(1)\). Strict in its arguments.

lookupOrd k ⇒ k → OMap k v → Maybe v Source #

\(O(\log n)\). If the key is not present lookup returns Nothing.

memberOrd k ⇒ k → OMap k v → Bool Source #

\(O(\log n)\). Key membership check.

(!?)Ord k ⇒ OMap k v → k → Maybe v Source #

fliped version of lookup

mapUnsafe ∷ (v1 → v2) → OMap k v1 → OMap k v2 Source #

This mapping function is only safe when the key stored in the new value matches the key stored in the new value. This invariant is not checked for performance reasons

fromSetHasOKey k v ⇒ Set v → OMap k v Source #

\(O(n \log n)\).

fromFoldable ∷ (Foldable f, HasOKey k v) ⇒ f v → OMap k v Source #

\(O(n \log n)\). Checks membership before snoc'ing. De-duplicates the StrictSeq without overwriting. Starts from the left or head, using foldl`

fromFoldableDuplicates ∷ (Foldable f, HasOKey k v, Ord v) ⇒ f v → (Set v, OMap k v) Source #

\(O(n \log n)\). Checks membership before snoc'ing. De-duplicates the StrictSeq and collects and returns the duplicates found. Starts from the left or head, using foldl`

toMapOMap k v → Map k v Source #

\(O(1)\).

assocListOrd k ⇒ OMap k v → [(k, v)] Source #

elemsOrd k ⇒ OMap k v → [v] Source #

toStrictSeqOrd k ⇒ OMap k v → StrictSeq v Source #

\(O(n \log n)\).

toStrictSeqOKeysOMap k v → StrictSeq k Source #

\(O(1)\).

toStrictSeqOfPairsOrd k ⇒ OMap k v → StrictSeq (k, v) Source #

\(O(n \log n)\).

invariantHoldsOMap k v → Bool Source #

\(O(1)\). Shallow invariant using just length and size.

invariantHolds'Ord k ⇒ OMap k v → Bool Source #

\(O(n \log n)\). Deep, costly invariant using membership check for each value. By the pigeon-hole principle, this check is exhaustive.

(|>)HasOKey k v ⇒ OMap k v → v → OMap k v infixl 5 Source #

\(O(\log n)\). Checks membership before snoc'ing.

(<|)HasOKey k v ⇒ v → OMap k v → OMap k v infixr 5 Source #

\(O(\log n)\). Checks membership before cons'ing.

(<||)HasOKey k v ⇒ v → OMap k v → OMap k v infixr 5 Source #

\(O(\log n)\). Checks membership before cons'ing. Overwrites a duplicate.

(||>)HasOKey k v ⇒ OMap k v → v → OMap k v infixl 5 Source #

\(O(\log n)\). Checks membership before snoc'ing. Overwrites a duplicate.

(|><)HasOKey k v ⇒ OMap k v → OMap k v → OMap k v infixl 5 Source #

\( O(n \log m) \). For every uncons-ed element from the sequence on the right, check its membership in the sequence on the left, before snoc'ing it. Preserve order. Remove duplicates from sequence on the right.

(><|)HasOKey k v ⇒ OMap k v → OMap k v → OMap k v infixr 5 Source #

\( O(m \log n) \). For every unsnoc-ed element from the sequence on the left, check its membership in the sequence on the right, before cons'ing it. Preserve order. Remove duplicates from sequence on the left.

elem ∷ (HasOKey k v, Eq v) ⇒ v → OMap k v → Bool Source #

\(O(\log n)\). Value membership check.

extractKeysOrd k ⇒ Set k → OMap k v → (OMap k v, Map k v) Source #

\(O(n)\). Given a Set of ks, and an OMap k v return a pair of Map and OMap where the ks in the Set have been removed from the OMap and presented as a separate Map.

adjustHasOKey k v ⇒ (v → v) → k → OMap k v → OMap k v Source #

\(O(n)\). Like adjust.

Returns the original OMap unaltered when the key does not exist.

If the key exists, then the function is applied to the value, but we need to consider three possible cases:

  1. The modified value's okeyL is unaltered - we return omap with the adjusted value,
  2. The modified value's okeyL is altered, but not a duplicate - we return the omap with adjusted key (in place) and value
  3. The modified value's okeyL is altered and is a duplicate - we return the omap with the old key deleted from the sequence but without inserting the new key since it is a duplicate, and deleting old value and inserting the new value in place of its duplicate.

Examples:

>>> import Data.OMap.Strict
>>> import Lens.Micro
>>> instance HasOKey Int (Int, Char) where okeyL = _1
>>> let m = fromFoldable $ zip [1,2] ['a','b'] :: OMap Int (Int, Char)
>>> m
StrictSeq {fromStrict = fromList [(1,(1,'a')),(2,(2,'b'))]}
>>> let adjustingFn (k, v) = (k, succ v) -- Changes the value
>>> let overwritingAdjustingFn (k,v) = (succ k, v) -- Changes the `okeyL`.
>>> adjust adjustingFn 1 m
StrictSeq {fromStrict = fromList [(1,(1,'b')),(2,(2,'b'))]}
>>> adjust overwritingAdjustingFn  1 m
StrictSeq {fromStrict = fromList [(2,(2,'a'))]}

filterOrd k ⇒ (v → Bool) → OMap k v → OMap k v Source #

\( O(n \log n) \)