コード例 #1
0
        public static IEnumerable <IBinaryTreeNode> TraverseSubtree(this IBinaryTreeNode partialroot, TraverseOrder order = TraverseOrder.InOrder)
        {
            Contract.Requires <ArgumentNullException>(partialroot != null);
            Contract.Ensures(Contract.Result <IEnumerable <IBinaryTreeNode> >() != null);

            return(partialroot.TraverseSubtree <object>(null, null, null, order).Select(res => res.Item1));
        }
コード例 #2
0
 public EqualityComparerCompatibleComparerDecorator(IComparer <T> comparer, IEqualityComparer <T> equalityComparer)
 {
     Contract.Requires <ArgumentNullException>(!ReferenceEquals(comparer, null));
     Contract.Requires <ArgumentNullException>(!ReferenceEquals(equalityComparer, null));
     this.comparer         = comparer;
     this.equalityComparer = equalityComparer;
 }
コード例 #3
0
        public static int GetDegree(this IBinaryTreeNode node)
        {
            Contract.Requires <ArgumentNullException>(node != null);
            Contract.Ensures(Contract.Result <int>() >= 0 && Contract.Result <int>() <= 2);

            if (SentinelEx.NotEqualNull(node.LeftChild))
            {
                if (SentinelEx.NotEqualNull(node.RightChild))
                {
                    return(2);
                }
                else
                {
                    return(1);
                }
            }
            else if (SentinelEx.NotEqualNull(node.RightChild))
            {
                return(1);
            }
            else
            {
                return(0);
            }
        }
コード例 #4
0
        public void InsertRange(int index, IEnumerable <TData> collection)
        {
            Contract.Requires <ArgumentOutOfRangeException>(index >= 0 && index <= Count);

            var itor = collection.GetEnumerator();
            var node = Find(ref index);

            node.Split(index, _new);
            var next = node.Next;

            while (itor.MoveNext())
            {
                if (node.Count >= node.Capacity)
                {
                    node.Next     = new UnrolledLinkedListNode <TData>(blocksize);
                    node          = node.Next;
                    next.Previous = node;
                }

                node.Insert(node.Count, itor.Current, _new); // Append to last node
                Count++;
            }

            Version++;
        }
コード例 #5
0
        internal static int IndexOf <T>(this IEnumerable <T> list, T item)
        {
            Contract.Requires <ArgumentNullException>(list != null);

            var itor  = list.GetEnumerator();
            int count = 0;

            if (ReferenceEquals(item, null))
            {
                while (itor.MoveNext())
                {
                    if (ReferenceEquals(itor.Current, null))
                    {
                        return(count);
                    }
                    count++;
                }
            }
            else
            {
                var comparer = EqualityComparer <T> .Default;
                while (itor.MoveNext())
                {
                    if (comparer.Equals(itor.Current, item))
                    {
                        return(count);
                    }
                    count++;
                }
            }
            return(-1);
        }
コード例 #6
0
        public Antlr4BackgroundParser(ITextBuffer textBuffer, TaskScheduler taskScheduler, ITextDocumentFactoryService textDocumentFactoryService, IOutputWindowService outputWindowService)
            : base(textBuffer, taskScheduler, textDocumentFactoryService, outputWindowService)
        {
            Contract.Requires(textBuffer != null);
            Contract.Requires(taskScheduler != null);
            Contract.Requires(textDocumentFactoryService != null);
            Contract.Requires(outputWindowService != null);

            if (!_initialized)
            {
                try
                {
#if false
                    // have to create an instance of the tool to make sure the error manager gets initialized
                    new AntlrTool();
#endif
                }
                catch (Exception e)
                {
                    if (ErrorHandler.IsCriticalException(e))
                    {
                        throw;
                    }
                }


                _initialized = true;
            }
        }
