Exemplo n.º 1
0
        // Toposort 2, node rescanning using a view.
        // Uses no method call stack and no extra data structures, but slower.
        public static IList <MyNode <T> > Toposort2 <T>(params MyNode <T>[] starts)
        {
            var sorted = new HashedLinkedList <MyNode <T> >();

            foreach (MyNode <T> start in starts)
            {
                if (!sorted.Contains(start))
                {
                    sorted.InsertLast(start);
                    using (IList <MyNode <T> > cursor = sorted.View(sorted.Count - 1, 1))
                    {
                        do
                        {
                            MyNode <T> child;
                            while ((child = PendingChild(sorted, cursor.First)) != null)
                            {
                                cursor.InsertFirst(child);
                                cursor.Slide(0, 1);
                            }
                        }while (cursor.TrySlide(+1));
                    }
                }
            }

            return(sorted);
        }
Exemplo n.º 2
0
        /*
         * This is the central method of the whole Dataflow engine as it executes the patches.
         *
         * A breath first search over the entire graph is done, starting from the rootSet.
         * All patches that have no connected inlets are part of the rootSet.
         *
         * The algorith is the follow
         *
         * 1) push all elements from the root set into the execution queue
         *
         * 2) dequeue a patch from the execution queue
         * 3) if execution criteria is met execute it *1
         * 4) propagate the values of all changed outlets and add the receiving patches to the discovered set *2 *3
         * 5) goto to step 2 if the execution queue is not empty
         * 6) move all elements from the discovered set to the execution queue
         * 7) goto step 2 if the execution queue is not empty
         * 8) finish the frame
         *
         * *1 right now the only criteria is 'execute allways'
         * *2 outlet values propagation and patch enqueuing are done from first to last outlet.
         * *3 order of discovery is maintained during execution.
         */
        public void StepFrame()
        {
            LinkedList <IPatchContainer>       executionQueue = new LinkedList <IPatchContainer> ();
            HashedLinkedList <IPatchContainer> discoveredSet  = new HashedLinkedList <IPatchContainer> ();

            executionQueue.AddAll(this.rootSet);

            do
            {
                while (executionQueue.Count > 0)
                {
                    IPatchContainer patch = executionQueue.RemoveFirst();
                    patch.ExecutePatch();
                    foreach (IOutlet outlet in patch.Outlets)
                    {
                        outlet.PropagateChanges(discoveredSet);
                    }
                }
                if (discoveredSet.Count > 0)
                {
                    executionQueue.AddAll(discoveredSet);
                    discoveredSet.Clear();
                }
            } while (executionQueue.Count > 0);
        }
Exemplo n.º 3
0
        public RendezvousCluster(IConfigurationStorage <RendezvousClusterConfiguration> configurationStorage)
        {
            this.configurationStorage = configurationStorage;

            config = new HashedLinkedList <RendezvousEndpoint>();
            config.AddAll(configurationStorage.Read().Cluster);
        }
Exemplo n.º 4
0
        public RendezvousCluster(IConfigurationStorage<RendezvousClusterConfiguration> configurationStorage)
        {
            this.configurationStorage = configurationStorage;

            config = new HashedLinkedList<RendezvousEndpoint>();
            config.AddAll(configurationStorage.Read().Cluster);
        }
Exemplo n.º 5
0
        public void Update(RendezvousClusterConfiguration newConfig)
        {
            var tmp = new HashedLinkedList <RendezvousEndpoint>();

            tmp.AddAll(SelectEndpointsDistinct(newConfig.Cluster));

            config = tmp;
        }
Exemplo n.º 6
0
    public static void Main()
    {
        HashedLinkedList <int> .Test(5);

        HashedLinkedList <long> list = new HashedLinkedList <long> ();

        list.Test(list);
    }
Exemplo n.º 7
0
        public HashedLinkedList <T> CopyToHashedLinkedList <T>(ICollection <T> lst)
        {
            HashedLinkedList <T> lstCopy = new HashedLinkedList <T>();

            foreach (var item in lst)
            {
                lstCopy.Add((T)item);
            }
            return(lstCopy);
        }
Exemplo n.º 8
0
        // --- Other view patterns --------------------------------------

        // Replace the first occurrence of each x from xs by y in list:

        public static void ReplaceXsByY <T>(HashedLinkedList <T> list, T[] xs, T y)
        {
            foreach (T x in xs)
            {
                using (IList <T> view = list.ViewOf(x)) {
                    if (view != null)
                    {
                        view.Remove();
                        view.Add(y);
                    }
                }
            }
        }
