@@ -13,20 +13,18 @@ import Streamly.Internal.Data.Unfold (Unfold)
13import qualified Streamly.Internal.Data.Unfold as UF
13import qualified Streamly.Internal.Data.Unfold as UF
14import qualified Streamly.Internal.Data.Fold as FL
14import qualified Streamly.Internal.Data.Fold as FL
19-- n * (n + 1) / 2 == linearCount
16-- n * (n + 1) / 2 == linearCount
20−concatCount :: Int
17+concatCount :: Int -> Int
21−concatCount = 450
18+concatCount linearCount =
19+ round (((1 + 8 * fromIntegral linearCount)**(1/2::Double) - 1) / 2)
23-- double nested loop
21-- double nested loop
24−nestedCount2 :: Int
22+nestedCount2 :: Int -> Int
25−nestedCount2 = round (fromIntegral linearCount**(1/2::Double))
23+nestedCount2 linearCount = round (fromIntegral linearCount**(1/2::Double))
27-- triple nested loop
25-- triple nested loop
28−nestedCount3 :: Int
26+nestedCount3 :: Int -> Int
29−nestedCount3 = round (fromIntegral linearCount**(1/3::Double))
27+nestedCount3 linearCount = round (fromIntegral linearCount**(1/3::Double))
31-------------------------------------------------------------------------------
29-------------------------------------------------------------------------------
32-- Stream generation and elimination
30-- Stream generation and elimination
@@ -42,18 +40,18 @@ source n = UF.enumerateFromToIntegral n
42-------------------------------------------------------------------------------
40-------------------------------------------------------------------------------
44{-# INLINE toNull #-}
42{-# INLINE toNull #-}
45−toNull :: MonadIO m => Int -> m ()
43+toNull :: MonadIO m => Int -> Int -> m ()
46−toNull start = do
44+toNull linearCount start = do
47− let end = start + nestedCount2
45+ let end = start + nestedCount2 linearCount
49 (UF.map (\(x, y) -> x + y)
47 (UF.map (\(x, y) -> x + y)
50 $ UF.outerProduct (source end) (source end))
48 $ UF.outerProduct (source end) (source end))
51 FL.drain (start, start)
49 FL.drain (start, start)
53{-# INLINE toNull3 #-}
51{-# INLINE toNull3 #-}
54−toNull3 :: MonadIO m => Int -> m ()
52+toNull3 :: MonadIO m => Int -> Int -> m ()
55−toNull3 start = do
53+toNull3 linearCount start = do
56− let end = start + nestedCount3
54+ let end = start + nestedCount3 linearCount
58 (UF.map (\(x, y) -> x + y)
56 (UF.map (\(x, y) -> x + y)
59 $ UF.outerProduct (source end)
57 $ UF.outerProduct (source end)
@@ -62,35 +60,35 @@ toNull3 start = do
62 FL.drain (start, (start, start))
60 FL.drain (start, (start, start))
64{-# INLINE concat #-}
62{-# INLINE concat #-}
65−concat :: MonadIO m => Int -> m ()
63+concat :: MonadIO m => Int -> Int -> m ()
66−concat start = do
64+concat linearCount start = do
67− let end = start + concatCount
65+ let end = start + concatCount linearCount
69 (UF.concat (source end) (source end))
67 (UF.concat (source end) (source end))
70 FL.drain start
68 FL.drain start
72{-# INLINE toList #-}
70{-# INLINE toList #-}
73−toList :: MonadIO m => Int -> m [Int]
71+toList :: MonadIO m => Int -> Int -> m [Int]
74−toList start = do
72+toList linearCount start = do
75− let end = start + nestedCount2
73+ let end = start + nestedCount2 linearCount
77 (UF.map (\(x, y) -> x + y)
75 (UF.map (\(x, y) -> x + y)
78 $ UF.outerProduct (source end) (source end))
76 $ UF.outerProduct (source end) (source end))
79 FL.toList (start, start)
77 FL.toList (start, start)
81{-# INLINE toListSome #-}
79{-# INLINE toListSome #-}
82−toListSome :: MonadIO m => Int -> m [Int]
80+toListSome :: MonadIO m => Int -> Int -> m [Int]
83−toListSome start = do
81+toListSome linearCount start = do
84− let end = start + nestedCount2
82+ let end = start + nestedCount2 linearCount
86 (UF.take 1000 $ (UF.map (\(x, y) -> x + y)
84 (UF.take 1000 $ (UF.map (\(x, y) -> x + y)
87 $ UF.outerProduct (source end) (source end)))
85 $ UF.outerProduct (source end) (source end)))
88 FL.toList (start, start)
86 FL.toList (start, start)
90{-# INLINE filterAllOut #-}
88{-# INLINE filterAllOut #-}
91−filterAllOut :: MonadIO m => Int -> m ()
89+filterAllOut :: MonadIO m => Int -> Int -> m ()
92−filterAllOut start = do
90+filterAllOut linearCount start = do
93− let end = start + nestedCount2
91+ let end = start + nestedCount2 linearCount
95 (UF.filter (< 0)
93 (UF.filter (< 0)
96 $ UF.map (\(x, y) -> x + y)
94 $ UF.map (\(x, y) -> x + y)
@@ -98,9 +96,9 @@ filterAllOut start = do
98 FL.drain (start, start)
96 FL.drain (start, start)
100{-# INLINE filterAllIn #-}
98{-# INLINE filterAllIn #-}
101−filterAllIn :: MonadIO m => Int -> m ()
99+filterAllIn :: MonadIO m => Int -> Int -> m ()
102−filterAllIn start = do
100+filterAllIn linearCount start = do
103− let end = start + nestedCount2
101+ let end = start + nestedCount2 linearCount
105 (UF.filter (> 0)
103 (UF.filter (> 0)
106 $ UF.map (\(x, y) -> x + y)
104 $ UF.map (\(x, y) -> x + y)
@@ -108,9 +106,9 @@ filterAllIn start = do
108 FL.drain (start, start)
106 FL.drain (start, start)
110{-# INLINE filterSome #-}
108{-# INLINE filterSome #-}
111−filterSome :: MonadIO m => Int -> m ()
109+filterSome :: MonadIO m => Int -> Int -> m ()
112−filterSome start = do
110+filterSome linearCount start = do
113− let end = start + nestedCount2
111+ let end = start + nestedCount2 linearCount
115 (UF.filter (> 1100000)
113 (UF.filter (> 1100000)
116 $ UF.map (\(x, y) -> x + y)
114 $ UF.map (\(x, y) -> x + y)
@@ -118,9 +116,9 @@ filterSome start = do
118 FL.drain (start, start)
116 FL.drain (start, start)
120{-# INLINE breakAfterSome #-}
118{-# INLINE breakAfterSome #-}
121−breakAfterSome :: MonadIO m => Int -> m ()
119+breakAfterSome :: MonadIO m => Int -> Int -> m ()
122−breakAfterSome start = do
120+breakAfterSome linearCount start = do
123− let end = start + nestedCount2
121+ let end = start + nestedCount2 linearCount
125 (UF.takeWhile (<= 1100000)
123 (UF.takeWhile (<= 1100000)
126 $ UF.map (\(x, y) -> x + y)
124 $ UF.map (\(x, y) -> x + y)