Example #1
0
        /// <summary>
        /// Initializes and incrementally creates a minimal <see cref="IMinimalDAGNode{T}"/> from a sorted collection of sequences of values.
        /// </summary>
        /// <typeparam name="T">The type to be arranged as a <see cref="IMinimalDAG{T}"/></typeparam>
        /// <param name="sortedSequences">The ascending ordered sequences of <typeparamref name="T"/> to be minimized.</param>
        /// <param name="nodeFactory">Factory for <see cref="IMinimalDAGNode{T}"/> creation</param>
        public MinimalDAG(IEnumerable <IEnumerable <T> > sortedSequences, IMinimalDAGNodeFactory <T> nodeFactory)//, T sourceValue = default(T), T sinkValue = default(T))
        {
            _registrationBySuffix = new HashSet <IMinimalDAGNode <T> >();
            _dagNodeFactory       = nodeFactory ?? new MinimalDAGNodeFactory <T>();
            _nodes  = new Dictionary <Guid, IMinimalDAGNode <T> >();
            _source = _dagNodeFactory.CreateNode(default(T), Guid.NewGuid());
            _sink   = _dagNodeFactory.CreateNode(default(T), Guid.NewGuid());
            _source.Children.Add(_sink.ID);

            _registrationBySuffix.Add(_sink);
            _sink.IsSuffixRegistered = true;

            var LastSequence = new List <T>()
            {
                _sink.Value
            }.DefaultIfEmpty();                                                //lazy but simple fix

            foreach (IEnumerable <T> Sequence in sortedSequences)
            {
                AddNextOrderedSequence(Sequence, LastSequence);
                LastSequence = Sequence;
            }
            HandleExistingSuffixes(_source);
            BuildParentLinks();
            BuildNodesByValueDictionary();
        }
Example #2
0
 public MinimalDAG(IMinimalDAGNode <T> _source, IMinimalDAGNode <T> _sink, IMinimalDAGNodeFactory <T> _dagNodeFactory,
                   Dictionary <Guid, IMinimalDAGNode <T> > _nodes, Dictionary <T, List <Guid> > _nodeIDsByValue, HashSet <Guid> _nodeIDsWithNullValue)
 {
     this._sink                 = _sink;
     this._source               = _source;
     this._nodeIDsByValue       = _nodeIDsByValue;
     this._nodes                = _nodes;
     this._dagNodeFactory       = _dagNodeFactory;
     this._nodeIDsWithNullValue = _nodeIDsWithNullValue;
 }
Example #3
0
 public IMinimalDAG <T> Create(IEnumerable <IEnumerable <T> > orderedSequences, IMinimalDAGNodeFactory <T> dagNodeFactory)
 {
     return(new MinimalDAG <T>(orderedSequences, dagNodeFactory));
 }