コード例 #7
0
        private static void ExportDot(IList <string> tokenNames, List <RuleBinding> rules, HashSet <State> reachableStates, Dictionary <int, RuleBinding> stateRules, string path)
        {
            Contract.Requires(rules != null);
            Contract.Requires(reachableStates != null);
            Contract.Requires(stateRules != null);

            StringBuilder builder = new StringBuilder();

            builder.AppendLine("digraph G {");

            foreach (var rule in rules)
            {
                builder.AppendLine(string.Format("subgraph rule_{0} {{", rule.Name));

                foreach (var state in reachableStates.Where(i => stateRules[i.Id] == rule))
                {
                    builder.AppendLine(string.Format("state_{0}[label=\"{1}\"]", state.Id, GetStateLabel(state)));
                }

                builder.AppendLine(string.Format("label = \"{0}\"", rule.Name));
                builder.AppendLine("}");
            }

            foreach (var state in reachableStates)
            {
                // now define the transitions
                foreach (var transition in state.OutgoingTransitions)
                {
                    builder.AppendLine(string.Format("state_{0} -> state_{1}[label=\"{2}\"]", transition.SourceState.Id, transition.TargetState.Id, GetTransitionLabel(transition, tokenNames)));
                }
            }

            builder.AppendLine("}");
            System.IO.File.WriteAllText(path, builder.ToString());
        }
コード例 #8
0
        public void PrintTo(TextWriter textOut)
        {
            Contract.Requires <ArgumentNullException>(textOut != null);

            if (Count == 0)
            {
                textOut.WriteLine("Null Unrolled Linked List");
            }

            var node = head;

            node.PrintTo(textOut);

            while (node.Next != head)
            {
                node = node.Next;
                textOut.Write("->");
                node.PrintTo(textOut);
            }

#if DEBUG
            textOut.Write($", hot at [{_hotindex}]:");
            _hotnode?.PrintTo(textOut);
#endif
        }
コード例 #9
0
        public static IEnumerable <IMultiwayTreeNode> TraverseSubtree(this IMultiwayTreeNode partialroot, TraverseOrder order = TraverseOrder.LevelOrder)
        {
            Contract.Requires <ArgumentNullException>(partialroot != null);
            Contract.Requires <NotSupportedException>(order != TraverseOrder.InOrder, "多叉树不支持中序遍历");
            Contract.Ensures(Contract.Result <IEnumerable <IMultiwayTreeNode> >() != null);

            return(partialroot.TraverseSubtree <object>(null, null, order).Select(res => res.Item1));
        }
コード例 #10
0
        protected EditorFactoryRegistrationAttribute(Type factoryType, short nameResourceID)
        {
            Contract.Requires <ArgumentNullException>(factoryType != null, "factoryType");

            _factoryType    = factoryType;
            _nameResourceID = nameResourceID;
            _trustLevel     = __VSEDITORTRUSTLEVEL.ETL_NeverTrusted;
        }
コード例 #11
0
        /// <summary>
        /// Initializes a new instance of the EventSourceActivity class that
        /// is attached to the specified event source. The new activity will
        /// be attached to the parent activity as specified by
        /// parentActivityId.
        /// The activity is created in the Initialized state. Call Start() to
        /// write the activity's Start event.
        /// </summary>
        /// <param name="eventSource">
        /// The event source to which the activity events should be written.
        /// </param>
        /// <param name="startStopOptions">
        /// The options to use for the start and stop events of the activity.
        /// Note that the Opcode property will be ignored.
        /// </param>
        /// <param name="parentActivityId">
        /// The id of the parent activity to which this new activity
        /// should be attached.
        /// </param>
        internal EventSourceActivity(EventSource eventSource, EventSourceOptions startStopOptions, Guid parentActivityId)
        {
            Contract.Requires <ArgumentNullException>(eventSource != null, nameof(eventSource));

            _eventSource      = eventSource;
            _startStopOptions = startStopOptions;
            _parentId         = parentActivityId;
        }
コード例 #12
0
        public JavaQuickInfoSource(ITextBuffer textBuffer, JavaQuickInfoSourceProvider provider)
        {
            Contract.Requires <ArgumentNullException>(textBuffer != null, "textBuffer");
            Contract.Requires <ArgumentNullException>(provider != null, "provider");

            _textBuffer = textBuffer;
            _provider   = provider;
        }
コード例 #13
0
        public Nfa(State startState, State endState)
        {
            Contract.Requires <ArgumentNullException>(startState != null, "startState");
            Contract.Requires <ArgumentNullException>(endState != null, "endState");

            StartState = startState;
            EndState   = endState;
        }
        public ProvideDebuggerExceptionKindAttribute(string debugEngineGuid, string exceptionKind)
        {
            Contract.Requires <ArgumentNullException>(debugEngineGuid != null, "debugEngineGuid");
            Contract.Requires <ArgumentNullException>(exceptionKind != null, "exceptionKind");

            _debugEngine   = Guid.Parse(debugEngineGuid);
            _exceptionKind = exceptionKind;
        }
コード例 #15
0
        /// <summary>
        /// Writes a Stop event with the specified name. Sets the activity
        /// to the Stopped state.
        /// May only be called when the activity is in the Started state.
        /// </summary>
        /// <param name="eventName">
        /// The name to use for the event. Must not be null.
        /// </param>
        internal void Stop(string eventName)
        {
            Contract.Requires <ArgumentNullException>(eventName != null, nameof(eventName));

            var data = EmptyStruct.Instance;

            Stop(eventName, ref data);
        }
コード例 #16
0
        /// <summary>
        /// Writes an event associated with this activity.
        /// May only be called when the activity is in the Started state.
        /// </summary>
        /// <param name="eventName">
        /// The name to use for the event. Must not be null.
        /// </param>
        /// <param name="options">
        /// The options to use for the event.
        /// </param>
        internal void Write(string eventName, EventSourceOptions options)
        {
            Contract.Requires <ArgumentNullException>(eventName != null, nameof(eventName));

            var data = EmptyStruct.Instance;

            Write(eventName, ref options, ref data);
        }
コード例 #17
0
        public ProvideLinkedEditorFactoryAttribute(Type factoryType, Type linkedFactoryType, short nameResourceID)
            : base(factoryType, nameResourceID)
        {
            Contract.Requires(factoryType != null);
            Contract.Requires <ArgumentNullException>(linkedFactoryType != null, "linkedFactoryType");

            _linkedFactoryType = linkedFactoryType;
        }
コード例 #18
0
        /// <summary>
        /// Initializes a new instance of the EventSourceActivity class that
        /// is attached to the specified parent activity.
        /// The activity is created in the Initialized state. Call Start() to
        /// write the activity's Start event.
        /// </summary>
        /// <param name="parentActivity">
        /// The parent activity. Activity events will be written
        /// to the event source attached to this activity.
        /// </param>
        /// <param name="startStopOptions">
        /// The options to use for the start and stop events of the activity.
        /// Note that the Opcode property will be ignored.
        /// </param>
        internal EventSourceActivity(EventSourceActivity parentActivity, EventSourceOptions startStopOptions)
        {
            Contract.Requires <ArgumentNullException>(parentActivity != null, nameof(parentActivity));

            _eventSource      = parentActivity.EventSource;
            _startStopOptions = startStopOptions;
            _parentId         = parentActivity.Id;
        }
コード例 #19
0
        public static void BindRule(RuleBinding ruleBinding, Nfa body)
        {
            Contract.Requires <ArgumentNullException>(ruleBinding != null, "ruleBinding");
            Contract.Requires <ArgumentNullException>(body != null, "body");

            ruleBinding.StartState.AddTransition(new EpsilonTransition(body.StartState));
            body.EndState.AddTransition(new EpsilonTransition(ruleBinding.EndState));
        }
コード例 #20
0
 public Antlr4BackgroundParser(ITextBuffer textBuffer, TaskScheduler taskScheduler, ITextDocumentFactoryService textDocumentFactoryService, IOutputWindowService outputWindowService)
     : base(textBuffer, taskScheduler, textDocumentFactoryService, outputWindowService)
 {
     Contract.Requires(textBuffer != null);
     Contract.Requires(taskScheduler != null);
     Contract.Requires(textDocumentFactoryService != null);
     Contract.Requires(outputWindowService != null);
 }
