cardano-ledger-binary-1.3.2.0: Binary serialization library used throughout ledger
Safe HaskellSafe-Inferred
LanguageHaskell2010

Cardano.Ledger.Binary.Decoding.Sharing

Synopsis

Documentation

class Monoid (Share a) ⇒ DecShareCBOR a where Source #

Minimal complete definition

(decShareCBOR | decSharePlusCBOR)

Associated Types

type Share a ∷ Type Source #

type Share a = ()

Methods

getShare ∷ a → Share a Source #

Whenever fromShareCBOR is being used for defining the instance this function should return the state that can be added whenever user invokes decSharePlusCBOR. mempty is returned by default.

decShareCBORShare a → Decoder s a Source #

Utilize sharing when decoding, but do not add anything to the state for future sharing.

decSharePlusCBORStateT (Share a) (Decoder s) a Source #

Deserialize with sharing and add to the state that is used for sharing. Default implementation will add value returned by getShare for adding to the state.

Instances

Instances details
(Ord k, DecCBOR k, DecCBOR v) ⇒ DecShareCBOR (Map k v) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.Sharing

Associated Types

type Share (Map k v) Source #

Methods

getShareMap k v → Share (Map k v) Source #

decShareCBORShare (Map k v) → Decoder s (Map k v) Source #

decSharePlusCBORStateT (Share (Map k v)) (Decoder s) (Map k v) Source #

(Ord k, DecCBOR k, DecCBOR v) ⇒ DecShareCBOR (VMap VB VB k v) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.Sharing

Associated Types

type Share (VMap VB VB k v) Source #

Methods

getShareVMap VB VB k v → Share (VMap VB VB k v) Source #

decShareCBORShare (VMap VB VB k v) → Decoder s (VMap VB VB k v) Source #

decSharePlusCBORStateT (Share (VMap VB VB k v)) (Decoder s) (VMap VB VB k v) Source #

(Ord k, DecCBOR k, DecCBOR v, Prim v) ⇒ DecShareCBOR (VMap VB VP k v) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.Sharing

Associated Types

type Share (VMap VB VP k v) Source #

Methods

getShareVMap VB VP k v → Share (VMap VB VP k v) Source #

decShareCBORShare (VMap VB VP k v) → Decoder s (VMap VB VP k v) Source #

decSharePlusCBORStateT (Share (VMap VB VP k v)) (Decoder s) (VMap VB VP k v) Source #

newtype Interns a Source #

Constructors

Interns [Intern a] 

Instances

Instances details
Monoid (Interns a) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.Sharing

Methods

memptyInterns a Source #

mappendInterns a → Interns a → Interns a Source #

mconcat ∷ [Interns a] → Interns a Source #

Semigroup (Interns a) Source # 
Instance details

Defined in Cardano.Ledger.Binary.Decoding.Sharing

Methods

(<>)Interns a → Interns a → Interns a Source #

sconcatNonEmpty (Interns a) → Interns a Source #

stimesIntegral b ⇒ b → Interns a → Interns a Source #

data Intern a Source #

This is an abstract interface that does the interning. In other words it does the actual sharing by looking up the supplied value in some existing data structure and uses that value instead. Relying on this interface gives us the benefit of ignoring the type of underlying data structure and allows us to compose many Interns with the monoidal interface provided by Interns wrapper. In order to create an Intern see the internsFromMap or internsFromVMap functions.

Constructors

Intern 

Fields

  • internMaybe ∷ a → Maybe a

    Function that will do the interning. If value is not available then Nothing is returned.

  • internWeight ∷ !Int

    Used for sorting. Normally set to the size of the underlying data structure. Keeping interns sorted with respect to how many elements is in the underlying data structure in theory gives a better chance of successful intern hit sooner rather than later.

decSharePlusLensCBORDecShareCBOR b ⇒ Lens' bs (Share b) → StateT bs (Decoder s) b Source #

Just like decSharePlusCBOR, except allows to transform the shared state with a lens.

decNoShareCBORDecShareCBOR a ⇒ Decoder s a Source #

Use DecShareCBOR class while ignoring sharing

internsInterns k → k → k Source #

internsFromMapOrd k ⇒ Map k a → Interns k Source #

internsFromVMapOrd k ⇒ VMap VB kv k a → Interns k Source #

toMemptyLensMonoid a ⇒ Lens' a b → Lens' c b → Lens' c a Source #

Using this function it is possible to compose two lenses. One will extract a value and another will used it for placing it into a empty monoid. Here is an example of how a second element of a tuple can be projected on the third element of a 3-tuple.

toMemptyLens _3 _2 == lens (\(_, b) -> (mempty, mempty, b)) (\(a, _) (_, _, b) -> (a, b))

Here is an example where we extract a second element of a tuple and insert it at third position of a three tuple while all other elements are set to mempty:

>>> import Lens.Micro
>>> ("foo","bar") ^. toMemptyLens _3 _2 :: (Maybe String, (), String)
(Nothing,(),"bar")

In the opposite direction of extracting the third element of a 3-tuple and replacing the second element of the tuple the setter is being applied to

>>> ("foo","bar") & toMemptyLens _3 _2 .~ (Just "baz", (), "booyah") :: (String, String)
("foo","booyah")

decShareMonadCBOR ∷ (DecCBOR (f b), Monad f) ⇒ Interns b → Decoder s (f b) Source #

Share every item in a functor, have deserializing it