Commit e7e22466 authored by Peter Achten's avatar Peter Achten

made naming convention consistent (only add 'By' in case of hof-versions)

parent 0ee632f0
Pipeline #42463 failed with stage
in 1 minute and 4 seconds
...@@ -6,9 +6,13 @@ definition module Data.SetBy ...@@ -6,9 +6,13 @@ definition module Data.SetBy
* This version is the same as Data.Set, except that the overloaded API is replaced * This version is the same as Data.Set, except that the overloaded API is replaced
* with a higher-order function API. * with a higher-order function API.
* *
* The naming convention is to add 'By' to a function or macro name that is overloaded
* in Data.Set but uses a higher-order function argument in Data.SetBy.
*
* For all documentation, please consult Data.Set. * For all documentation, please consult Data.Set.
* *
* The `morally equivalent` function from Data.Set is added in the comment. * The `morally equivalent` function from Data.Set is added in the comment. This is not
* strictly equivalent function because of the different types.
* *
* When using the functions in Data.SetBy, make sure to use the same higher-order * When using the functions in Data.SetBy, make sure to use the same higher-order
* function parameter for the same data structure to ensure internal integrity. * function parameter for the same data structure to ensure internal integrity.
...@@ -67,7 +71,7 @@ instance Foldable SetBy ...@@ -67,7 +71,7 @@ instance Foldable SetBy
* @property equivalence with size 0: A.s :: SetBy a: * @property equivalence with size 0: A.s :: SetBy a:
* size s == 0 <==> null s * size s == 0 <==> null s
* @property equivalence with newSet: A.s :: SetBy a: * @property equivalence with newSet: A.s :: SetBy a:
* s == newSetBy <==> null s * s == newSet <==> null s
*/ */
null s :== case s of null s :== case s of
TipBy -> True TipBy -> True
...@@ -116,15 +120,15 @@ isProperSubsetOfBy comp s1 s2 :== (size s1 < size s2) && (isSubsetOfBy comp s1 s ...@@ -116,15 +120,15 @@ isProperSubsetOfBy comp s1 s2 :== (size s1 < size s2) && (isSubsetOfBy comp s1 s
* The empty set. * The empty set.
* @complexity O(1) * @complexity O(1)
* @property is null: * @property is null:
* null newSetBy * null newSet
*/ */
newSetBy :: SetBy a newSet :: SetBy a
/** /**
* Create a singleton set. * Create a singleton set.
* @complexity O(1) * @complexity O(1)
*/ */
singletonBy :: !u:a -> w:(SetBy u:a), [w <= u] singleton :: !u:a -> w:(SetBy u:a), [w <= u]
/** /**
* Insert an element in a set. If the set already contains an element equal to * Insert an element in a set. If the set already contains an element equal to
...@@ -205,7 +209,7 @@ unionBy :: !(a a -> Bool) !u:(SetBy a) !u:(SetBy a) -> SetBy a ...@@ -205,7 +209,7 @@ unionBy :: !(a a -> Bool) !u:(SetBy a) !u:(SetBy a) -> SetBy a
* *
* Morally equivalent function: Data.Set.unions ts = Data.SetBy.unionsBy (<) ts * Morally equivalent function: Data.Set.unions ts = Data.SetBy.unionsBy (<) ts
*/ */
unionsBy ts :== foldl unionBy newSetBy ts unionsBy ts :== foldl unionBy newSet ts
/** /**
* Difference of two sets. * Difference of two sets.
......
...@@ -8,7 +8,10 @@ from Data.Foldable import class Foldable (..) ...@@ -8,7 +8,10 @@ from Data.Foldable import class Foldable (..)
import qualified StdList import qualified StdList
from StdList import instance == [a] from StdList import instance == [a]
// PA: this is a dangerous function... shouldn't be part of the API /*
* This function should only be used if the argument function preserves the ordering property of
* the new set.
*/
mapSetByMonotonic :: !(a -> b) !(SetBy a) -> SetBy b mapSetByMonotonic :: !(a -> b) !(SetBy a) -> SetBy b
mapSetByMonotonic _ TipBy = TipBy mapSetByMonotonic _ TipBy = TipBy
mapSetByMonotonic f (BinBy n x l r) = BinBy n (f x) (mapSetByMonotonic f l) (mapSetByMonotonic f r) mapSetByMonotonic f (BinBy n x l r) = BinBy n (f x) (mapSetByMonotonic f l) (mapSetByMonotonic f r)
...@@ -75,11 +78,11 @@ memberBy _ _ _ = False ...@@ -75,11 +78,11 @@ memberBy _ _ _ = False
* Construction * Construction
*--------------------------------------------------------------------*/ *--------------------------------------------------------------------*/
newSetBy :: SetBy a newSet :: SetBy a
newSetBy = TipBy newSet = TipBy
singletonBy :: !u:a -> w:(SetBy u:a), [w <= u] singleton :: !u:a -> w:(SetBy u:a), [w <= u]
singletonBy x = BinBy 1 x TipBy TipBy singleton x = BinBy 1 x TipBy TipBy
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
* Insertion, Deletion * Insertion, Deletion
...@@ -90,7 +93,7 @@ insertBy comp x t=:(BinBy _ y l r) ...@@ -90,7 +93,7 @@ insertBy comp x t=:(BinBy _ y l r)
| comp x y = balanceL y (insertBy comp x l) r | comp x y = balanceL y (insertBy comp x l) r
| comp y x = balanceR y l (insertBy comp x r) | comp y x = balanceR y l (insertBy comp x r)
| otherwise = t | otherwise = t
insertBy _ x _ = singletonBy x insertBy _ x _ = singleton x
deleteBy :: !(a a -> Bool) !a !.(SetBy a) -> SetBy a deleteBy :: !(a a -> Bool) !a !.(SetBy a) -> SetBy a
deleteBy comp x (BinBy _ y l r) deleteBy comp x (BinBy _ y l r)
...@@ -221,7 +224,7 @@ partition _ t = (t, t) ...@@ -221,7 +224,7 @@ partition _ t = (t, t)
*--------------------------------------------------------------------*/ *--------------------------------------------------------------------*/
fromListBy :: !(a a -> Bool) ![a] -> SetBy a fromListBy :: !(a a -> Bool) ![a] -> SetBy a
fromListBy comp xs = 'StdList'.foldl (ins comp) newSetBy xs fromListBy comp xs = 'StdList'.foldl (ins comp) newSet xs
where where
ins :: !(a a -> Bool) !(SetBy a) !a -> SetBy a ins :: !(a a -> Bool) !(SetBy a) !a -> SetBy a
ins comp t x = insertBy comp x t ins comp t x = insertBy comp x t
...@@ -333,11 +336,11 @@ link x l _ = insertMax x l ...@@ -333,11 +336,11 @@ link x l _ = insertMax x l
// insertMin and insertMax don't perform potentially expensive comparisons. // insertMin and insertMax don't perform potentially expensive comparisons.
insertMax :: !a !(SetBy a) -> SetBy a insertMax :: !a !(SetBy a) -> SetBy a
insertMax x (BinBy _ y l r) = balanceR y l (insertMax x r) insertMax x (BinBy _ y l r) = balanceR y l (insertMax x r)
insertMax x _ = singletonBy x insertMax x _ = singleton x
insertMin :: !a !(SetBy a) -> SetBy a insertMin :: !a !(SetBy a) -> SetBy a
insertMin x (BinBy _ y l r) = balanceL y (insertMin x l) r insertMin x (BinBy _ y l r) = balanceL y (insertMin x l) r
insertMin x _ = singletonBy x insertMin x _ = singleton x
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
* [merge l r]: merges two trees. * [merge l r]: merges two trees.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment