LGTM
On 11/02/2015 04:59 PM, 'Klaus Aehlig' via ganeti-devel wrote:
Splitting a problem into two smaller problems of about
equal size is a common approach. Do this for lists by moving
list elements alternatingly into two sublists.
Signed-off-by: Klaus Aehlig <[email protected]>
---
src/Ganeti/Utils.hs | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/src/Ganeti/Utils.hs b/src/Ganeti/Utils.hs
index fbe3a36..46cfc67 100644
--- a/src/Ganeti/Utils.hs
+++ b/src/Ganeti/Utils.hs
@@ -4,7 +4,7 @@
{-
-Copyright (C) 2009, 2010, 2011, 2012, 2013 Google Inc.
+Copyright (C) 2009, 2010, 2011, 2012, 2013, 2015 Google Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -44,6 +44,7 @@ module Ganeti.Utils
, applyIf
, commaJoin
, ensureQuoted
+ , divideList
, tryRead
, readMaybe
, formatTable
@@ -209,6 +210,12 @@ ensureQuoted v = if not (all (\c -> isAlphaNum c || c ==
'.') v)
threadDelaySeconds :: Int -> IO ()
threadDelaySeconds = threadDelay . (*) 1000000
+-- | Split a list into two lists of approximately the same length.
+divideList :: [a] -> ([a], [a])
+divideList [] = ([], [])
+divideList [a] = ([a], [])
+divideList (a:b:xs) = let (ls, rs) = divideList xs in (a:ls, b:rs)
+
-- * Mathematical functions
-- Simple and slow statistical functions, please replace with better