コード例 #21
0
        private void BeginUpdateQuickInfoContent(IQuickInfoSession session, SnapshotPoint triggerPoint)
        {
            Contract.Requires(session != null);

            Action updateAction = () => UpdateQuickInfoContent(session, triggerPoint);

            Task.Factory.StartNew(updateAction, CancellationToken.None, TaskCreationOptions.None, Provider.PriorityIntelliSenseTaskScheduler).HandleNonCriticalExceptions();
        }
コード例 #22
0
        public void Reverse(int index, int count)
        {
            Contract.Requires <ArgumentOutOfRangeException>(index >= 0);
            Contract.Requires <ArgumentOutOfRangeException>(count >= 0);
            Contract.Requires <ArgumentOutOfRangeException>(index + count <= Count);

            throw new NotImplementedException();
        }
コード例 #23
0
        public RuleBinding(string name)
            : this(name, new State(), new State())
        {
            Contract.Requires(!String.IsNullOrEmpty(name));

            Contract.Ensures(!string.IsNullOrEmpty(this.Name));
            Contract.Ensures(this.StartState != null);
            Contract.Ensures(this.EndState != null);
        }
コード例 #24
0
        protected virtual void TryBindRule(RuleBinding ruleBinding, Nfa nfa)
        {
            Contract.Requires(ruleBinding != null);
            if (nfa == null)
            {
                return;
            }

            Nfa.BindRule(ruleBinding, nfa);
        }
コード例 #25
0
        public AntlrClassifierBase(ITextBuffer textBuffer)
        {
            Contract.Requires <ArgumentNullException>(textBuffer != null, "textBuffer");

            _textBuffer = textBuffer;

            _lineStates.AddRange(Enumerable.Repeat(LineStateInfo.Dirty, textBuffer.CurrentSnapshot.LineCount));
            SubscribeEvents();
            ForceReclassifyLines(0, textBuffer.CurrentSnapshot.LineCount - 1);
        }
コード例 #26
0
        private static bool IsMultilineClassificationSpan(ClassificationSpan span)
        {
            Contract.Requires <ArgumentNullException>(span != null, "span");

            if (span.Span.IsEmpty)
            {
                return(false);
            }

            return(span.Span.Start.GetContainingLine().LineNumber != span.Span.End.GetContainingLine().LineNumber);
        }
コード例 #27
0
ファイル: UnitOfWork.cs プロジェクト: ivankrutik/HalfBlood
        public UnitOfWork(ISession session)
        {
            Contract.Requires(session != null, "The session must be is not null");

            //_serviceFactory = ServiceLocator.Container.GetExportedValue<IServiceFactory>();
            _session     = session;
            _transaction = session.BeginTransaction(IsolationLevel.ReadCommitted);
#if !RELEASE
            LogManager.Log.Debug("START TRANSACTION");
#endif
        }
コード例 #28
0
        public static T LoadPackage <T>(this IVsShell shell)
            where T : Package
        {
            Contract.Requires <ArgumentNullException>(shell != null, "shell");

            Guid       guid = typeof(T).GUID;
            IVsPackage package;

            ErrorHandler.ThrowOnFailure(shell.LoadPackage(ref guid, out package));
            return((T)package);
        }
コード例 #29
0
        public static IEnumerable <T> HeapSort <T>(this IEnumerable <T> data, IComparer <T> comparer)
        {
            Contract.Requires <ArgumentNullException>(data != null);
            Contract.Requires <ArgumentNullException>(comparer != null);
            BinaryHeap <T> heap = new BinaryHeap <T>(data, comparer);

            while (heap.Count > 0)
            {
                yield return(heap.ExtractMin());
            }
        }
コード例 #30
0
        public void Insert(int index, TData item)
        {
            Contract.Requires <ArgumentOutOfRangeException>(index >= 0 && index <= Count);

            var loc = Find(ref index);

            loc.Insert(index, item, _new);

            Version++;
            Count++;
        }