Exemplo n.º 9
0
        // Toposort 0, adding each node when finished, after its descendants.
        // Classic depth-first search.  Does not terminate on cyclic graphs.

        public static IList <Node <T> > Toposort0 <T>(params Node <T>[] starts)
        {
            HashedLinkedList <Node <T> > sorted = new HashedLinkedList <Node <T> >();

            foreach (Node <T> start in starts)
            {
                if (!sorted.Contains(start))
                {
                    AddNode0(sorted, start);
                }
            }
            return(sorted);
        }
Exemplo n.º 10
0
        private static IEnumerable <RendezvousEndpoint> SelectEndpointsDistinct(IEnumerable <RendezvousEndpoint> initialConfiguration)
        {
            var tmp = new HashedLinkedList <RendezvousEndpoint>();

            tmp.AddAll(initialConfiguration);

            if (tmp.Count < initialConfiguration.Count())
            {
                throw new DuplicatedKeyException("Initial Rendezvous configuration contains duplicated endpoints!");
            }

            return(tmp);
        }
Exemplo n.º 11
0
        private void MapMessageToNode(ExternalRouteRegistration routeRegistration, ReceiverIdentifier nodeIdentifier)
        {
            var messageIdentifier = routeRegistration.Route.Message;

            if (!messageToNodeMap.TryGetValue(messageIdentifier, out var nodes))
            {
                nodes = new HashedLinkedList <ReceiverIdentifier>();
                messageToNodeMap[messageIdentifier] = nodes;
            }
            if (!nodes.Contains(nodeIdentifier))
            {
                nodes.InsertLast(nodeIdentifier);
            }
        }
Exemplo n.º 12
0
 private void MapMessageToActor(InternalRouteRegistration routeRegistration, MessageContract messageContract)
 {
     if (!messageToActorMap.TryGetValue(messageContract.Message, out var actors))
     {
         actors = new HashedLinkedList <ReceiverIdentifier>();
         messageToActorMap[messageContract.Message] = actors;
     }
     if (!actors.Contains(routeRegistration.ReceiverIdentifier))
     {
         var registration = new ReceiverIdentifierRegistration(routeRegistration.ReceiverIdentifier,
                                                               messageContract.KeepRegistrationLocal);
         actors.InsertLast(registration);
     }
 }
Exemplo n.º 13
0
        // Toposort 1, using hash index to add each node before its descendants.
        // Terminates also on cyclic graphs.
        public static IList <MyNode <T> > Toposort1 <T>(params MyNode <T>[] starts)
        {
            var sorted = new HashedLinkedList <MyNode <T> >();

            foreach (var start in starts)
            {
                if (!sorted.Contains(start))
                {
                    sorted.InsertLast(start);
                    AddNode1(sorted, start);
                }
            }

            return(sorted);
        }
Exemplo n.º 14
0
        private static T Get <T>(HashedLinkedList <T> hashSet)
        {
            var count = hashSet.Count;

            if (count > 0)
            {
                var first = (count > 1) ? hashSet.RemoveFirst() : hashSet.First;
                if (count > 1)
                {
                    hashSet.InsertLast(first);
                }
                return(first);
            }

            return(default(T));
        }
Exemplo n.º 15
0
        public void Main()
        {
            var list = new HashedLinkedList <int> {
                2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59
            };

            // View of item
            list.ViewOf(2);

            // Last view of item
            list.LastViewOf(11);

            // View in range
            var view = list.View(0, 3);

            // Slide with offset
            view.Slide(3);

            // Slide with offset and set lenght
            view.Slide(-3, 3);

            // Try slide with offset and set lenght
            var hasSucceed = view.TrySlide(-10, 3);

            // Try slide with offset and set lenght
            view.TrySlide(3, -3);

            var view2 = list.View(0, 3);
            var view3 = list.View(1, 3);

            // Check if views overlap
            Overlap(view2, view3);

            // Check if views contained in each other
            ContainsView(view2, view3);

            // Span views
            var spannedView = view2.Span(view3);

            // Invalidate all views by shuffle
            list.Shuffle();

            // Check if view is valid
            Console.WriteLine($"View is valid? {view.IsValid}");
        }
Exemplo n.º 16
0
    public static void Main(String[] args) {
      HashedLinkedList<int> test = new HashedLinkedList<int>();
      for (int i = 0; i < 33; i++) {
        test.Add(i);
      } // for

      // Fails after 7 removals
      for (int i = 0; i < 33; i++) {
        Console.WriteLine(i);
        test.Remove(i);
      } // for

      // Fails after 23 removals
//        for (int i = 32; i >= 0; i--) {
//          Console.WriteLine(i);
//          test.Remove(i);
//        } // for
    }
