Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Tourney.Common
Description
Common types and functions
Synopsis
- type PlayerCount = Int
- newtype Player = Player Int
- newtype Slot = Slot Int
- fromSlot :: Slot -> Int
- newtype RoundNo = RoundNo Int
- data Standings
- createInitialStandings :: PlayerCount -> Standings
- modifyStandings :: Standings -> (forall s. MVector s Player -> ST s ()) -> Standings
- vectorToStandings :: Vector v Player => v Player -> Standings
- asInt :: Coercible a Int => a -> Int
- (..<) :: (Enum a, Num a) => a -> a -> [a]
- (..>) :: (Enum a, Num a) => a -> a -> [a]
- data SortMethod
- data Sorter = Sorter {
- sorterFocus :: !Focus
- sorterMethod :: !SortMethod
- data Focus = Focus {
- focusStart :: !Slot
- focusLength :: !Int
- focusEnd :: Focus -> Slot
- focusWithin :: Focus -> Focus -> Bool
- focusContains :: Focus -> Slot -> Bool
- stride2 :: Int -> OrdPair Int
- nearestPow2Above :: Coercible Int a => a -> a
- bitLog2 :: Coercible Int a => a -> a
- isqrt :: Coercible Int a => a -> a
- triangular :: Coercible Int a => a -> a
Types
Type-safe wrappers around numeric types
This prevents mixing up two different ideas, namely Slot
and Player
, due
to their representations being the same.
type PlayerCount = Int Source #
The basic type for a player is an Int
denoting the "nth" best player in
the tournament at the outset of it. A Player
is the data that gets sorted
by the sorting networks constructed by tournaments.
Instances
A slot denotes an index into a round of a tournament, which a Player
occupies.
Instances
Round number
Instances
Standings
A mapping from slots to players
Instances
Show Standings Source # | |
Ixed Standings Source # | |
Defined in Tourney.Common | |
(AsRound a r, r ~ ()) => AsRound (Standings -> a) r Source # | |
(AsSteps a r, r ~ ()) => AsSteps (Standings -> a) r Source # | |
type Index Standings Source # | |
Defined in Tourney.Common | |
type IxValue Standings Source # | |
Defined in Tourney.Common |
Conversions
Ranges
(..<) :: (Enum a, Num a) => a -> a -> [a] infix 5 Source #
Create an increasing [closed, open) interval of slots
(..>) :: (Enum a, Num a) => a -> a -> [a] infix 5 Source #
Create a decreasing [closed, open) interval of slots
Sort methods
data SortMethod Source #
Constructors
WinnerTakesHigh | |
PointsAward | Award points and use that to sort the results in the end |
Instances
Show SortMethod Source # | |
Defined in Tourney.Common | |
Default SortMethod Source # | |
Defined in Tourney.Common Methods def :: SortMethod Source # | |
Eq SortMethod Source # | |
Defined in Tourney.Common Methods (==) :: SortMethod -> SortMethod -> Bool Source # (/=) :: SortMethod -> SortMethod -> Bool Source # | |
Ord SortMethod Source # | |
Defined in Tourney.Common Methods compare :: SortMethod -> SortMethod -> Ordering Source # (<) :: SortMethod -> SortMethod -> Bool Source # (<=) :: SortMethod -> SortMethod -> Bool Source # (>) :: SortMethod -> SortMethod -> Bool Source # (>=) :: SortMethod -> SortMethod -> Bool Source # max :: SortMethod -> SortMethod -> SortMethod Source # min :: SortMethod -> SortMethod -> SortMethod Source # |
Constructors
Sorter | |
Fields
|
Instances
Generic Sorter Source # | |
Show Sorter Source # | |
Eq Sorter Source # | |
type Rep Sorter Source # | |
Defined in Tourney.Common type Rep Sorter = D1 ('MetaData "Sorter" "Tourney.Common" "journeyman-0.1.0.0-inplace" 'False) (C1 ('MetaCons "Sorter" 'PrefixI 'True) (S1 ('MetaSel ('Just "sorterFocus") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Focus) :*: S1 ('MetaSel ('Just "sorterMethod") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 SortMethod))) |
Focus
The focus of a tournament over a sorting network. A good intuition is that
a Focus
is basically an array slice over a round.
Constructors
Focus | |
Fields
|
Instances
Generic Focus Source # | |
Show Focus Source # | |
Eq Focus Source # | |
Ord Focus Source # | |
Defined in Tourney.Common | |
type Rep Focus Source # | |
Defined in Tourney.Common type Rep Focus = D1 ('MetaData "Focus" "Tourney.Common" "journeyman-0.1.0.0-inplace" 'False) (C1 ('MetaCons "Focus" 'PrefixI 'True) (S1 ('MetaSel ('Just "focusStart") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Slot) :*: S1 ('MetaSel ('Just "focusLength") 'NoSourceUnpackedness 'SourceStrict 'DecidedStrict) (Rec0 Int))) |
Arithmetic functions
Where appropriate these are overloaded to work with types that have the
same representation as Int
, such as Player
, Slot
, and RoundNo
.
nearestPow2Above :: Coercible Int a => a -> a Source #
Round to the nearest power of 2 above the input
triangular :: Coercible Int a => a -> a Source #
Generate the N-th triangular number