int-multimap (empty) → 0.1.0.1
raw patch · 4 files changed
+106/−0 lines, 4 filesdep +basedep +containersdep +hashablesetup-changed
Dependencies added: base, containers, hashable, unordered-containers
Files
- LICENSE +22/−0
- Setup.hs +2/−0
- int-multimap.cabal +49/−0
- library/IntMultiMap.hs +33/−0
+ LICENSE view
@@ -0,0 +1,22 @@+Copyright (c) 2018, Metrix.AI++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
+ int-multimap.cabal view
@@ -0,0 +1,49 @@+name:+ int-multimap+version:+ 0.1.0.1+synopsis:+ A data structure that associates each Int key with a set of values+category:+ Containers+homepage:+ https://github.com/metrix-ai/int-multimap+bug-reports:+ https://github.com/metrix-ai/int-multimap/issues+author:+ Oleg Shevchenko <shevchenko.cmc@gmail.com>+maintainer:+ Metrix.AI Ninjas <ninjas@metrix.ai>+copyright:+ (c) 2018, Metrix.AI+license:+ MIT+license-file:+ LICENSE+build-type:+ Simple+cabal-version:+ >=1.24++source-repository head+ type:+ git+ location:+ https://github.com/metrix-ai/int-multimap.git++library+ hs-source-dirs:+ library+ default-extensions:+ Arrows, BangPatterns, ConstraintKinds, DataKinds, DefaultSignatures, DeriveDataTypeable, DeriveFoldable, DeriveFunctor, DeriveGeneric, DeriveTraversable, EmptyDataDecls, FlexibleContexts, FlexibleInstances, FunctionalDependencies, GADTs, GeneralizedNewtypeDeriving, LambdaCase, LiberalTypeSynonyms, MagicHash, MultiParamTypeClasses, MultiWayIf, NoImplicitPrelude, NoMonomorphismRestriction, OverloadedStrings, PatternGuards, ParallelListComp, QuasiQuotes, RankNTypes, RecordWildCards, ScopedTypeVariables, StandaloneDeriving, TemplateHaskell, TupleSections, TypeFamilies, TypeOperators, UnboxedTuples, StrictData+ ghc-options: -funbox-strict-fields+ default-language:+ Haskell2010+ exposed-modules:+ IntMultiMap+ other-modules:+ build-depends:+ base >=4.7 && <5,+ hashable >=1.2 && <2,+ containers >=0.5.10 && <0.5.15,+ unordered-containers >=0.2.8.0 && <0.3
+ library/IntMultiMap.hs view
@@ -0,0 +1,33 @@+module IntMultiMap+ where++import qualified Data.IntMap.Strict as A+import qualified Data.HashSet as B+import Prelude+import Data.Int+import Data.Hashable+import Data.Foldable+import Control.Monad++{-|++-}+newtype IntMultiMap value =+ IntMultiMap (A.IntMap (B.HashSet value))+ deriving(Foldable)++delete :: (Hashable value, Eq value) => Int {-^ Key -} -> value -> IntMultiMap value -> IntMultiMap value+delete key value (IntMultiMap intMap) =+ IntMultiMap $ A.update f key intMap+ where+ f hashSet =+ mfilter (not . B.null) . Just $ B.delete value hashSet++insert :: (Hashable value, Ord value) => Int -> value -> IntMultiMap value -> IntMultiMap value+insert key value (IntMultiMap intMap) =+ IntMultiMap $ A.update (\hash -> Just $ B.insert value hash) key intMap++split :: Int -> IntMultiMap value -> (IntMultiMap value, IntMultiMap value)+split key (IntMultiMap intMap) = (IntMultiMap oldMap, IntMultiMap newMap)+ where+ (oldMap, newMap) = A.split key intMap