{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE TypeFamilies #-}

module Data.VMap (
  VG.Vector,
  VB,
  VU,
  VP,
  VS,
  VMap (..),
  empty,
  size,
  lookup,
  findWithDefault,
  member,
  notMember,
  map,
  mapMaybe,
  mapWithKey,
  filter,
  fold,
  foldl,
  foldlWithKey,
  foldMap,
  foldMapWithKey,
  fromMap,
  toMap,
  fromList,
  fromListN,
  toList,
  toAscList,
  keys,
  elems,
  fromAscList,
  fromAscListN,
  fromAscListWithKey,
  fromAscListWithKeyN,
  fromDistinctAscList,
  fromDistinctAscListN,
  internMaybe,
  null,
  splitAt,
  -- Internal types
  KV.KVMVector,
  KV.KVVector,
  KV.normalize,
  KV.normalizeM,
)
where

import Control.DeepSeq
import Data.Aeson (FromJSON (..), FromJSONKey, ToJSON (..), ToJSONKey)
import qualified Data.Map.Strict as Map
import Data.Maybe as Maybe hiding (mapMaybe)
import Data.VMap.KVVector (KVVector (..))
import qualified Data.VMap.KVVector as KV
import qualified Data.Vector as V
import qualified Data.Vector.Generic as VG
import qualified Data.Vector.Primitive as VP
import qualified Data.Vector.Storable as VS
import qualified Data.Vector.Unboxed as VU
import qualified GHC.Exts as Exts
import GHC.Generics (Generic)
import NoThunks.Class
import Prelude hiding (filter, foldMap, foldl, lookup, map, null, splitAt)

type VB = V.Vector

type VU = VU.Vector

type VP = VP.Vector

type VS = VS.Vector

newtype VMap kv vv k v = VMap
  { forall (kv :: * -> *) (vv :: * -> *) k v.
VMap kv vv k v -> KVVector kv vv (k, v)
unVMap :: KVVector kv vv (k, v)
  }
  deriving (VMap kv vv k v -> VMap kv vv k v -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall (kv :: * -> *) (vv :: * -> *) k v.
(Eq (kv k), Eq (vv v)) =>
VMap kv vv k v -> VMap kv vv k v -> Bool
/= :: VMap kv vv k v -> VMap kv vv k v -> Bool
$c/= :: forall (kv :: * -> *) (vv :: * -> *) k v.
(Eq (kv k), Eq (vv v)) =>
VMap kv vv k v -> VMap kv vv k v -> Bool
== :: VMap kv vv k v -> VMap kv vv k v -> Bool
$c== :: forall (kv :: * -> *) (vv :: * -> *) k v.
(Eq (kv k), Eq (vv v)) =>
VMap kv vv k v -> VMap kv vv k v -> Bool
Eq, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall (kv :: * -> *) (vv :: * -> *) k v x.
Rep (VMap kv vv k v) x -> VMap kv vv k v
forall (kv :: * -> *) (vv :: * -> *) k v x.
VMap kv vv k v -> Rep (VMap kv vv k v) x
$cto :: forall (kv :: * -> *) (vv :: * -> *) k v x.
Rep (VMap kv vv k v) x -> VMap kv vv k v
$cfrom :: forall (kv :: * -> *) (vv :: * -> *) k v x.
VMap kv vv k v -> Rep (VMap kv vv k v) x
Generic, Context -> VMap kv vv k v -> IO (Maybe ThunkInfo)
Proxy (VMap kv vv k v) -> String
forall a.
(Context -> a -> IO (Maybe ThunkInfo))
-> (Context -> a -> IO (Maybe ThunkInfo))
-> (Proxy a -> String)
-> NoThunks a
forall (kv :: * -> *) (vv :: * -> *) k v.
(NoThunks (kv k), NoThunks (vv v), Typeable kv, Typeable vv,
 Typeable k, Typeable v) =>
Context -> VMap kv vv k v -> IO (Maybe ThunkInfo)
forall (kv :: * -> *) (vv :: * -> *) k v.
(NoThunks (kv k), NoThunks (vv v), Typeable kv, Typeable vv,
 Typeable k, Typeable v) =>
Proxy (VMap kv vv k v) -> String
showTypeOf :: Proxy (VMap kv vv k v) -> String
$cshowTypeOf :: forall (kv :: * -> *) (vv :: * -> *) k v.
(NoThunks (kv k), NoThunks (vv v), Typeable kv, Typeable vv,
 Typeable k, Typeable v) =>
Proxy (VMap kv vv k v) -> String
wNoThunks :: Context -> VMap kv vv k v -> IO (Maybe ThunkInfo)
$cwNoThunks :: forall (kv :: * -> *) (vv :: * -> *) k v.
(NoThunks (kv k), NoThunks (vv v), Typeable kv, Typeable vv,
 Typeable k, Typeable v) =>
Context -> VMap kv vv k v -> IO (Maybe ThunkInfo)
noThunks :: Context -> VMap kv vv k v -> IO (Maybe ThunkInfo)
$cnoThunks :: forall (kv :: * -> *) (vv :: * -> *) k v.
(NoThunks (kv k), NoThunks (vv v), Typeable kv, Typeable vv,
 Typeable k, Typeable v) =>
Context -> VMap kv vv k v -> IO (Maybe ThunkInfo)
NoThunks, VMap kv vv k v -> ()
forall a. (a -> ()) -> NFData a
forall (kv :: * -> *) (vv :: * -> *) k v.
(NFData (kv k), NFData (vv v)) =>
VMap kv vv k v -> ()
rnf :: VMap kv vv k v -> ()
$crnf :: forall (kv :: * -> *) (vv :: * -> *) k v.
(NFData (kv k), NFData (vv v)) =>
VMap kv vv k v -> ()
NFData, NonEmpty (VMap kv vv k v) -> VMap kv vv k v
VMap kv vv k v -> VMap kv vv k v -> VMap kv vv k v
forall b. Integral b => b -> VMap kv vv k v -> VMap kv vv k v
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
forall (kv :: * -> *) (vv :: * -> *) k v.
(Vector kv k, Vector vv v, Ord k) =>
NonEmpty (VMap kv vv k v) -> VMap kv vv k v
forall (kv :: * -> *) (vv :: * -> *) k v.
(Vector kv k, Vector vv v, Ord k) =>
VMap kv vv k v -> VMap kv vv k v -> VMap kv vv k v
forall (kv :: * -> *) (vv :: * -> *) k v b.
(Vector kv k, Vector vv v, Ord k, Integral b) =>
b -> VMap kv vv k v -> VMap kv vv k v
stimes :: forall b. Integral b => b -> VMap kv vv k v -> VMap kv vv k v
$cstimes :: forall (kv :: * -> *) (vv :: * -> *) k v b.
(Vector kv k, Vector vv v, Ord k, Integral b) =>
b -> VMap kv vv k v -> VMap kv vv k v
sconcat :: NonEmpty (VMap kv vv k v) -> VMap kv vv k v
$csconcat :: forall (kv :: * -> *) (vv :: * -> *) k v.
(Vector kv k, Vector vv v, Ord k) =>
NonEmpty (VMap kv vv k v) -> VMap kv vv k v
<> :: VMap kv vv k v -> VMap kv vv k v -> VMap kv vv k v
$c<> :: forall (kv :: * -> *) (vv :: * -> *) k v.
(Vector kv k, Vector vv v, Ord k) =>
VMap kv vv k v -> VMap kv vv k v -> VMap kv vv k v
Semigroup, VMap kv vv k v
[VMap kv vv k v] -> VMap kv vv k v
VMap kv vv k v -> VMap kv vv k v -> VMap kv vv k v
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
forall (kv :: * -> *) (vv :: * -> *) k v.
(Vector kv k, Vector vv v, Ord k) =>
Semigroup (VMap kv vv k v)
forall (kv :: * -> *) (vv :: * -> *) k v.
(Vector kv k, Vector vv v, Ord k) =>
VMap kv vv k v
forall (kv :: * -> *) (vv :: * -> *) k v.
(Vector kv k, Vector vv v, Ord k) =>
[VMap kv vv k v] -> VMap kv vv k v
forall (kv :: * -> *) (vv :: * -> *) k v.
(Vector kv k, Vector vv v, Ord k) =>
VMap kv vv k v -> VMap kv vv k v -> VMap kv vv k v
mconcat :: [VMap kv vv k v] -> VMap kv vv k v
$cmconcat :: forall (kv :: * -> *) (vv :: * -> *) k v.
(Vector kv k, Vector vv v, Ord k) =>
[VMap kv vv k v] -> VMap kv vv k v
mappend :: VMap kv vv k v -> VMap kv vv k v -> VMap kv vv k v
$cmappend :: forall (kv :: * -> *) (vv :: * -> *) k v.
(Vector kv k, Vector vv v, Ord k) =>
VMap kv vv k v -> VMap kv vv k v -> VMap kv vv k v
mempty :: VMap kv vv k v
$cmempty :: forall (kv :: * -> *) (vv :: * -> *) k v.
(Vector kv k, Vector vv v, Ord k) =>
VMap kv vv k v
Monoid)

instance (Show k, Show v, VG.Vector kv k, VG.Vector vv v) => Show (VMap kv vv k v) where
  show :: VMap kv vv k v -> String
show = forall a. Show a => a -> String
show forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (kv :: * -> *) k (vv :: * -> *) v.
(Vector kv k, Vector vv v) =>
KVVector kv vv (k, v) -> Map k v
KV.toMap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (kv :: * -> *) (vv :: * -> *) k v.
VMap kv vv k v -> KVVector kv vv (k, v)
unVMap

instance (VG.Vector kv k, VG.Vector vv v, Ord k) => Exts.IsList (VMap kv vv k v) where
  type Item (VMap kv vv k v) = (k, v)
  fromList :: [Item (VMap kv vv k v)] -> VMap kv vv k v
fromList = forall k (kv :: * -> *) (vv :: * -> *) v.
(Ord k, Vector kv k, Vector vv v) =>
[(k, v)] -> VMap kv vv k v
fromList
  {-# INLINE fromList #-}
  fromListN :: Int -> [Item (VMap kv vv k v)] -> VMap kv vv k v
fromListN = forall k (kv :: * -> *) (vv :: * -> *) v.
(Ord k, Vector kv k, Vector vv v) =>
Int -> [(k, v)] -> VMap kv vv k v
fromListN
  {-# INLINE fromListN #-}
  toList :: VMap kv vv k v -> [Item (VMap kv vv k v)]
toList = forall (kv :: * -> *) k (vv :: * -> *) v.
(Vector kv k, Vector vv v) =>
VMap kv vv k v -> [(k, v)]
toAscList
  {-# INLINE toList #-}

instance
  (VG.Vector vk k, VG.Vector vv v, ToJSONKey k, ToJSON v) =>
  ToJSON (VMap vk vv k v)
  where
  toJSON :: VMap vk vv k v -> Value
toJSON = forall a. ToJSON a => a -> Value
toJSON forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (kv :: * -> *) k (vv :: * -> *) v.
(Vector kv k, Vector vv v) =>
VMap kv vv k v -> Map k v
toMap
  toEncoding :: VMap vk vv k v -> Encoding
toEncoding = forall a. ToJSON a => a -> Encoding
toEncoding forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (kv :: * -> *) k (vv :: * -> *) v.
(Vector kv k, Vector vv v) =>
VMap kv vv k v -> Map k v
toMap

instance
  (VG.Vector vk k, VG.Vector vv v, Ord k, FromJSONKey k, FromJSON v) =>
  FromJSON (VMap vk vv k v)
  where
  parseJSON :: Value -> Parser (VMap vk vv k v)
parseJSON = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (kv :: * -> *) k (vv :: * -> *) v.
(Vector kv k, Vector vv v) =>
Map k v -> VMap kv vv k v
fromMap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. FromJSON a => Value -> Parser a
parseJSON

empty :: (VG.Vector kv k, VG.Vector vv v) => VMap kv vv k v
empty :: forall (kv :: * -> *) k (vv :: * -> *) v.
(Vector kv k, Vector vv v) =>
VMap kv vv k v
empty = forall (kv :: * -> *) (vv :: * -> *) k v.
KVVector kv vv (k, v) -> VMap kv vv k v
VMap forall (v :: * -> *) a. Vector v a => v a
VG.empty

size :: VG.Vector kv k => VMap kv vv k v -> Int
size :: forall (kv :: * -> *) k (vv :: * -> *) v.
Vector kv k =>
VMap kv vv k v -> Int
size = forall (v :: * -> *) a. Vector v a => v a -> Int
VG.length forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (kv :: * -> *) (vv :: * -> *) a.
KVVector kv vv a -> kv (Key a)
KV.keysVector forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (kv :: * -> *) (vv :: * -> *) k v.
VMap kv vv k v -> KVVector kv vv (k, v)
unVMap
{-# INLINE size #-}

lookup ::
  (Ord k, VG.Vector kv k, VG.Vector vv v) => k -> VMap kv vv k v -> Maybe v
lookup :: forall k (kv :: * -> *) (vv :: * -> *) v.
(Ord k, Vector kv k, Vector vv v) =>
k -> VMap kv vv k v -> Maybe v
lookup k
k = forall k (kv :: * -> *) (vv :: * -> *) v.
(Ord k, Vector kv k, Vector vv v) =>
k -> KVVector kv vv (k, v) -> Maybe v
KV.lookupKVVector k
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (kv :: * -> *) (vv :: * -> *) k v.
VMap kv vv k v -> KVVector kv vv (k, v)
unVMap
{-# INLINE lookup #-}

member ::
  (Ord k, VG.Vector kv k) => k -> VMap kv vv k v -> Bool
member :: forall k (kv :: * -> *) (vv :: * -> *) v.
(Ord k, Vector kv k) =>
k -> VMap kv vv k v -> Bool
member k
k = forall k (kv :: * -> *) (vv :: * -> *) v.
(Ord k, Vector kv k) =>
k -> KVVector kv vv (k, v) -> Bool
KV.memberKVVector k
k forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (kv :: * -> *) (vv :: * -> *) k v.
VMap kv vv k v -> KVVector kv vv (k, v)
unVMap
{-# INLINE member #-}

notMember ::
  (Ord k, VG.Vector kv k) => k -> VMap kv vv k v -> Bool
notMember :: forall k (kv :: * -> *) (vv :: * -> *) v.
(Ord k, Vector kv k) =>
k -> VMap kv vv k v -> Bool
notMember k
k = Bool -> Bool
not forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k (kv :: * -> *) (vv :: * -> *) v.
(Ord k, Vector kv k) =>
k -> VMap kv vv k v -> Bool
member k
k
{-# INLINE notMember #-}

filter ::
  (VG.Vector kv k, VG.Vector vv v) =>
  (k -> v -> Bool) ->
  VMap kv vv k v ->
  VMap kv vv k v
filter :: forall (kv :: * -> *) k (vv :: * -> *) v.
(Vector kv k, Vector vv v) =>
(k -> v -> Bool) -> VMap kv vv k v -> VMap kv vv k v
filter k -> v -> Bool
f = forall (kv :: * -> *) (vv :: * -> *) k v.
KVVector kv vv (k, v) -> VMap kv vv k v
VMap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (v :: * -> *) a. Vector v a => (a -> Bool) -> v a -> v a
VG.filter (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry k -> v -> Bool
f) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (kv :: * -> *) (vv :: * -> *) k v.
VMap kv vv k v -> KVVector kv vv (k, v)
unVMap
{-# INLINE filter #-}

findWithDefault ::
  (Ord k, VG.Vector kv k, VG.Vector vv v) => v -> k -> VMap kv vv k v -> v
findWithDefault :: forall k (kv :: * -> *) (vv :: * -> *) v.
(Ord k, Vector kv k, Vector vv v) =>
v -> k -> VMap kv vv k v -> v
findWithDefault v
a k
k = forall a. a -> Maybe a -> a
fromMaybe v
a forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k (kv :: * -> *) (vv :: * -> *) v.
(Ord k, Vector kv k, Vector vv v) =>
k -> VMap kv vv k v -> Maybe v
lookup k
k
{-# INLINE findWithDefault #-}

fromMap :: (VG.Vector kv k, VG.Vector vv v) => Map.Map k v -> VMap kv vv k v
fromMap :: forall (kv :: * -> *) k (vv :: * -> *) v.
(Vector kv k, Vector vv v) =>
Map k v -> VMap kv vv k v
fromMap = forall (kv :: * -> *) (vv :: * -> *) k v.
KVVector kv vv (k, v) -> VMap kv vv k v
VMap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (kv :: * -> *) k (vv :: * -> *) v.
(Vector kv k, Vector vv v) =>
Map k v -> KVVector kv vv (k, v)
KV.fromMap
{-# INLINE fromMap #-}

toMap :: (VG.Vector kv k, VG.Vector vv v) => VMap kv vv k v -> Map.Map k v
toMap :: forall (kv :: * -> *) k (vv :: * -> *) v.
(Vector kv k, Vector vv v) =>
VMap kv vv k v -> Map k v
toMap = forall (kv :: * -> *) k (vv :: * -> *) v.
(Vector kv k, Vector vv v) =>
KVVector kv vv (k, v) -> Map k v
KV.toMap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (kv :: * -> *) (vv :: * -> *) k v.
VMap kv vv k v -> KVVector kv vv (k, v)
unVMap
{-# INLINE toMap #-}

toList :: (VG.Vector kv k, VG.Vector vv v) => VMap kv vv k v -> [(k, v)]
toList :: forall (kv :: * -> *) k (vv :: * -> *) v.
(Vector kv k, Vector vv v) =>
VMap kv vv k v -> [(k, v)]
toList = forall (v :: * -> *) a. Vector v a => v a -> [a]
VG.toList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (kv :: * -> *) (vv :: * -> *) k v.
VMap kv vv k v -> KVVector kv vv (k, v)
unVMap
{-# INLINE toList #-}

toAscList :: (VG.Vector kv k, VG.Vector vv v) => VMap kv vv k v -> [(k, v)]
toAscList :: forall (kv :: * -> *) k (vv :: * -> *) v.
(Vector kv k, Vector vv v) =>
VMap kv vv k v -> [(k, v)]
toAscList = forall (v :: * -> *) a. Vector v a => v a -> [a]
VG.toList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (kv :: * -> *) (vv :: * -> *) k v.
VMap kv vv k v -> KVVector kv vv (k, v)
unVMap
{-# INLINE toAscList #-}

fromList ::
  (Ord k, VG.Vector kv k, VG.Vector vv v) => [(k, v)] -> VMap kv vv k v
fromList :: forall k (kv :: * -> *) (vv :: * -> *) v.
(Ord k, Vector kv k, Vector vv v) =>
[(k, v)] -> VMap kv vv k v
fromList = forall (kv :: * -> *) (vv :: * -> *) k v.
KVVector kv vv (k, v) -> VMap kv vv k v
VMap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (kv :: * -> *) k (vv :: * -> *) v.
(Vector kv k, Vector vv v, Ord k) =>
[(k, v)] -> KVVector kv vv (k, v)
KV.fromList
{-# INLINE fromList #-}

fromListN ::
  (Ord k, VG.Vector kv k, VG.Vector vv v) => Int -> [(k, v)] -> VMap kv vv k v
fromListN :: forall k (kv :: * -> *) (vv :: * -> *) v.
(Ord k, Vector kv k, Vector vv v) =>
Int -> [(k, v)] -> VMap kv vv k v
fromListN Int
n = forall (kv :: * -> *) (vv :: * -> *) k v.
KVVector kv vv (k, v) -> VMap kv vv k v
VMap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (kv :: * -> *) k (vv :: * -> *) v.
(Vector kv k, Vector vv v, Ord k) =>
Int -> [(k, v)] -> KVVector kv vv (k, v)
KV.fromListN Int
n
{-# INLINE fromListN #-}

fromAscList ::
  (Eq k, VG.Vector kv k, VG.Vector vv v) => [(k, v)] -> VMap kv vv k v
fromAscList :: forall k (kv :: * -> *) (vv :: * -> *) v.
(Eq k, Vector kv k, Vector vv v) =>
[(k, v)] -> VMap kv vv k v
fromAscList = forall (kv :: * -> *) (vv :: * -> *) k v.
KVVector kv vv (k, v) -> VMap kv vv k v
VMap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k (kv :: * -> *) (vv :: * -> *) v.
(Eq k, Vector kv k, Vector vv v) =>
[(k, v)] -> KVVector kv vv (k, v)
KV.fromAscList
{-# INLINE fromAscList #-}

fromAscListN ::
  (Eq k, VG.Vector kv k, VG.Vector vv v) => Int -> [(k, v)] -> VMap kv vv k v
fromAscListN :: forall k (kv :: * -> *) (vv :: * -> *) v.
(Eq k, Vector kv k, Vector vv v) =>
Int -> [(k, v)] -> VMap kv vv k v
fromAscListN Int
n = forall (kv :: * -> *) (vv :: * -> *) k v.
KVVector kv vv (k, v) -> VMap kv vv k v
VMap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k (kv :: * -> *) (vv :: * -> *) v.
(Eq k, Vector kv k, Vector vv v) =>
Int -> [(k, v)] -> KVVector kv vv (k, v)
KV.fromAscListN Int
n
{-# INLINE fromAscListN #-}

fromAscListWithKey ::
  (Eq k, VG.Vector kv k, VG.Vector vv v) => (k -> v -> v -> v) -> [(k, v)] -> VMap kv vv k v
fromAscListWithKey :: forall k (kv :: * -> *) (vv :: * -> *) v.
(Eq k, Vector kv k, Vector vv v) =>
(k -> v -> v -> v) -> [(k, v)] -> VMap kv vv k v
fromAscListWithKey k -> v -> v -> v
f = forall (kv :: * -> *) (vv :: * -> *) k v.
KVVector kv vv (k, v) -> VMap kv vv k v
VMap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k (kv :: * -> *) (vv :: * -> *) v.
(Eq k, Vector kv k, Vector vv v) =>
(k -> v -> v -> v) -> [(k, v)] -> KVVector kv vv (k, v)
KV.fromAscListWithKey k -> v -> v -> v
f
{-# INLINE fromAscListWithKey #-}

fromAscListWithKeyN ::
  (Eq k, VG.Vector kv k, VG.Vector vv v) => Int -> (k -> v -> v -> v) -> [(k, v)] -> VMap kv vv k v
fromAscListWithKeyN :: forall k (kv :: * -> *) (vv :: * -> *) v.
(Eq k, Vector kv k, Vector vv v) =>
Int -> (k -> v -> v -> v) -> [(k, v)] -> VMap kv vv k v
fromAscListWithKeyN Int
n k -> v -> v -> v
f = forall (kv :: * -> *) (vv :: * -> *) k v.
KVVector kv vv (k, v) -> VMap kv vv k v
VMap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall k (kv :: * -> *) (vv :: * -> *) v.
(Eq k, Vector kv k, Vector vv v) =>
Int -> (k -> v -> v -> v) -> [(k, v)] -> KVVector kv vv (k, v)
KV.fromAscListWithKeyN Int
n k -> v -> v -> v
f
{-# INLINE fromAscListWithKeyN #-}

fromDistinctAscList ::
  (VG.Vector kv k, VG.Vector vv v) => [(k, v)] -> VMap kv vv k v
fromDistinctAscList :: forall (kv :: * -> *) k (vv :: * -> *) v.
(Vector kv k, Vector vv v) =>
[(k, v)] -> VMap kv vv k v
fromDistinctAscList = forall (kv :: * -> *) (vv :: * -> *) k v.
KVVector kv vv (k, v) -> VMap kv vv k v
VMap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (kv :: * -> *) k (vv :: * -> *) v.
(Vector kv k, Vector vv v) =>
[(k, v)] -> KVVector kv vv (k, v)
KV.fromDistinctAscList
{-# INLINE fromDistinctAscList #-}

fromDistinctAscListN ::
  (VG.Vector kv k, VG.Vector vv v) => Int -> [(k, v)] -> VMap kv vv k v
fromDistinctAscListN :: forall (kv :: * -> *) k (vv :: * -> *) v.
(Vector kv k, Vector vv v) =>
Int -> [(k, v)] -> VMap kv vv k v
fromDistinctAscListN Int
n = forall (kv :: * -> *) (vv :: * -> *) k v.
KVVector kv vv (k, v) -> VMap kv vv k v
VMap forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (kv :: * -> *) k (vv :: * -> *) v.
(Vector kv k, Vector vv v) =>
Int -> [(k, v)] -> KVVector kv vv (k, v)
KV.fromDistinctAscListN Int
n
{-# INLINE fromDistinctAscListN #-}

map ::
  (VG.Vector vv a, VG.Vector vv b) =>
  (a -> b) ->
  VMap kv vv k a ->
  VMap kv vv k b
map :: forall (vv :: * -> *) a b (kv :: * -> *) k.
(Vector vv a, Vector vv b) =>
(a -> b) -> VMap kv vv k a -> VMap kv vv k b
map a -> b
f (VMap KVVector kv vv (k, a)
vec) = forall (kv :: * -> *) (vv :: * -> *) k v.
KVVector kv vv (k, v) -> VMap kv vv k v
VMap (forall (vv :: * -> *) a b (kv :: * -> *) k.
(Vector vv a, Vector vv b) =>
(a -> b) -> KVVector kv vv (k, a) -> KVVector kv vv (k, b)
KV.mapValsKVVector a -> b
f KVVector kv vv (k, a)
vec)
{-# INLINE map #-}

mapMaybe ::
  (VG.Vector kv k, VG.Vector vv a, VG.Vector vv b) =>
  (a -> Maybe b) ->
  VMap kv vv k a ->
  VMap kv vv k b
mapMaybe :: forall (kv :: * -> *) k (vv :: * -> *) a b.
(Vector kv k, Vector vv a, Vector vv b) =>
(a -> Maybe b) -> VMap kv vv k a -> VMap kv vv k b
mapMaybe a -> Maybe b
f (VMap KVVector kv vv (k, a)
vec) = forall (kv :: * -> *) (vv :: * -> *) k v.
KVVector kv vv (k, v) -> VMap kv vv k v
VMap (forall (v :: * -> *) a b.
(Vector v a, Vector v b) =>
(a -> Maybe b) -> v a -> v b
VG.mapMaybe (\(k
k, a
x) -> (,) k
k forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> a -> Maybe b
f a
x) KVVector kv vv (k, a)
vec)
{-# INLINE mapMaybe #-}

mapWithKey ::
  (VG.Vector kv k, VG.Vector vv a, VG.Vector vv b) =>
  (k -> a -> b) ->
  VMap kv vv k a ->
  VMap kv vv k b
mapWithKey :: forall (kv :: * -> *) k (vv :: * -> *) a b.
(Vector kv k, Vector vv a, Vector vv b) =>
(k -> a -> b) -> VMap kv vv k a -> VMap kv vv k b
mapWithKey k -> a -> b
f (VMap KVVector kv vv (k, a)
vec) = forall (kv :: * -> *) (vv :: * -> *) k v.
KVVector kv vv (k, v) -> VMap kv vv k v
VMap (forall (kv :: * -> *) k (vv :: * -> *) a b.
(Vector kv k, Vector vv a, Vector vv b) =>
(k -> a -> b) -> KVVector kv vv (k, a) -> KVVector kv vv (k, b)
KV.mapWithKeyKVVector k -> a -> b
f KVVector kv vv (k, a)
vec)
{-# INLINE mapWithKey #-}

foldMapWithKey ::
  (VG.Vector kv k, VG.Vector vv v, Monoid m) =>
  (k -> v -> m) ->
  VMap kv vv k v ->
  m
foldMapWithKey :: forall (kv :: * -> *) k (vv :: * -> *) v m.
(Vector kv k, Vector vv v, Monoid m) =>
(k -> v -> m) -> VMap kv vv k v -> m
foldMapWithKey k -> v -> m
f = forall m (v :: * -> *) a.
(Monoid m, Vector v a) =>
(a -> m) -> v a -> m
VG.foldMap' (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry k -> v -> m
f) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (kv :: * -> *) (vv :: * -> *) k v.
VMap kv vv k v -> KVVector kv vv (k, v)
unVMap
{-# INLINE foldMapWithKey #-}

foldl ::
  VG.Vector vv v =>
  (a -> v -> a) ->
  a ->
  VMap kv vv k v ->
  a
foldl :: forall (vv :: * -> *) v a (kv :: * -> *) k.
Vector vv v =>
(a -> v -> a) -> a -> VMap kv vv k v -> a
foldl a -> v -> a
f a
a = forall (v :: * -> *) b a.
Vector v b =>
(a -> b -> a) -> a -> v b -> a
VG.foldl' a -> v -> a
f a
a forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (kv :: * -> *) (vv :: * -> *) a.
KVVector kv vv a -> vv (Value a)
valsVector forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (kv :: * -> *) (vv :: * -> *) k v.
VMap kv vv k v -> KVVector kv vv (k, v)
unVMap
{-# INLINE foldl #-}

foldlWithKey ::
  (VG.Vector kv k, VG.Vector vv v) =>
  (a -> k -> v -> a) ->
  a ->
  VMap kv vv k v ->
  a
foldlWithKey :: forall (kv :: * -> *) k (vv :: * -> *) v a.
(Vector kv k, Vector vv v) =>
(a -> k -> v -> a) -> a -> VMap kv vv k v -> a
foldlWithKey a -> k -> v -> a
f a
a = forall (v :: * -> *) b a.
Vector v b =>
(a -> b -> a) -> a -> v b -> a
VG.foldl' (forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> k -> v -> a
f) a
a forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (kv :: * -> *) (vv :: * -> *) k v.
VMap kv vv k v -> KVVector kv vv (k, v)
unVMap
{-# INLINE foldlWithKey #-}

foldMap :: (VG.Vector vv v, Monoid m) => (v -> m) -> VMap kv vv k v -> m
foldMap :: forall (vv :: * -> *) v m (kv :: * -> *) k.
(Vector vv v, Monoid m) =>
(v -> m) -> VMap kv vv k v -> m
foldMap v -> m
f = forall m (v :: * -> *) a.
(Monoid m, Vector v a) =>
(a -> m) -> v a -> m
VG.foldMap' v -> m
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (kv :: * -> *) (vv :: * -> *) a.
KVVector kv vv a -> vv (Value a)
valsVector forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (kv :: * -> *) (vv :: * -> *) k v.
VMap kv vv k v -> KVVector kv vv (k, v)
unVMap
{-# INLINE foldMap #-}

-- | Fold values monoidally
fold :: (VG.Vector vv m, Monoid m) => VMap kv vv k m -> m
fold :: forall (vv :: * -> *) m (kv :: * -> *) k.
(Vector vv m, Monoid m) =>
VMap kv vv k m -> m
fold = forall m (v :: * -> *) a.
(Monoid m, Vector v a) =>
(a -> m) -> v a -> m
VG.foldMap' forall a. a -> a
id forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (kv :: * -> *) (vv :: * -> *) a.
KVVector kv vv a -> vv (Value a)
valsVector forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (kv :: * -> *) (vv :: * -> *) k v.
VMap kv vv k v -> KVVector kv vv (k, v)
unVMap
{-# INLINE fold #-}

keys :: VG.Vector kv k => VMap kv vv k v -> [k]
keys :: forall (kv :: * -> *) k (vv :: * -> *) v.
Vector kv k =>
VMap kv vv k v -> [k]
keys = forall (v :: * -> *) a. Vector v a => v a -> [a]
VG.toList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (kv :: * -> *) (vv :: * -> *) a.
KVVector kv vv a -> kv (Key a)
keysVector forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (kv :: * -> *) (vv :: * -> *) k v.
VMap kv vv k v -> KVVector kv vv (k, v)
unVMap
{-# INLINE keys #-}

elems :: VG.Vector vv v => VMap kv vv k v -> [v]
elems :: forall (vv :: * -> *) v (kv :: * -> *) k.
Vector vv v =>
VMap kv vv k v -> [v]
elems = forall (v :: * -> *) a. Vector v a => v a -> [a]
VG.toList forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (kv :: * -> *) (vv :: * -> *) a.
KVVector kv vv a -> vv (Value a)
valsVector forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (kv :: * -> *) (vv :: * -> *) k v.
VMap kv vv k v -> KVVector kv vv (k, v)
unVMap
{-# INLINE elems #-}

null :: (VG.Vector vv v, VG.Vector kv k) => VMap kv vv k v -> Bool
null :: forall (vv :: * -> *) v (kv :: * -> *) k.
(Vector vv v, Vector kv k) =>
VMap kv vv k v -> Bool
null (VMap KVVector kv vv (k, v)
vec) = forall (v :: * -> *) a. Vector v a => v a -> Bool
VG.null KVVector kv vv (k, v)
vec
{-# INLINE null #-}

splitAt ::
  (VG.Vector vv v, VG.Vector kv k) =>
  Int ->
  VMap kv vv k v ->
  (VMap kv vv k v, VMap kv vv k v)
splitAt :: forall (vv :: * -> *) v (kv :: * -> *) k.
(Vector vv v, Vector kv k) =>
Int -> VMap kv vv k v -> (VMap kv vv k v, VMap kv vv k v)
splitAt Int
i (VMap KVVector kv vv (k, v)
vec) = let (KVVector kv vv (k, v)
l, KVVector kv vv (k, v)
r) = forall (v :: * -> *) a. Vector v a => Int -> v a -> (v a, v a)
VG.splitAt Int
i KVVector kv vv (k, v)
vec in (forall (kv :: * -> *) (vv :: * -> *) k v.
KVVector kv vv (k, v) -> VMap kv vv k v
VMap KVVector kv vv (k, v)
l, forall (kv :: * -> *) (vv :: * -> *) k v.
KVVector kv vv (k, v) -> VMap kv vv k v
VMap KVVector kv vv (k, v)
r)
{-# INLINE splitAt #-}

internMaybe :: (VG.Vector kv k, Ord k) => k -> VMap kv vv k v -> Maybe k
internMaybe :: forall (kv :: * -> *) k (vv :: * -> *) v.
(Vector kv k, Ord k) =>
k -> VMap kv vv k v -> Maybe k
internMaybe k
key = forall (kv :: * -> *) k (vv :: * -> *) v.
(Vector kv k, Ord k) =>
k -> KVVector kv vv (k, v) -> Maybe k
KV.internKVVectorMaybe k
key forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (kv :: * -> *) (vv :: * -> *) k v.
VMap kv vv k v -> KVVector kv vv (k, v)
unVMap
{-# INLINE internMaybe #-}