public void Dictionary_Generic_Constructor_IDictionary(int count) { IDictionary <TKey, TValue> source = GenericIDictionaryFactory(count); IDictionary <TKey, TValue> copied = new SegmentedDictionary <TKey, TValue>(source); Assert.Equal(source, copied); }
public FormattingContext(AbstractFormatEngine engine, TokenStream tokenStream) { Contract.ThrowIfNull(engine); Contract.ThrowIfNull(tokenStream); _engine = engine; _tokenStream = tokenStream; _relativeIndentationTree = new ContextIntervalTree <RelativeIndentationData, FormattingContextIntervalIntrospector>(new FormattingContextIntervalIntrospector()); _indentationTree = new ContextIntervalTree <IndentationData, FormattingContextIntervalIntrospector>(new FormattingContextIntervalIntrospector()); _suppressWrappingTree = new ContextIntervalTree <SuppressWrappingData, SuppressIntervalIntrospector>(new SuppressIntervalIntrospector()); _suppressSpacingTree = new ContextIntervalTree <SuppressSpacingData, SuppressIntervalIntrospector>(new SuppressIntervalIntrospector()); _suppressFormattingTree = new ContextIntervalTree <SuppressSpacingData, SuppressIntervalIntrospector>(new SuppressIntervalIntrospector()); _anchorTree = new ContextIntervalTree <AnchorData, FormattingContextIntervalIntrospector>(new FormattingContextIntervalIntrospector()); _anchorBaseTokenMap = new SegmentedDictionary <SyntaxToken, AnchorData>(); _indentationMap = new HashSet <TextSpan>(); _suppressWrappingMap = new HashSet <TextSpan>(); _suppressSpacingMap = new HashSet <TextSpan>(); _suppressFormattingMap = new HashSet <TextSpan>(); _anchorMap = new HashSet <TextSpan>(); _initialIndentBlockOperations = new List <IndentBlockOperation>(); }
public void Dictionary_Generic_Constructor_int_IEqualityComparer(int count) { IEqualityComparer <TKey> comparer = GetKeyIEqualityComparer(); SegmentedDictionary <TKey, TValue> dictionary = new SegmentedDictionary <TKey, TValue>(count, comparer); Assert.Empty(dictionary); Assert.Equal(comparer, dictionary.Comparer); }
internal Enumerator(SegmentedDictionary <TKey, TValue> dictionary, int getEnumeratorRetType) { _dictionary = dictionary; _version = dictionary._version; _index = 0; _getEnumeratorRetType = getEnumeratorRetType; _current = default; }
public void Dictionary_Generic_Constructor_IEqualityComparer(int count) { IEqualityComparer <TKey> comparer = GetKeyIEqualityComparer(); IDictionary <TKey, TValue> source = GenericIDictionaryFactory(count); SegmentedDictionary <TKey, TValue> copied = new SegmentedDictionary <TKey, TValue>(source, comparer); Assert.Equal(source, copied); Assert.Equal(comparer, copied.Comparer); }
public void EnsureCapacity_Generic_ExistingCapacityRequested_SameValueReturned(int capacity) { var dictionary = new SegmentedDictionary <TKey, TValue>(capacity); Assert.True(dictionary.EnsureCapacity(capacity) > capacity); dictionary = (SegmentedDictionary <TKey, TValue>)GenericIDictionaryFactory(capacity); Assert.True(dictionary.EnsureCapacity(capacity) > capacity); }
public void Dictionary_Generic_RemoveKey_ValidKeyNotContainedInDictionary(int count) { SegmentedDictionary <TKey, TValue> dictionary = (SegmentedDictionary <TKey, TValue>)GenericIDictionaryFactory(count); TValue value; TKey missingKey = GetNewKey(dictionary); Assert.False(dictionary.Remove(missingKey, out value)); Assert.Equal(count, dictionary.Count); Assert.Equal(default(TValue), value); }
public void EnsureCapacity_Generic_RequestedCapacitySmallerThanCurrent_CapacityUnchanged(int currentCapacity) { SegmentedDictionary <TKey, TValue> dictionary; // assert capacity remains the same when ensuring a capacity smaller or equal than existing for (int i = 0; i <= currentCapacity; i++) { dictionary = new SegmentedDictionary <TKey, TValue>(currentCapacity); Assert.True(dictionary.EnsureCapacity(i) > currentCapacity); } }
public void Dictionary_Generic_RemoveKey_DefaultKeyContainedInDictionary(int count) { if (DefaultValueAllowed) { SegmentedDictionary <TKey, TValue> dictionary = (SegmentedDictionary <TKey, TValue>)(GenericIDictionaryFactory(count)); TKey missingKey = default(TKey); TValue value; dictionary.TryAdd(missingKey, default(TValue)); Assert.True(dictionary.Remove(missingKey, out value)); } }
public void Dictionary_Generic_ContainsValue_NotPresent(int count) { SegmentedDictionary <TKey, TValue> dictionary = (SegmentedDictionary <TKey, TValue>)GenericIDictionaryFactory(count); int seed = 4315; TValue notPresent = CreateTValue(seed++); while (dictionary.Values.Contains(notPresent)) { notPresent = CreateTValue(seed++); } Assert.False(dictionary.ContainsValue(notPresent)); }
public void Dictionary_Generic_Remove_RemoveCurrentEnumerationContinues() { SegmentedDictionary <TKey, TValue> dict = (SegmentedDictionary <TKey, TValue>)GenericIDictionaryFactory(3); using (var enumerator = dict.GetEnumerator()) { enumerator.MoveNext(); enumerator.MoveNext(); dict.Remove(enumerator.Current.Key); Assert.True(enumerator.MoveNext()); Assert.False(enumerator.MoveNext()); } }
public void Dictionary_Generic_RemoveKey_ValidKeyContainedInDictionary(int count) { SegmentedDictionary <TKey, TValue> dictionary = (SegmentedDictionary <TKey, TValue>)GenericIDictionaryFactory(count); TKey missingKey = GetNewKey(dictionary); TValue outValue; TValue inValue = CreateTValue(count); dictionary.Add(missingKey, inValue); Assert.True(dictionary.Remove(missingKey, out outValue)); Assert.Equal(count, dictionary.Count); Assert.Equal(inValue, outValue); Assert.False(dictionary.TryGetValue(missingKey, out outValue)); }
public void Dictionary_Generic_ContainsValue_DefaultValuePresent(int count) { SegmentedDictionary <TKey, TValue> dictionary = (SegmentedDictionary <TKey, TValue>)GenericIDictionaryFactory(count); int seed = 4315; TKey notPresent = CreateTKey(seed++); while (dictionary.ContainsKey(notPresent)) { notPresent = CreateTKey(seed++); } dictionary.Add(notPresent, default(TValue)); Assert.True(dictionary.ContainsValue(default(TValue))); }
public void Dictionary_Generic_ContainsValue_Present(int count) { SegmentedDictionary <TKey, TValue> dictionary = (SegmentedDictionary <TKey, TValue>)GenericIDictionaryFactory(count); int seed = 4315; KeyValuePair <TKey, TValue> notPresent = CreateT(seed++); while (dictionary.Contains(notPresent)) { notPresent = CreateT(seed++); } dictionary.Add(notPresent.Key, notPresent.Value); Assert.True(dictionary.ContainsValue(notPresent.Value)); }
public MemoryGraph(int expectedSize, bool isVeryLargeGraph = false) : base(expectedSize, isVeryLargeGraph) { // If we have too many addresses we will reach the Dictionary's internal array's size limit and throw. // Therefore use a new implementation of it that is similar in performance but that can handle the extra load. if (isVeryLargeGraph) { m_addressToNodeIndex = new SegmentedDictionary <Address, NodeIndex>(expectedSize); } else { m_addressToNodeIndex = new Dictionary <Address, NodeIndex>(expectedSize); } m_nodeAddresses = new SegmentedList <Address>(SegmentSize, expectedSize); }
public void Dictionary_Generic_Remove_RemoveLastEnumerationFinishes() { SegmentedDictionary <TKey, TValue> dict = (SegmentedDictionary <TKey, TValue>)GenericIDictionaryFactory(3); TKey key = default; using (var enumerator = dict.GetEnumerator()) { while (enumerator.MoveNext()) { key = enumerator.Current.Key; } } using (var enumerator = dict.GetEnumerator()) { enumerator.MoveNext(); enumerator.MoveNext(); dict.Remove(key); Assert.False(enumerator.MoveNext()); } }
public void Dictionary_Generic_RemoveKey_DefaultKeyNotContainedInDictionary(int count) { SegmentedDictionary <TKey, TValue> dictionary = (SegmentedDictionary <TKey, TValue>)GenericIDictionaryFactory(count); TValue outValue; if (DefaultValueAllowed) { TKey missingKey = default(TKey); while (dictionary.ContainsKey(missingKey)) { dictionary.Remove(missingKey); } Assert.False(dictionary.Remove(missingKey, out outValue)); Assert.Equal(default(TValue), outValue); } else { TValue initValue = CreateTValue(count); outValue = initValue; Assert.Throws <ArgumentNullException>(() => dictionary.Remove(default(TKey), out outValue)); Assert.Equal(initValue, outValue); } }
public CurrentNodes(SyntaxNode root) { // there could be multiple nodes with same annotation if a tree is rewritten with // same node injected multiple times. var map = new SegmentedDictionary <SyntaxAnnotation, List <SyntaxNode> >(); foreach (var node in root.GetAnnotatedNodesAndTokens(IdAnnotationKind).Select(n => n.AsNode() !)) { Debug.Assert(node is object); foreach (var id in node.GetAnnotations(IdAnnotationKind)) { List <SyntaxNode>?list; if (!map.TryGetValue(id, out list)) { list = new List <SyntaxNode>(); map.Add(id, list); } list.Add(node); } } _idToNodeMap = map.ToImmutableSegmentedDictionary(kv => kv.Key, kv => (IReadOnlyList <SyntaxNode>)ImmutableArray.CreateRange(kv.Value)); }
public void EnsureCapacity_Generic_NegativeCapacityRequested_Throws() { var dictionary = new SegmentedDictionary <TKey, TValue>(); AssertExtensions.Throws <ArgumentOutOfRangeException>("capacity", () => dictionary.EnsureCapacity(-1)); }
internal Enumerator(SegmentedDictionary <TKey, TValue> dictionary, ReturnType returnType) { _dictionary = dictionary; _returnType = returnType; _enumerator = dictionary.GetEnumerator(); }
public void Dictionary_Generic_ContainsValue_DefaultValueNotPresent(int count) { SegmentedDictionary <TKey, TValue> dictionary = (SegmentedDictionary <TKey, TValue>)GenericIDictionaryFactory(count); Assert.False(dictionary.ContainsValue(default(TValue))); }
public void EnsureCapacity_Generic_DictionaryNotInitialized_RequestedZero_ReturnsZero() { var dictionary = new SegmentedDictionary <TKey, TValue>(); Assert.Equal(0, dictionary.EnsureCapacity(0)); }
public void Dictionary_Generic_Constructor_int(int count) { IDictionary <TKey, TValue> dictionary = new SegmentedDictionary <TKey, TValue>(count); Assert.Equal(0, dictionary.Count); }
public void EnsureCapacity_Generic_DictionaryNotInitialized_RequestedNonZero_CapacityIsSetToAtLeastTheRequested(int requestedCapacity) { var dictionary = new SegmentedDictionary <TKey, TValue>(); Assert.InRange(dictionary.EnsureCapacity(requestedCapacity), requestedCapacity, int.MaxValue); }