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)); }
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; }
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); } }
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++; }
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); }
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; } }
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()); }
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 }
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)); }
protected EditorFactoryRegistrationAttribute(Type factoryType, short nameResourceID) { Contract.Requires <ArgumentNullException>(factoryType != null, "factoryType"); _factoryType = factoryType; _nameResourceID = nameResourceID; _trustLevel = __VSEDITORTRUSTLEVEL.ETL_NeverTrusted; }
/// <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; }
public JavaQuickInfoSource(ITextBuffer textBuffer, JavaQuickInfoSourceProvider provider) { Contract.Requires <ArgumentNullException>(textBuffer != null, "textBuffer"); Contract.Requires <ArgumentNullException>(provider != null, "provider"); _textBuffer = textBuffer; _provider = provider; }
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; }
/// <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); }
/// <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); }
public ProvideLinkedEditorFactoryAttribute(Type factoryType, Type linkedFactoryType, short nameResourceID) : base(factoryType, nameResourceID) { Contract.Requires(factoryType != null); Contract.Requires <ArgumentNullException>(linkedFactoryType != null, "linkedFactoryType"); _linkedFactoryType = linkedFactoryType; }
/// <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; }
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)); }
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); }
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(); }
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(); }
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); }
protected virtual void TryBindRule(RuleBinding ruleBinding, Nfa nfa) { Contract.Requires(ruleBinding != null); if (nfa == null) { return; } Nfa.BindRule(ruleBinding, nfa); }
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); }
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); }
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 }
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); }
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()); } }
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++; }