Guest User

Untitled

a guest
Sep 24th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.31 KB | None | 0 0
  1.     public class GetSpread<T> : IPluginEvaluate
  2.     {
  3.         #region fields & pins
  4.         [Input("Input")]
  5.         IInStream<IInStream<T>> FInput;
  6.  
  7.         //[Input("Input Bin Size")]
  8.         //IInStream<int> FInputBinSize;
  9.        
  10.         [Input("Offset")]
  11.         IInStream<int> FOffset;
  12.        
  13.         [Input("Count", DefaultValue = 1, MinValue = 0)]
  14.         IInStream<int> FCount;
  15.  
  16.         [Output("Output")]
  17.         IOutStream<IInStream<T>> FOutput;
  18.  
  19.         //[Output("Output Bin Size")]
  20.         //IOutStream<int> FOutputBinSize;
  21.         #endregion fields & pins
  22.  
  23.         //called when data for any output pin is requested
  24.         public void Evaluate(int spreadMax)
  25.         {
  26.             FOutput.Length = StreamUtils.GetMaxLength(FInput, FOffset, FCount);
  27.  
  28.             var inputBuffer = MemoryPool<IInStream<T>>.GetArray();
  29.             var offsetBuffer = MemoryPool<int>.GetArray();
  30.             var countBuffer = MemoryPool<int>.GetArray();
  31.            
  32.             try
  33.             {
  34.                 using (var inputReader = FInput.GetCyclicReader())
  35.                 using (var offsetReader = FOffset.GetCyclicReader())
  36.                 using (var countReader = FCount.GetCyclicReader())
  37.                 using (var outputWriter = FOutput.GetWriter())
  38.                 {
  39.                     var numSlicesToWrite = FOutput.Length;
  40.                     while (numSlicesToWrite > 0)
  41.                     {
  42.                         var blockSize = Math.Min(numSlicesToWrite, inputBuffer.Length);
  43.                         inputReader.Read(inputBuffer, 0, blockSize);
  44.                         offsetReader.Read(offsetBuffer, 0, blockSize);
  45.                         countReader.Read(countBuffer, 0, blockSize);
  46.  
  47.                         for (int i = 0; i < blockSize; i++)
  48.                         {
  49.                             inputBuffer[i] = inputBuffer[i].GetRange(offsetBuffer[i], countBuffer[i]);
  50.                         }
  51.  
  52.                         numSlicesToWrite -= outputWriter.Write(inputBuffer, 0, blockSize);
  53.                     }
  54.                 }
  55.             }
  56.             finally
  57.             {
  58.                 MemoryPool<IInStream<T>>.PutArray(inputBuffer);
  59.                 MemoryPool<int>.PutArray(offsetBuffer);
  60.                 MemoryPool<int>.PutArray(countBuffer);
  61.             }
  62.         }
  63.     }
Add Comment
Please, Sign In to add comment