Weight-balanced priority search pennants (based on Adams's weight-balanced trees).
> data PSQ k p = Void | Winner k p (LTree k p) k |
> maxKey :: PSQ k p -> k |
Smart constructors.
> start :: LTree k p |
Balance factor.
> omega :: Int |
> lbalance, rbalance :: (Ord k, Ord p) => k -> p -> LTree k p -> k -> LTree k p -> LTree k p |
> lbalanceLeft k p l m r |
> lsingleLeft k1 p1 t1 m1 (LLoser _ k2 p2 t2 m2 t3) |
> ldoubleLeft k1 p1 t1 m1 (LLoser _ k2 p2 t2 m2 t3) |
> play :: (Ord k, Ord p) => PSQ k p -> PSQ k p -> PSQ k p |
Note that this is the only place where lbalance and rbalance are used.
> unsafePlay :: (Ord k, Ord p) => PSQ k p -> PSQ k p -> PSQ k p |
The unsafe function unsafePlay can be used instead of play if we know that the shape of the tree has not changed or if the tree is known to be balanced.
Tournament view.
> data TourView k p = Null | Single k p | PSQ k p `Play` PSQ k p |
> empty = Void |
> minView Void = Empty |
Determining the second-best player.
> secondBest :: (Ord k, Ord p) => LTree k p -> k -> PSQ k p |
> lookup k q = case tourView q of |
> atMostRanges :: (Ord k, Ord p) => p -> (k, k) -> PSQ k p -> Sequ (Binding k p) |
> adjust f k q = case tourView q of |