{-
-Copyright (C) 2009, 2010 Google Inc.
+Copyright (C) 2009, 2010, 2011 Google Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
-}
module Ganeti.HTools.Container
- (
- -- * Types
- Container
- , Key
- -- * Creation
- , IntMap.empty
- , IntMap.singleton
- , IntMap.fromList
- -- * Query
- , IntMap.size
- , IntMap.null
- , find
- , IntMap.findMax
- -- * Update
- , add
- , addTwo
- , IntMap.map
- , IntMap.mapAccum
- , IntMap.filter
- -- * Conversion
- , IntMap.elems
- , IntMap.keys
- -- * Element functions
- , nameOf
- , findByName
- ) where
+ ( -- * Types
+ Container
+ , Key
+ -- * Creation
+ , IntMap.empty
+ , IntMap.singleton
+ , IntMap.fromList
+ -- * Query
+ , IntMap.size
+ , IntMap.null
+ , find
+ , IntMap.findMax
+ , IntMap.member
+ -- * Update
+ , add
+ , addTwo
+ , IntMap.map
+ , IntMap.mapAccum
+ , IntMap.filter
+ -- * Conversion
+ , IntMap.elems
+ , IntMap.keys
+ -- * Element functions
+ , nameOf
+ , findByName
+ ) where
import qualified Data.IntMap as IntMap
import qualified Ganeti.HTools.Types as T
+-- | Our key type.
+
type Key = IntMap.Key
+
+-- | Our container type.
type Container = IntMap.IntMap
-- | Locate a key in the map (must exist).
findByName :: (T.Element a, Monad m) =>
Container a -> String -> m a
findByName c n =
- let all_elems = IntMap.elems c
- result = filter ((n `elem`) . T.allNames) all_elems
- in case result of
- [item] -> return item
- _ -> fail $ "Wrong number of elems found with name " ++ n
+ let all_elems = IntMap.elems c
+ result = filter ((n `elem`) . T.allNames) all_elems
+ in case result of
+ [item] -> return item
+ _ -> fail $ "Wrong number of elems found with name " ++ n