Exemplo n.º 17
0
        public override void CreateNewInstanceOfInternalC5DataStructure(C5DataStructure dataStructure)
        {
            switch (dataStructure)
            {
            case C5DataStructure.ArrayList:
                InternalC5DataStructure = new ArrayList <T>();
                break;

            case C5DataStructure.LinkedList:
                InternalC5DataStructure = new LinkedList <T>();
                break;

            case C5DataStructure.HashBag:
                InternalC5DataStructure = new HashBag <T>();
                break;

            case C5DataStructure.TreeBag:
                InternalC5DataStructure = new TreeBag <T>();
                break;

            case C5DataStructure.HashedArrayList:
                InternalC5DataStructure = new HashedArrayList <T>();
                break;

            case C5DataStructure.HashedLinkedList:
                InternalC5DataStructure = new HashedLinkedList <T>();
                break;

            case C5DataStructure.SortedArray:
                InternalC5DataStructure = new SortedArray <T>();
                break;

            case C5DataStructure.HashSet:
                InternalC5DataStructure = new HashSet <T>();
                break;

            case C5DataStructure.TreeSet:
                InternalC5DataStructure = new TreeSet <T>();
                break;

            default: throw new ArgumentException("Unknown C5 Collection name");
            }
        }
        public void Add(T item, int priority = 0)
        {
            int oldPriority;

            if (sub.UpdateOrAdd(item, priority, out oldPriority))
            {
                RemoveMain(oldPriority, item);
            }
            if (reserveList == null)
            {
                reserveList = new HashedLinkedList <T>(cmp);
            }
            var list = reserveList;

            if (!main.FindOrAdd(priority, ref list))
            {
                reserveList = null;
            }
            list.Add(item);
        }
    public DetailConfiguration()
    {
      var columns = new ColumnCollection( this.DataGridControl, this );

      this.SetColumns( columns );
      this.Columns.CollectionChanged += new NotifyCollectionChangedEventHandler( this.OnColumnsCollectionChanged );
      VisibilityChangedEventManager.AddListener( this.Columns, this );

      this.SetVisibleColumns( new ReadOnlyColumnCollection() );

      m_columnsByVisiblePosition = new HashedLinkedList<ColumnBase>();
      m_columnSynchronizationManager = new ColumnSynchronizationManager( this );

      this.SetHeaders( new ObservableCollection<DataTemplate>() );
      this.SetFooters( new ObservableCollection<DataTemplate>() );

      this.SetGroupLevelDescriptions( new GroupLevelDescriptionCollection() );
      this.SetDetailConfigurations( new DetailConfigurationCollection( this.DataGridControl, this ) );
      CollectionChangedEventManager.AddListener( this.DetailConfigurations, this );

    }
Exemplo n.º 20
0
        public static void Main(String[] args)
        {
            HashedLinkedList <int> test = new HashedLinkedList <int>();

            for (int i = 0; i < 33; i++)
            {
                test.Add(i);
            } // for

            // Fails after 7 removals
            for (int i = 0; i < 33; i++)
            {
                Console.WriteLine(i);
                test.Remove(i);
            } // for

            // Fails after 23 removals
//        for (int i = 32; i >= 0; i--) {
//          Console.WriteLine(i);
//          test.Remove(i);
//        } // for
        }
Exemplo n.º 21
0
        public static void Main()
        {
            var test = new HashedLinkedList <int>();

            for (var i = 0; i < 33; i++)
            {
                test.Add(i);
            }

            // Fails after 7 removals
            for (var i = 0; i < 33; i++)
            {
                Console.WriteLine(i);
                test.Remove(i);
            }

            // Fails after 23 removals
            for (var i = 32; i >= 0; i--)
            {
                Console.WriteLine(i);
                test.Remove(i);
            }
        }
Exemplo n.º 22
0
 public RoundRobinDestinationList(ILogger logger)
 {
     this.logger  = logger;
     destinations = new HashedLinkedList <IDestination>();
 }
    // Returns the visible index of a column by its visible position
    internal static int CalculateVisibleIndex( int visiblePosition, HashedLinkedList<ColumnBase> columnsByVisiblePosition )
    {
      if( columnsByVisiblePosition == null )
        return -1;

      int visibleIndex = 0;
      LinkedListNode<ColumnBase> tempNode = columnsByVisiblePosition.First;

      for( int i = 0; i < visiblePosition; i++ )
      {
        if( tempNode == null )
          break;

        if( tempNode.Value.Visible )
        {
          visibleIndex++;
        }

        tempNode = tempNode.Next;
      }

      return visibleIndex;
    }
Exemplo n.º 24
0
        public RendezvousClusterConfigurationReadonlyStorage(IEnumerable <RendezvousEndpoint> initialConfiguration)
        {
            config = new HashedLinkedList <RendezvousEndpoint>();

            config.AddAll(SelectEndpointsDistinct(initialConfiguration));
        }
Exemplo n.º 25
0
 public HashedQueue(int maxQueueLength)
 {
     this.maxQueueLength = maxQueueLength;
     collection          = new HashedLinkedList <T>();
 }
Exemplo n.º 26
0
 public Recording()
 {
     Keyframes = new HashedLinkedList <Keyframe>();
 }
