packages feed

binary-list 0.3.3.0 → 0.3.4.0

raw patch · 2 files changed

+17/−1 lines, 2 files

Files

Data/BinaryList.hs view
@@ -52,6 +52,7 @@   , take   , takeEnd     -- * Transformation+  , replace   , reverse     -- * Tuples   , joinPairs@@ -121,6 +122,21 @@           else lookup r $ i - m -- Lookup in the right branch lookup (ListEnd x) 0 = Just x lookup _ _ = Nothing++-- | /O(log n)/. Replace a single element in the list. If the index is+--   out of range, returns the original list.+replace :: Int -- ^ Index to look for+        -> a   -- ^ Element to insert+        -> BinList a -> BinList a+replace i0 y = go i0+  where+    go i (ListNode n l r) =+      let m = 2^(n-1)+      in  if i < m+             then ListNode (go i l)          r+             else ListNode       l (go (i-m) r)+    go 0 (ListEnd x) = ListEnd y+    go _ e = e  -- | /O(1)/. Append two binary lists. This is only possible --   if both lists have the same length. If this condition
binary-list.cabal view
@@ -1,5 +1,5 @@ name:                binary-list-version:             0.3.3.0+version:             0.3.4.0 synopsis:            Lists of size length a power of two. description:         Implementation of lists whose number of elements is a                      power of two. Binary lists have this property by definition,