forked from influxdata/influxdb-csharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add maxBatchSize parameter to IntervalBatcher
Fixes influxdata#58
- Loading branch information
1 parent
2e8eca8
commit 8a62bb9
Showing
4 changed files
with
60 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace InfluxDB.Collector.Util | ||
{ | ||
internal static class EnumerableExtensions | ||
{ | ||
// from https://github.com/morelinq/MoreLINQ/blob/master/MoreLinq/Batch.cs | ||
public static IEnumerable<IEnumerable<TSource>> Batch<TSource>(this IEnumerable<TSource> source, int size) | ||
{ | ||
TSource[] bucket = null; | ||
var count = 0; | ||
|
||
foreach (var item in source) | ||
{ | ||
if (bucket == null) | ||
{ | ||
bucket = new TSource[size]; | ||
} | ||
|
||
bucket[count++] = item; | ||
if (count != size) | ||
{ | ||
continue; | ||
} | ||
|
||
yield return bucket; | ||
|
||
bucket = null; | ||
count = 0; | ||
} | ||
|
||
if (bucket != null && count > 0) | ||
{ | ||
yield return bucket.Take(count); | ||
} | ||
} | ||
} | ||
} |