Exemplo n.º 27
0
    public bool SelectItemCells(
      int itemIndex,
      object item,
      HashedLinkedList<ColumnBase> columnsByVisiblePosition,
      bool preserveSelection )
    {
      bool selectionDone = true;
      int columnsCount = columnsByVisiblePosition.Count;
      m_toDeferSelect.Clear();

      SelectionCellRangeWithItems rangeWithItemsToSelect =
        new SelectionCellRangeWithItems(
        new SelectionRange( itemIndex ),
        new object[] { item },
        new SelectionRange( 0, columnsCount - 1 ) );

      SelectionCellRange cellRange = rangeWithItemsToSelect.CellRange;

      m_cellsToSelect.Clear();
      SelectedCellsStorage selectedCellsInChange = m_owner.SelectedCellsStore;

      // Remove all currently selected Cells from the new selectionRange
      // to avoid duplicate SelectionCellRange
      SelectedCellsStorage tempStorage = new SelectedCellsStorage( null, 1 );
      tempStorage.Add( rangeWithItemsToSelect );

      for( int i = 0; i < selectedCellsInChange.Count; i++ )
      {
        tempStorage.Remove( selectedCellsInChange[ i ] );
      }

      foreach( ColumnBase column in columnsByVisiblePosition )
      {
        if( !column.Visible )
          tempStorage.Remove( new SelectionCellRangeWithItems( itemIndex, item, column.VisiblePosition ) );
      }

      int tempStorageCount = tempStorage.Count;

      // All Cells are already selected
      if( tempStorageCount == 0 )
      {
        if( !m_cellsToUnselect.Contains( cellRange ) )
          selectionDone = false;

        m_cellsToUnselect.Clear();

        if( !preserveSelection )
        {
          foreach( SelectionCellRangeWithItems selectedCellRangeWithItems in selectedCellsInChange )
          {
            m_cellsToUnselect.Add( selectedCellRangeWithItems );
          }
        }

        m_cellsToUnselect.Remove( rangeWithItemsToSelect );
      }
      else
      {
        // Add each range to selection
        for( int i = 0; i < tempStorageCount; i++ )
        {
          m_cellsToSelect.Add( tempStorage[ i ] );
        }

        m_cellsToUnselect.Clear();

        if( !preserveSelection )
        {
          foreach( SelectionCellRangeWithItems selectedCellRangeWithItems in selectedCellsInChange )
          {
            tempStorage = new SelectedCellsStorage( null, 1 );
            tempStorage.Add( selectedCellRangeWithItems );
            tempStorage.Remove( rangeWithItemsToSelect );
            tempStorageCount = tempStorage.Count;

            for( int i = 0; i < tempStorageCount; i++ )
            {
              m_cellsToUnselect.Add( tempStorage[ i ] );
            }
          }
        }
      }

      if( !preserveSelection )
        this.UnselectAllItems();

      return selectionDone;
    }
Exemplo n.º 28
0
 public void Test(HashedLinkedList <T> view)
 {
     view.Offset--;
 }
Exemplo n.º 29
0
        public void Main()
        {
            // Construct hashed array list using collection initializer
            var list = new HashedLinkedList <int> {
                2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59
            };

            // Chose from list
            list.Choose();

            var array = new int[list.Count];

            // Copy list to array
            list.CopyTo(array, 0);

            // Add item to the end of list
            list.Add(61);

            // Add range to list
            array = new[] { 67, 71, 73, 79, 83 };
            list.AddRange(array);

            // Check if list contains an item
            list.Contains(list.Choose());

            // Check if list contains all items in enumerable
            list.ContainsRange(array);

            // Count all occuerence of an item
            list.CountDuplicates(list.Choose());

            // Find an item in list
            var itemToFind = list.Last;

            list.Find(ref itemToFind);

            // Return all occurence of an item
            list.FindDuplicates(itemToFind);

            // Remove within range
            list.RemoveIndexRange(0, 3);

            var range = new[] { list.First, list.Last };

            // Remove all items in enumerable from list
            list.RemoveRange(range);

            // Retain all items in enumarable from list
            list.RetainRange(list.ToArray());

            var lastItem = list.Last;

            // Find last index of an item
            list.LastIndexOf(lastItem);

            // Insert at the end of list
            list.InsertLast(100);

            // Insert at the beginning of list
            list.InsertFirst(-100);

            // Reverse list
            list.Reverse();

            // Shuffle list
            list.Shuffle();

            // Sort list
            list.Sort();

            // Check if list is sorted
            var isSorted = list.IsSorted();

            // Print all items in list by indexer
            var index = 0;

            foreach (var item in list)
            {
                Console.WriteLine($"list[{index++}] = {item}");
            }

            // Clear list
            list.Clear();
        }