Skip to content

Commit

Permalink
Add missing functions to Plutarch.Core.List
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mueller committed Dec 16, 2024
1 parent 26cf63f commit a1aa459
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/plutarch-onchain-lib/lib/Plutarch/Core/List.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ module Plutarch.Core.List (
pbuiltinListLengthFast,
penforceNSpendRedeemers,
phasNSetBits,
pisUniqueSet,
phasNUniqueElements,
emptyByteArray
) where

import Plutarch (ClosedTerm, Config (NoTracing),
PType, S, Term, perror, pfix,
phoistAcyclic, plam, plet, pto,
type (:-->), (#$), (#))
import Plutarch.Bitwise (pcountSetBits)
import Plutarch.Bitwise (pcountSetBits, pwriteBits)
import Plutarch.Bool (PBool, PEq ((#==)),
PPartialOrd ((#<), (#<=)), pif,
pnot)
Expand Down Expand Up @@ -153,3 +155,13 @@ penforceNSpendRedeemers n rdmrs =
(pelimList (\x _ -> isNonSpend (pfstBuiltin # x)) (pconstant True) (ptail # redeemers))
perror
in isLastSpend # (pdropFast # (n - 1) # pto rdmrs)

pisUniqueSet :: Term s (PInteger :--> PBuiltinList PInteger :--> PBool)
pisUniqueSet = phoistAcyclic $ plam $ \n xs ->
let flagUniqueBits = pwriteBits # emptyByteArray # xs # pconstant [True]
in (pcountSetBits # flagUniqueBits #== (pbuiltinListLengthFast # n # xs))

phasNUniqueElements :: Term s (PInteger :--> PBuiltinList PInteger :--> PBool)
phasNUniqueElements = phoistAcyclic $ plam $ \n xs ->
let flagUniqueBits = pwriteBits # emptyByteArray # xs # pconstant [True]
in (pcountSetBits # flagUniqueBits #== n)

0 comments on commit a1aa459

Please sign in to comment.