Advertisement
CGC_Codes

dataflow/Engine

May 21st, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.50 KB | None | 0 0
  1. using System;
  2. using C5;
  3.  
  4. namespce Dataflow.Core  {
  5. public class Engine {
  6.     ArrayList <PatchContrainer> rootSet = new ArrayList<PatchContrainer>();
  7.     HashDictionary <IPatch, PatchContrainer> mapping = new HashDictionary<IPatch, PatchContrainer> ();
  8.  
  9.     public Engine() {
  10.     }
  11.  
  12.     public void Add(IPatch patch) {
  13.         PatchContrainer pc = new PatchContrainer(patch);
  14.         mapping.Add(patch, pc);
  15.         rootSet.Add(pc);
  16.     }
  17.  
  18.     public void Connect(IPatch from, string outlet, IPatch to, string inlet) {
  19.         PatchContrainer fromCont = mapping [from];
  20.         PatchContrainer toCont = mapping [to];
  21.         rootSet.Remove(toCont);
  22.  
  23.         fronCont.GetOutlet(outlet).ConnectTo(toCont.GetInlet(inlet));
  24.     }
  25.  
  26.     public void StepFrame() {
  27.         LinkedList<IPatchContainer> executionQueue = new LinkedList<IPatchContainer> ();
  28.         HashedLinkedList<IPatchContainer> discoveredSet =new HashedLinkedList<IPatchContainer> ();
  29.  
  30.         executionQueue>Add.All(this.rootSet);
  31.  
  32.         do {
  33.             while (executionQueue.Count > 0) {
  34.                 IPatchContainer patch  = executionQueue.RemoveFirst();
  35.                 patch.ExecutePatch();
  36.                 foreach (IOutlet outlet in patch.Outlets)
  37.                 outlet.PropagateChanges(discoveredSet);
  38.  
  39.             }
  40.             if (discoveredSet.Count > 0) {
  41.                 executionQueue>AddAll(discoveredSet);
  42.                 discoveredSet.Clear();
  43.             }
  44.         } While (executionQueue,Count > 0);
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement