Zora 1.1.15 → 1.1.16
raw patch · 3 files changed
+15/−12 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Zora.List: elem_counts_by :: Ord b => (a -> b) -> [a] -> [(a, Integer)]
Files
- Zora.cabal +2/−2
- Zora/List.hs +10/−0
- Zora/Math.hs +3/−10
Zora.cabal view
@@ -1,5 +1,5 @@ Name: Zora-Version: 1.1.15+Version: 1.1.16 Synopsis: Graphing library wrapper + assorted useful functions Description: A library of assorted useful functions for working with lists, doing mathematical operations and graphing custom data types. Category: Unclassified@@ -8,7 +8,7 @@ License-File: LICENSE Stability: Experimental Author: Brett Wines-Maintainer: brettwines@gmail.com+Maintainer: bgwines@cs.stanford.edu Homepage: http://github.com/bgwines/zora Build-Type: Simple Source-Repository head
Zora/List.hs view
@@ -62,6 +62,7 @@ , bsearch , bsearch_1st_geq , elem_counts+, elem_counts_by , running_bests , running_bests_by , (<$*>)@@ -501,6 +502,15 @@ = map (\l -> (head l, length' l)) . List.group . List.sort++-- | /O(nlog(n))/ Counts the number of time each element appears in the given list. For example:+--+-- > elem_counts [1,2,1,4] == [(1,2),(2,1),(4,1)]+elem_counts_by :: (Ord b) => (a -> b) -> [a] -> [(a, Integer)]+elem_counts_by cmp+ = map (\l -> (head l, length' l))+ . List.groupBy (\a b -> cmp a == cmp b)+ . List.sortBy (Ord.comparing cmp) -- | Shorthand for applying the same parameter twice. --
Zora/Math.hs view
@@ -128,16 +128,9 @@ d :: Integer d = (n - 1) `div` (2^s) -prime_rec :: Integer -> Integer -> Bool-prime_rec n k- | (n <= 1) = False- | (fromInteger k >= ((fromInteger n) / 2) + 1.0) = True- | ((n `mod` k) == 0) = False- | otherwise = prime_rec n (k+1)---- | /O(n)/ Returns whether the parameter is a prime number.+-- | /O(k n log(n)^-1)/, where /k/ is the number of primes dividing /n/ (double-counting for powers). /n log(n)^-1/ is an approximation for <http://en.wikipedia.org/wiki/Prime-counting_function the number of primes below a number>. Returns whether the parameter is a prime number. prime :: Integer -> Bool-prime n = prime_rec n 2+prime n = (factor n) == [n] -- | /O(min(n, m))/ Returns whether the the two parameters are <http://en.wikipedia.org/wiki/Coprime coprime>, that is, whether they share any divisors. coprime :: Integer -> Integer -> Bool@@ -218,7 +211,7 @@ factors_to_divisors :: [(Integer, Integer)] -> [Integer] factors_to_divisors- = init+ = (\l -> if l == [] then [] else init l) . List.sort . map product . map (map (\(p, a) -> p^a))