Abstract the secondary evac into a separate function
[ganeti-local] / htools / Ganeti / HTools / Container.hs
index 12d1978..ec8a11c 100644 (file)
@@ -7,7 +7,7 @@ give the best performance for our workload.
 
 {-
 
-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
@@ -27,38 +27,42 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 -}
 
 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).
@@ -81,8 +85,8 @@ nameOf c k = T.nameOf $ find k c
 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