uniqueness-periods-vector (empty) → 0.1.0.0
raw patch · 5 files changed
+105/−0 lines, 5 filesdep +basedep +vectorsetup-changed
Dependencies added: base, vector
Files
- ChangeLog.md +5/−0
- LICENSE +20/−0
- Setup.hs +2/−0
- String/Languages/UniquenessPeriods/Vector.hs +53/−0
- uniqueness-periods-vector.cabal +25/−0
+ ChangeLog.md view
@@ -0,0 +1,5 @@+# Revision history for uniqueness-periods-vector++## 0.1.0.0 -- 2020-08-30++* First version. Released on an unsuspecting world.
+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2020 OleksandrZhabenko++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ String/Languages/UniquenessPeriods/Vector.hs view
@@ -0,0 +1,53 @@+-- |+-- Module : String.Languages.UniquenessPeriods.Vector+-- Copyright : (c) OleksandrZhabenko 2020+-- License : MIT+-- Stability : Experimental+-- Maintainer : olexandr543@yahoo.com+--+-- Generalization of the uniqueness-periods and uniqueness-periods-general +-- packages functionality.+-- ++{-# LANGUAGE BangPatterns, FlexibleInstances, MultiParamTypeClasses #-}++module String.Languages.UniquenessPeriods.Vector where++import qualified Data.Vector as V++data UniquenessGeneral1 a b = UG1 a [b] (V.Vector b) | UG2 a [b] (V.Vector b) deriving Eq++class UniquenessGeneral a b where+ get :: a -> b++type UniquenessGeneral2 a = V.Vector ([Int], a) + +instance (Eq a) => UniquenessGeneral (UniquenessGeneral1 Bool a) (UniquenessGeneral2 a) where+ get (UG1 y whspss v) = uniquenessPeriodsVector1 y whspss v+ get (UG2 y whspss v) = uniquenessPeriodsVector2 y whspss v ++-- | List of 'Int' in the result is a list of indexes for the occurrences of the value of the @a@ (usually, @a@ is a sound representation or its duration). +-- The first 'Bool' argument defines whether to apply the filtering for not informative (possibly) \"whitespace symbols\" given as the +-- second argument list. The resulting 'V.Vector' is sorted in the order of the first occurrence of each of the @a@ (usually, @a@ is the sound +-- representation, or its duration, or some other its characteristics) in the given third argument.+uniquenessPeriodsVector1 :: Eq a => Bool -> [a] -> V.Vector a -> UniquenessGeneral2 a+uniquenessPeriodsVector1 y whspss v + | V.null v = V.empty+ | otherwise = let !v1 = V.force . V.indexed $ v in + let f !x = if V.null x then Nothing + else Just . (\(v2,v3) -> ((V.toList . V.map fst $ v2,snd . V.unsafeIndex v2 $ 0),v3)) . + V.partition (\(_,xs) -> xs == (snd . V.unsafeIndex x $ 0)) $ x in + V.force . (if y then V.filter (\(_,!zs) -> zs `notElem` whspss) else id) . V.unfoldr f $ v1 ++-- | List of 'Int' in the result is a list of distances between the consequential occurrences of the @a@ (usually, @a@ is a sound representation or its duration)+-- in the given 'V.Vector'. The first 'Bool' argument defines whether to apply the filtering for not informative+-- (possibly) \"whitespace symbols\" given as the second argument list. The resulting 'V.Vector' is sorted in the order of the first occurrence of each of +-- the @a@ (usually, @a@ is the sound representation or its duration, or some other its characteristics) in the given third argument.+uniquenessPeriodsVector2 :: Eq a => Bool -> [a] -> V.Vector a -> UniquenessGeneral2 a+uniquenessPeriodsVector2 y whspss v + | V.null v = V.empty+ | otherwise = let !v1 = V.force . V.indexed $ v in + let f !x = if V.null x then Nothing + else Just . (\(v2,v3) -> ((V.toList . (\v4 -> V.zipWith subtract v4 (V.unsafeSlice 1 (V.length v4 -1) v4)) . V.map fst $ v2,snd . + V.unsafeIndex v2 $ 0),v3)) . V.partition (\(_,xs) -> xs == (snd . V.unsafeIndex x $ 0)) $ x in + V.force . (if y then V.filter (\(ys,!zs) -> not (null ys) && zs `notElem` whspss) else id) . V.unfoldr f $ v1
+ uniqueness-periods-vector.cabal view
@@ -0,0 +1,25 @@+-- Initial uniqueness-periods-vector.cabal generated by cabal init. For+-- further documentation, see http://haskell.org/cabal/users-guide/++name: uniqueness-periods-vector+version: 0.1.0.0+synopsis: Generalization of the uniqueness-periods and uniqueness-periods-general packages functionality.+description: Generalization of the uniqueness-periods and uniqueness-periods-general packages functionality.+homepage: https://hackage.haskell.org/package/uniqueness-periods-vector+license: MIT+license-file: LICENSE+author: OleksandrZhabenko+maintainer: olexandr543@yahoo.com+copyright: Oleksandr Zhabenko+category: Language, Game, Math+build-type: Simple+extra-source-files: ChangeLog.md+cabal-version: >=1.10++library+ exposed-modules: String.Languages.UniquenessPeriods.Vector+ -- other-modules: String.Languages.UniquenessPeriods.Vector+ other-extensions: BangPatterns, FlexibleInstances, MultiParamTypeClasses+ build-depends: base >=4.7 && <4.15, vector >=0.11 && <0.14+ -- hs-source-dirs:+ default-language: Haskell2010