packages feed

sdp4unordered (empty) → 0.2

raw patch · 6 files changed

+357/−0 lines, 6 filesdep +basedep +sdpdep +sdp-hashablesetup-changed

Dependencies added: base, sdp, sdp-hashable, unordered-containers

Files

+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Andrey Mulik (c) 2020++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Andrey Mulik nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ sdp4unordered.cabal view
@@ -0,0 +1,50 @@+name:          sdp4unordered+version:       0.2+category:      Data Structures++synopsis:      SDP classes for unordered containers+description:   Implementation of SDP core classes for unordered containers++author:        Andrey Mulik+maintainer:    work.a.mulik@gmail.com+bug-reports:   https://github.com/andreymulik/sdp4unordered/issues++copyright:     2020 Andrey Mulik+license-file:  LICENSE+license:       BSD3++build-type:    Simple+cabal-version: >=1.10++source-repository head+  type: git+  location: https://github.com/andreymulik/sdp4unordered++---            _      _____ ______ ______   ___  ______ __   __              ---+---           | |    |_   _|| ___ \| ___ \ / _ \ | ___ \\ \ / /              ---+---           | |      | |  | |_/ /| |_/ // /_\ \| |_/ / \ V /               ---+---           | |      | |  | ___ \|    / |  _  ||    /   \ /                ---+---           | |____ _| |_ | |_/ /| |\ \ | | | || |\ \   | |                ---+---           \_____/ \___/ \____/ \_| \_|\_| |_/\_| \_|  \_/                ---++Library+  default-language: Haskell2010+  hs-source-dirs:   src+  +  build-depends:+    base                 >= 4.12 && < 5,+    sdp                  >= 0.2  && < 1,+    sdp-hashable         >= 0.2  && < 1,+    unordered-containers >= 0.2 && < 0.3+  +  ghc-options: -Wall -Wno-orphans -Wcompat+  +  exposed-modules:+    SDP.HashMap.Strict+    SDP.HashMap.Lazy+    SDP.HashSet+++++
+ src/SDP/HashMap/Lazy.hs view
@@ -0,0 +1,90 @@+{-# LANGUAGE Safe, MultiParamTypeClasses, FlexibleInstances #-}++{- |+    Module      :  SDP.HashMap.Lazy+    Copyright   :  (c) Andrey Mulik 2020+    License     :  BSD-style+    Maintainer  :  work.a.mulik@gmail.com+    Portability :  portable+  +    @SDP.HashMap.Lazy@ provides 'HashMap' - lazy unordered associative array+    with 'Hashable' keys.+-}+module SDP.HashMap.Lazy+(+  -- * Exports+  module SDP.Hashable,+  module SDP.Linear,+  module SDP.Map,+  +  -- * Hash map+  HashMap, LHashMap+)+where++import Prelude ()+import SDP.SafePrelude+import SDP.Hashable+import SDP.Linear+import SDP.Map++import qualified Data.HashMap.Lazy as H+import Data.HashMap.Lazy ( HashMap )++import Data.Maybe++import Control.Exception.SDP++default ()++--------------------------------------------------------------------------------++-- | 'HashMap' alias, may reduce ambiguity.+type LHashMap = HashMap++--------------------------------------------------------------------------------++instance Nullable (HashMap k e)+  where+    isNull = null+    lzero  = H.empty++instance (Index k) => Estimate (HashMap k e)+  where+    (<==>) = on (<=>) length+    (.<=.) = on (<=)  length+    (.>=.) = on (>=)  length+    (.>.)  = on (>)   length+    (.<.)  = on (<)   length+    +    (<.=>) = (<=>) . length+    (.>=)  = (>=)  . length+    (.<=)  = (<=)  . length+    (.>)   = (>)   . length+    (.<)   = (<)   . length++instance (Eq k, Hashable k) => Map (HashMap k e) k e+  where+    toMap' = const toMap+    toMap  = H.fromList+    assocs = H.toList+    +    kfoldl  = H.foldlWithKey' . flip+    kfoldr  = H.foldrWithKey+    +    filter' = H.filterWithKey+    member' = H.member+    insert' = H.insert+    delete' = H.delete+    +    -- | Throws 'IndexException' instead 'error' call.+    (!)  = fromMaybe (undEx "(!) {HashMap k e}") ... (!?)+    (//) = toMap ... (++) . assocs+    (!?) = flip H.lookup+    keys = H.keys++--------------------------------------------------------------------------------++undEx :: String -> a+undEx =  throw . UndefinedValue . showString "in SDP.HashMap.Lazy."+
+ src/SDP/HashMap/Strict.hs view
@@ -0,0 +1,90 @@+{-# LANGUAGE Safe, MultiParamTypeClasses, FlexibleInstances #-}++{- |+    Module      :  SDP.HashMap.Strict+    Copyright   :  (c) Andrey Mulik 2020+    License     :  BSD-style+    Maintainer  :  work.a.mulik@gmail.com+    Portability :  portable+  +    @SDP.HashMap.Strict@ provides 'HashMap' - strict unordered associative array+    with 'Hashable' keys.+-}+module SDP.HashMap.Strict+(+  -- * Exports+  module SDP.Hashable,+  module SDP.Linear,+  module SDP.Map,+  +  -- * Hash map+  HashMap, SHashMap+)+where++import Prelude ()+import SDP.SafePrelude+import SDP.Hashable+import SDP.Linear+import SDP.Map++import qualified Data.HashMap.Strict as H+import Data.HashMap.Strict ( HashMap )++import Data.Maybe++import Control.Exception.SDP++default ()++--------------------------------------------------------------------------------++-- | 'HashMap' alias, may reduce ambiguity.+type SHashMap = HashMap++--------------------------------------------------------------------------------++instance Nullable (HashMap k e)+  where+    isNull = null+    lzero  = H.empty++instance (Index k) => Estimate (HashMap k e)+  where+    (<==>) = on (<=>) length+    (.<=.) = on (<=)  length+    (.>=.) = on (>=)  length+    (.>.)  = on (>)   length+    (.<.)  = on (<)   length+    +    (<.=>) = (<=>) . length+    (.>=)  = (>=)  . length+    (.<=)  = (<=)  . length+    (.>)   = (>)   . length+    (.<)   = (<)   . length++instance (Eq k, Hashable k) => Map (HashMap k e) k e+  where+    toMap' = const toMap+    toMap  = H.fromList+    assocs = H.toList+    +    kfoldl  = H.foldlWithKey' . flip+    kfoldr  = H.foldrWithKey+    +    filter' = H.filterWithKey+    member' = H.member+    insert' = H.insert+    delete' = H.delete+    +    -- | Throws 'IndexException' instead 'error' call.+    (!)  = fromMaybe (undEx "(!) {HashMap k e}") ... (!?)+    (//) = toMap ... (++) . assocs+    (!?) = flip H.lookup+    keys = H.keys++--------------------------------------------------------------------------------++undEx :: String -> a+undEx =  throw . UndefinedValue . showString "in SDP.HashMap.Strict."+
+ src/SDP/HashSet.hs view
@@ -0,0 +1,95 @@+{-# LANGUAGE Safe, MultiParamTypeClasses, FlexibleInstances #-}++{- |+    Module      :  SDP.HashSet+    Copyright   :  (c) Andrey Mulik 2020+    License     :  BSD-style+    Maintainer  :  work.a.mulik@gmail.com+    Portability :  portable+  +    @SDP.HashSet@ provides 'HashSet' - unordered set with 'Hashable' keys.+-}+module SDP.HashSet+(+  -- * Exports+  module SDP.Hashable,+  module SDP.Linear,+  module SDP.Set,+  +  -- * Hash set+  HashSet+)+where++import Prelude ()+import SDP.SafePrelude+import SDP.Hashable+import SDP.Linear+import SDP.Set++import qualified Data.HashSet as H+import Data.HashSet ( HashSet )++default ()++--------------------------------------------------------------------------------++{- Nullable, Estimate and Bordered instances. -}++instance Nullable (HashSet e)+  where+    isNull = null+    lzero  = H.empty++instance Estimate (HashSet e)+  where+    (<==>) = on (<=>) sizeOf+    (.<=.) = on (<=)  sizeOf+    (.>=.) = on (>=)  sizeOf+    (.>.)  = on (>)   sizeOf+    (.<.)  = on (<)   sizeOf+    +    (<.=>) = (<=>) . sizeOf+    (.>=)  = (>=)  . sizeOf+    (.<=)  = (<=)  . sizeOf+    (.>)   = (>)   . sizeOf+    (.<)   = (<)   . sizeOf++instance Bordered (HashSet e) Int+  where+    sizeOf = length+    +    upper xs = length xs - 1+    lower  _ = 0++--------------------------------------------------------------------------------++instance (Eq e, Hashable e) => Set (HashSet e) e+  where+    set    = id -- always correct+    member = H.member+    insert = H.insert+    delete = H.delete+    +    unions        = foldr1 (\/)+    symdiffs      = foldr1 (\^/)+    differences   = foldr1 (/\)+    intersections = foldr1 (\\)+    +    (/\) = H.intersection+    (\\) = H.difference+    (\/) = H.union+    +    xs \^/ ys = (xs \/ ys) \\ (xs /\ ys)+    xs \+/ ys = isNull (ys \\ xs)+    xs /?\ ys = isNull (xs /\ ys)+    xs \?/ ys = not (xs /?\ ys)+    +    lookupLT e = lookupLT e . H.toList+    lookupGT e = lookupGT e . H.toList+    lookupLE e = lookupLE e . H.toList+    lookupGE e = lookupGE e . H.toList++++