提交 5618acc3 编写于 作者: L Lakshmi Priya

Formatting changes to System.Collections.Immutable


Commit migrated from https://github.com/dotnet/corefx/commit/ae985912211b000a4ce1748724691a7e48384efd
上级 edb84305
......@@ -12,14 +12,14 @@ internal static class AllocFreeConcurrentStack<T>
private const int MaxSize = 35;
[ThreadStatic]
private static Stack<RefAsValueType<T>> stack;
private static Stack<RefAsValueType<T>> t_stack;
public static void TryAdd(T item)
{
Stack<RefAsValueType<T>> localStack = stack; // cache in a local to avoid unnecessary TLS hits on repeated accesses
Stack<RefAsValueType<T>> localStack = t_stack; // cache in a local to avoid unnecessary TLS hits on repeated accesses
if (localStack == null)
{
stack = localStack = new Stack<RefAsValueType<T>>(MaxSize);
t_stack = localStack = new Stack<RefAsValueType<T>>(MaxSize);
}
// Just in case we're in a scenario where an object is continually requested on one thread
......@@ -32,7 +32,7 @@ public static void TryAdd(T item)
public static bool TryTake(out T item)
{
Stack<RefAsValueType<T>> localStack = stack; // cache in a local to avoid unnecessary TLS hits on repeated accesses
Stack<RefAsValueType<T>> localStack = t_stack; // cache in a local to avoid unnecessary TLS hits on repeated accesses
if (localStack != null && localStack.Count > 0)
{
item = localStack.Pop().Value;
......
......@@ -8,28 +8,28 @@ namespace System.Collections.Immutable
{
internal class DictionaryEnumerator<TKey, TValue> : IDictionaryEnumerator
{
private readonly IEnumerator<KeyValuePair<TKey, TValue>> inner;
private readonly IEnumerator<KeyValuePair<TKey, TValue>> _inner;
internal DictionaryEnumerator(IEnumerator<KeyValuePair<TKey, TValue>> inner)
{
Requires.NotNull(inner, "inner");
this.inner = inner;
_inner = inner;
}
public DictionaryEntry Entry
{
get { return new DictionaryEntry(this.inner.Current.Key, this.inner.Current.Value); }
get { return new DictionaryEntry(_inner.Current.Key, _inner.Current.Value); }
}
public object Key
{
get { return this.inner.Current.Key; }
get { return _inner.Current.Key; }
}
public object Value
{
get { return this.inner.Current.Value; }
get { return _inner.Current.Value; }
}
public object Current
......@@ -39,12 +39,12 @@ public object Current
public bool MoveNext()
{
return this.inner.MoveNext();
return _inner.MoveNext();
}
public void Reset()
{
this.inner.Reset();
_inner.Reset();
}
}
}
// Copyright (c) Microsoft. All rights reserved.
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
......@@ -17,16 +17,16 @@ internal struct DisposableEnumeratorAdapter<T, TEnumerator> : IDisposable
/// <summary>
/// The enumerator object to use if not null.
/// </summary>
private readonly IEnumerator<T> enumeratorObject;
private readonly IEnumerator<T> _enumeratorObject;
/// <summary>
/// The enumerator struct to use if <see cref="enumeratorObject"/> is <c>null</c>.
/// The enumerator struct to use if <see cref="_enumeratorObject"/> is <c>null</c>.
/// </summary>
/// <remarks>
/// This field must NOT be readonly because the field's value is a struct and must be able to mutate
/// in-place. A readonly keyword would cause any mutation to take place in a copy rather than the field.
/// </remarks>
private TEnumerator enumeratorStruct;
private TEnumerator _enumeratorStruct;
/// <summary>
/// Initializes a new instance of the <see cref="EnumeratorAdapter{T, TEnumerator}"/> struct
......@@ -35,8 +35,8 @@ internal struct DisposableEnumeratorAdapter<T, TEnumerator> : IDisposable
/// <param name="enumerator">The initialized enumerator struct.</param>
internal DisposableEnumeratorAdapter(TEnumerator enumerator)
{
this.enumeratorStruct = enumerator;
this.enumeratorObject = null;
_enumeratorStruct = enumerator;
_enumeratorObject = null;
}
/// <summary>
......@@ -46,8 +46,8 @@ internal DisposableEnumeratorAdapter(TEnumerator enumerator)
/// <param name="enumerator">The initialized enumerator object.</param>
internal DisposableEnumeratorAdapter(IEnumerator<T> enumerator)
{
this.enumeratorStruct = default(TEnumerator);
this.enumeratorObject = enumerator;
_enumeratorStruct = default(TEnumerator);
_enumeratorObject = enumerator;
}
/// <summary>
......@@ -55,7 +55,7 @@ internal DisposableEnumeratorAdapter(IEnumerator<T> enumerator)
/// </summary>
public T Current
{
get { return this.enumeratorObject != null ? this.enumeratorObject.Current : this.enumeratorStruct.Current; }
get { return _enumeratorObject != null ? _enumeratorObject.Current : _enumeratorStruct.Current; }
}
/// <summary>
......@@ -63,7 +63,7 @@ public T Current
/// </summary>
public bool MoveNext()
{
return this.enumeratorObject != null ? this.enumeratorObject.MoveNext() : this.enumeratorStruct.MoveNext();
return _enumeratorObject != null ? _enumeratorObject.MoveNext() : _enumeratorStruct.MoveNext();
}
/// <summary>
......@@ -71,13 +71,13 @@ public bool MoveNext()
/// </summary>
public void Dispose()
{
if (this.enumeratorObject != null)
if (_enumeratorObject != null)
{
this.enumeratorObject.Dispose();
_enumeratorObject.Dispose();
}
else
{
this.enumeratorStruct.Dispose();
_enumeratorStruct.Dispose();
}
}
......
// Copyright (c) Microsoft. All rights reserved.
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
......@@ -17,16 +17,16 @@ internal struct EnumeratorAdapter<T, TEnumerator>
/// <summary>
/// The enumerator object to use if not null.
/// </summary>
private readonly IEnumerator<T> enumeratorObject;
private readonly IEnumerator<T> _enumeratorObject;
/// <summary>
/// The enumerator struct to use if <see cref="enumeratorObject"/> is <c>null</c>.
/// The enumerator struct to use if <see cref="_enumeratorObject"/> is <c>null</c>.
/// </summary>
/// <remarks>
/// This field must NOT be readonly because the field's value is a struct and must be able to mutate
/// in-place. A readonly keyword would cause any mutation to take place in a copy rather than the field.
/// </remarks>
private TEnumerator enumeratorStruct;
private TEnumerator _enumeratorStruct;
/// <summary>
/// Initializes a new instance of the <see cref="EnumeratorAdapter{T, TEnumerator}"/> struct
......@@ -35,8 +35,8 @@ internal struct EnumeratorAdapter<T, TEnumerator>
/// <param name="enumerator">The initialized enumerator struct.</param>
internal EnumeratorAdapter(TEnumerator enumerator)
{
this.enumeratorStruct = enumerator;
this.enumeratorObject = null;
_enumeratorStruct = enumerator;
_enumeratorObject = null;
}
/// <summary>
......@@ -46,8 +46,8 @@ internal EnumeratorAdapter(TEnumerator enumerator)
/// <param name="enumerator">The initialized enumerator object.</param>
internal EnumeratorAdapter(IEnumerator<T> enumerator)
{
this.enumeratorStruct = default(TEnumerator);
this.enumeratorObject = enumerator;
_enumeratorStruct = default(TEnumerator);
_enumeratorObject = enumerator;
}
/// <summary>
......@@ -55,7 +55,7 @@ internal EnumeratorAdapter(IEnumerator<T> enumerator)
/// </summary>
public T Current
{
get { return this.enumeratorObject != null ? this.enumeratorObject.Current : this.enumeratorStruct.Current; }
get { return _enumeratorObject != null ? _enumeratorObject.Current : _enumeratorStruct.Current; }
}
/// <summary>
......@@ -63,7 +63,7 @@ public T Current
/// </summary>
public bool MoveNext()
{
return this.enumeratorObject != null ? this.enumeratorObject.MoveNext() : this.enumeratorStruct.MoveNext();
return _enumeratorObject != null ? _enumeratorObject.MoveNext() : _enumeratorStruct.MoveNext();
}
/// <summary>
......
// Copyright (c) Microsoft. All rights reserved.
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
......
// Copyright (c) Microsoft. All rights reserved.
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
......
......@@ -22,12 +22,12 @@ public sealed class Builder : IList<T>, IReadOnlyList<T>
/// <summary>
/// The backing array for the builder.
/// </summary>
private RefAsValueType<T>[] elements;
private RefAsValueType<T>[] _elements;
/// <summary>
/// The number of initialized elements in the array.
/// </summary>
private int count;
private int _count;
/// <summary>
/// Initializes a new instance of the <see cref="Builder"/> class.
......@@ -36,7 +36,7 @@ public sealed class Builder : IList<T>, IReadOnlyList<T>
internal Builder(int capacity)
{
Requires.Range(capacity >= 0, "capacity");
this.elements = new RefAsValueType<T>[capacity];
_elements = new RefAsValueType<T>[capacity];
this.Count = 0;
}
......@@ -59,39 +59,39 @@ public int Count
{
get
{
return this.count;
return _count;
}
set
{
Requires.Range(value >= 0, "value");
if (value < this.count)
if (value < _count)
{
// truncation mode
// Clear the elements of the elements that are effectively removed.
var e = this.elements;
var e = _elements;
// PERF: Array.Clear works well for big arrays,
// but may have too much overhead with small ones (which is the common case here)
if (this.count - value > 64)
if (_count - value > 64)
{
Array.Clear(this.elements, value, this.count - value);
Array.Clear(_elements, value, _count - value);
}
else
{
for (int i = value; i < this.Count; i++)
{
this.elements[i].Value = default(T);
_elements[i].Value = default(T);
}
}
}
else if (value > this.count)
else if (value > _count)
{
// expansion
this.EnsureCapacity(value);
}
this.count = value;
_count = value;
}
}
......@@ -111,7 +111,7 @@ public int Count
throw new IndexOutOfRangeException();
}
return this.elements[index].Value;
return _elements[index].Value;
}
set
......@@ -121,7 +121,7 @@ public int Count
throw new IndexOutOfRangeException();
}
this.elements[index].Value = value;
_elements[index].Value = value;
}
}
......@@ -169,11 +169,11 @@ public void Insert(int index, T item)
if (index < this.Count)
{
Array.Copy(this.elements, index, this.elements, index + 1, this.Count - index);
Array.Copy(_elements, index, _elements, index + 1, this.Count - index);
}
this.count++;
this.elements[index].Value = item;
_count++;
_elements[index].Value = item;
}
/// <summary>
......@@ -183,7 +183,7 @@ public void Insert(int index, T item)
public void Add(T item)
{
this.EnsureCapacity(this.Count + 1);
this.elements[this.count++].Value = item;
_elements[_count++].Value = item;
}
/// <summary>
......@@ -217,7 +217,7 @@ public void AddRange(params T[] items)
var offset = this.Count;
this.Count += items.Length;
var nodes = this.elements;
var nodes = _elements;
for (int i = 0; i < items.Length; i++)
{
nodes[offset + i].Value = items[i];
......@@ -235,7 +235,7 @@ public void AddRange(params T[] items)
var offset = this.Count;
this.Count += items.Length;
var nodes = this.elements;
var nodes = _elements;
for (int i = 0; i < items.Length; i++)
{
nodes[offset + i].Value = items[i];
......@@ -255,7 +255,7 @@ public void AddRange(T[] items, int length)
var offset = this.Count;
this.Count += length;
var nodes = this.elements;
var nodes = _elements;
for (int i = 0; i < length; i++)
{
nodes[offset + i].Value = items[i];
......@@ -305,7 +305,7 @@ public void AddRange(ImmutableArray<T> items, int length)
public void AddRange(Builder items)
{
Requires.NotNull(items, "items");
this.AddRange(items.elements, items.Count);
this.AddRange(items._elements, items.Count);
}
/// <summary>
......@@ -315,7 +315,7 @@ public void AddRange(Builder items)
public void AddRange<TDerived>(ImmutableArray<TDerived>.Builder items) where TDerived : T
{
Requires.NotNull(items, "items");
this.AddRange(items.elements, items.Count);
this.AddRange(items._elements, items.Count);
}
/// <summary>
......@@ -345,7 +345,7 @@ public void RemoveAt(int index)
if (index < this.Count - 1)
{
Array.Copy(this.elements, index + 1, this.elements, index, this.Count - index - 1);
Array.Copy(_elements, index + 1, _elements, index, this.Count - index - 1);
}
this.Count--;
......@@ -369,7 +369,7 @@ public bool Contains(T item)
public T[] ToArray()
{
var tmp = new T[this.Count];
var elements = this.elements;
var elements = _elements;
for (int i = 0; i < tmp.Length; i++)
{
tmp[i] = elements[i].Value;
......@@ -400,10 +400,10 @@ public void CopyTo(T[] array, int index)
/// <param name="capacity">The required capacity.</param>
public void EnsureCapacity(int capacity)
{
if (this.elements.Length < capacity)
if (_elements.Length < capacity)
{
int newCapacity = Math.Max(this.elements.Length * 2, capacity);
Array.Resize(ref this.elements, newCapacity);
int newCapacity = Math.Max(_elements.Length * 2, capacity);
Array.Resize(ref _elements, newCapacity);
}
}
......@@ -417,7 +417,7 @@ public void EnsureCapacity(int capacity)
[Pure]
public int IndexOf(T item)
{
return this.IndexOf(item, 0, this.count, EqualityComparer<T>.Default);
return this.IndexOf(item, 0, _count, EqualityComparer<T>.Default);
}
/// <summary>
......@@ -468,13 +468,13 @@ public int IndexOf(T item, int startIndex, int count, IEqualityComparer<T> equal
if (equalityComparer == EqualityComparer<T>.Default)
{
return Array.IndexOf(this.elements, new RefAsValueType<T>(item), startIndex, count);
return Array.IndexOf(_elements, new RefAsValueType<T>(item), startIndex, count);
}
else
{
for (int i = startIndex; i < startIndex + count; i++)
{
if (equalityComparer.Equals(this.elements[i].Value, item))
if (equalityComparer.Equals(_elements[i].Value, item))
{
return i;
}
......@@ -555,13 +555,13 @@ public int LastIndexOf(T item, int startIndex, int count, IEqualityComparer<T> e
if (equalityComparer == EqualityComparer<T>.Default)
{
return Array.LastIndexOf(this.elements, new RefAsValueType<T>(item), startIndex, count);
return Array.LastIndexOf(_elements, new RefAsValueType<T>(item), startIndex, count);
}
else
{
for (int i = startIndex; i >= startIndex - count + 1; i--)
{
if (equalityComparer.Equals(item, this.elements[i].Value))
if (equalityComparer.Equals(item, _elements[i].Value))
{
return i;
}
......@@ -579,9 +579,9 @@ public void ReverseContents()
int end = this.Count - 1;
for (int i = 0, j = end; i < j; i++, j--)
{
var tmp = this.elements[i].Value;
this.elements[i] = this.elements[j];
this.elements[j].Value = tmp;
var tmp = _elements[i].Value;
_elements[i] = _elements[j];
_elements[j].Value = tmp;
}
}
......@@ -592,7 +592,7 @@ public void Sort()
{
if (Count > 1)
{
Array.Sort(this.elements, 0, this.Count, Comparer.Default);
Array.Sort(_elements, 0, this.Count, Comparer.Default);
}
}
......@@ -604,7 +604,7 @@ public void Sort(IComparer<T> comparer)
{
if (Count > 1)
{
Array.Sort(this.elements, 0, this.Count, Comparer.Create(comparer));
Array.Sort(_elements, 0, this.Count, Comparer.Create(comparer));
}
}
......@@ -623,7 +623,7 @@ public void Sort(int index, int count, IComparer<T> comparer)
if (count > 1)
{
Array.Sort(this.elements, index, count, Comparer.Create(comparer));
Array.Sort(_elements, index, count, Comparer.Create(comparer));
}
}
......@@ -670,7 +670,7 @@ IEnumerator IEnumerable.GetEnumerator()
var offset = this.Count;
this.Count += length;
var nodes = this.elements;
var nodes = _elements;
for (int i = 0; i < length; i++)
{
nodes[offset + i].Value = items[i].Value;
......@@ -679,13 +679,13 @@ IEnumerator IEnumerable.GetEnumerator()
private sealed class Comparer : IComparer<RefAsValueType<T>>
{
private readonly IComparer<T> comparer;
private readonly IComparer<T> _comparer;
public static readonly Comparer Default = new Comparer(Comparer<T>.Default);
public static Comparer Create(IComparer<T> comparer)
{
if (comparer == null || comparer == Comparer<T>.Default)
if (comparer == null || comparer == Comparer<T>.Default)
{
return Default;
}
......@@ -696,12 +696,12 @@ public static Comparer Create(IComparer<T> comparer)
private Comparer(IComparer<T> comparer)
{
Requires.NotNull(comparer, "comparer"); // use Comparer.Default instead of passing null
this.comparer = comparer;
_comparer = comparer;
}
public int Compare(RefAsValueType<T> x, RefAsValueType<T> y)
{
return this.comparer.Compare(x.Value, y.Value);
return _comparer.Compare(x.Value, y.Value);
}
}
}
......@@ -716,14 +716,14 @@ internal sealed class ImmutableArrayBuilderDebuggerProxy<T>
/// <summary>
/// The collection to be enumerated.
/// </summary>
private readonly ImmutableArray<T>.Builder builder;
private readonly ImmutableArray<T>.Builder _builder;
/// <summary>
/// Initializes a new instance of the <see cref="ImmutableArrayBuilderDebuggerProxy&lt;T&gt;"/> class.
/// </summary>
/// <param name="builder">The collection to display in the debugger</param>
public ImmutableArrayBuilderDebuggerProxy(ImmutableArray<T>.Builder builder)
{
this.builder = builder;
_builder = builder;
}
/// <summary>
......@@ -734,7 +734,7 @@ public T[] A
{
get
{
return this.builder.ToArray();
return _builder.ToArray();
}
}
}
......
......@@ -20,7 +20,7 @@ public struct Enumerator
/// <summary>
/// The array being enumerated.
/// </summary>
private readonly T[] array;
private readonly T[] _array;
/// <summary>
/// The currently enumerated position.
......@@ -29,7 +29,7 @@ public struct Enumerator
/// -1 before the first call to <see cref="MoveNext"/>.
/// >= this.array.Length after MoveNext returns false.
/// </value>
private int index;
private int _index;
/// <summary>
/// Initializes a new instance of the <see cref="Enumerator"/> struct.
......@@ -37,8 +37,8 @@ public struct Enumerator
/// <param name="array">The array to enumerate.</param>
internal Enumerator(T[] array)
{
this.array = array;
this.index = -1;
_array = array;
_index = -1;
}
/// <summary>
......@@ -51,7 +51,7 @@ public T Current
// PERF: no need to do a range check, we already did in MoveNext.
// if user did not call MoveNext or ignored its result (incorrect use)
// he will still get an exception from the array access range check.
return this.array[this.index];
return _array[_index];
}
}
......@@ -61,7 +61,7 @@ public T Current
/// <returns><c>true</c> if another item exists in the array; <c>false</c> otherwise.</returns>
public bool MoveNext()
{
return ++this.index < this.array.Length;
return ++_index < _array.Length;
}
}
......@@ -73,13 +73,13 @@ private class EnumeratorObject : IEnumerator<T>
/// <summary>
/// A shareable singleton for enumerating empty arrays.
/// </summary>
private static readonly IEnumerator<T> EmptyEnumerator =
private static readonly IEnumerator<T> s_EmptyEnumerator =
new EnumeratorObject(ImmutableArray<T>.Empty.array);
/// <summary>
/// The array being enumerated.
/// </summary>
private readonly T[] array;
private readonly T[] _array;
/// <summary>
/// The currently enumerated position.
......@@ -88,15 +88,15 @@ private class EnumeratorObject : IEnumerator<T>
/// -1 before the first call to <see cref="MoveNext"/>.
/// this.array.Length - 1 after MoveNext returns false.
/// </value>
private int index;
private int _index;
/// <summary>
/// Initializes a new instance of the <see cref="Enumerator"/> class.
/// </summary>
private EnumeratorObject(T[] array)
{
this.index = -1;
this.array = array;
_index = -1;
_array = array;
}
/// <summary>
......@@ -108,9 +108,9 @@ public T Current
{
// this.index >= 0 && this.index < this.array.Length
// unsigned compare performs the range check above in one compare
if ((uint)this.index < (uint)this.array.Length)
if ((uint)_index < (uint)_array.Length)
{
return this.array[this.index];
return _array[_index];
}
// Before first or after last MoveNext.
......@@ -132,13 +132,13 @@ object IEnumerator.Current
/// <returns><c>true</c> if another item exists in the array; <c>false</c> otherwise.</returns>
public bool MoveNext()
{
int newIndex = this.index + 1;
int length = array.Length;
int newIndex = _index + 1;
int length = _array.Length;
// unsigned math is used to prevent false positive if index + 1 overflows.
if ((uint)newIndex <= (uint)length)
{
this.index = newIndex;
_index = newIndex;
return (uint)newIndex < (uint)length;
}
......@@ -150,7 +150,7 @@ public bool MoveNext()
/// </summary>
void IEnumerator.Reset()
{
this.index = -1;
_index = -1;
}
/// <summary>
......@@ -176,7 +176,7 @@ internal static IEnumerator<T> Create(T[] array)
}
else
{
return EmptyEnumerator;
return s_EmptyEnumerator;
}
}
}
......
......@@ -38,33 +38,33 @@ public sealed class Builder : IDictionary<TKey, TValue>, IReadOnlyDictionary<TKe
/// <summary>
/// The root of the binary tree that stores the collection. Contents are typically not entirely frozen.
/// </summary>
private SortedInt32KeyNode<HashBucket> root = SortedInt32KeyNode<HashBucket>.EmptyNode;
private SortedInt32KeyNode<HashBucket> _root = SortedInt32KeyNode<HashBucket>.EmptyNode;
/// <summary>
/// The comparers.
/// </summary>
private Comparers comparers;
private Comparers _comparers;
/// <summary>
/// The number of elements in this collection.
/// </summary>
private int count;
private int _count;
/// <summary>
/// Caches an immutable instance that represents the current state of the collection.
/// </summary>
/// <value>Null if no immutable view has been created for the current version.</value>
private ImmutableDictionary<TKey, TValue> immutable;
private ImmutableDictionary<TKey, TValue> _immutable;
/// <summary>
/// A number that increments every time the builder changes its contents.
/// </summary>
private int version;
private int _version;
/// <summary>
/// The object callers may use to synchronize access to this collection.
/// </summary>
private object syncRoot;
private object _syncRoot;
/// <summary>
/// Initializes a new instance of the <see cref="ImmutableDictionary&lt;TKey, TValue&gt;.Builder"/> class.
......@@ -73,10 +73,10 @@ public sealed class Builder : IDictionary<TKey, TValue>, IReadOnlyDictionary<TKe
internal Builder(ImmutableDictionary<TKey, TValue> map)
{
Requires.NotNull(map, "map");
this.root = map.root;
this.count = map.count;
this.comparers = map.comparers;
this.immutable = map;
_root = map._root;
_count = map._count;
_comparers = map._comparers;
_immutable = map;
}
/// <summary>
......@@ -89,7 +89,7 @@ public IEqualityComparer<TKey> KeyComparer
{
get
{
return this.comparers.KeyComparer;
return _comparers.KeyComparer;
}
set
......@@ -101,9 +101,9 @@ public IEqualityComparer<TKey> KeyComparer
var input = new MutationInput(SortedInt32KeyNode<HashBucket>.EmptyNode, comparers, 0);
var result = ImmutableDictionary<TKey, TValue>.AddRange(this, input);
this.immutable = null;
this.comparers = comparers;
this.count = result.CountAdjustment; // offset from 0
_immutable = null;
_comparers = comparers;
_count = result.CountAdjustment; // offset from 0
this.Root = result.Root;
}
}
......@@ -119,7 +119,7 @@ public IEqualityComparer<TValue> ValueComparer
{
get
{
return this.comparers.ValueComparer;
return _comparers.ValueComparer;
}
set
......@@ -130,8 +130,8 @@ public IEqualityComparer<TValue> ValueComparer
// When the key comparer is the same but the value comparer is different, we don't need a whole new tree
// because the structure of the tree does not depend on the value comparer.
// We just need a new root node to store the new value comparer.
this.comparers = this.comparers.WithValueComparer(value);
this.immutable = null; // invalidate cached immutable
_comparers = _comparers.WithValueComparer(value);
_immutable = null; // invalidate cached immutable
}
}
}
......@@ -144,7 +144,7 @@ public IEqualityComparer<TValue> ValueComparer
/// <returns>The number of elements contained in the <see cref="T:System.Collections.Generic.ICollection`1"/>.</returns>
public int Count
{
get { return this.count; }
get { return _count; }
}
/// <summary>
......@@ -161,7 +161,7 @@ public int Count
/// </summary>
public IEnumerable<TKey> Keys
{
get
get
{
foreach (KeyValuePair<TKey, TValue> item in this)
{
......@@ -260,12 +260,12 @@ object ICollection.SyncRoot
{
get
{
if (this.syncRoot == null)
if (_syncRoot == null)
{
Threading.Interlocked.CompareExchange<Object>(ref this.syncRoot, new Object(), null);
Threading.Interlocked.CompareExchange<Object>(ref _syncRoot, new Object(), null);
}
return this.syncRoot;
return _syncRoot;
}
}
......@@ -352,7 +352,7 @@ void ICollection.CopyTo(Array array, int arrayIndex)
Requires.Range(arrayIndex >= 0, "arrayIndex");
Requires.Range(array.Length >= arrayIndex + this.Count, "arrayIndex");
if (this.count == 0)
if (_count == 0)
{
return;
}
......@@ -372,7 +372,7 @@ void ICollection.CopyTo(Array array, int arrayIndex)
/// </summary>
internal int Version
{
get { return this.version; }
get { return _version; }
}
/// <summary>
......@@ -380,7 +380,7 @@ internal int Version
/// </summary>
private MutationInput Origin
{
get { return new MutationInput(this.Root, this.comparers, this.count); }
get { return new MutationInput(this.Root, _comparers, _count); }
}
/// <summary>
......@@ -390,7 +390,7 @@ private SortedInt32KeyNode<HashBucket> Root
{
get
{
return this.root;
return _root;
}
set
......@@ -398,14 +398,14 @@ private SortedInt32KeyNode<HashBucket> Root
// We *always* increment the version number because some mutations
// may not create a new value of root, although the existing root
// instance may have mutated.
this.version++;
_version++;
if (this.root != value)
if (_root != value)
{
this.root = value;
_root = value;
// Clear any cached value for the immutable view since it is now invalidated.
this.immutable = null;
_immutable = null;
}
}
}
......@@ -472,7 +472,7 @@ public void RemoveRange(IEnumerable<TKey> keys)
/// </returns>
public Enumerator GetEnumerator()
{
return new Enumerator(this.root, this);
return new Enumerator(_root, this);
}
/// <summary>
......@@ -521,12 +521,12 @@ public TValue GetValueOrDefault(TKey key, TValue defaultValue)
// Creating an instance of ImmutableSortedMap<T> with our root node automatically freezes our tree,
// ensuring that the returned instance is immutable. Any further mutations made to this builder
// will clone (and unfreeze) the spine of modified nodes until the next time this method is invoked.
if (this.immutable == null)
if (_immutable == null)
{
this.immutable = ImmutableDictionary<TKey, TValue>.Wrap(this.root, this.comparers, this.count);
_immutable = ImmutableDictionary<TKey, TValue>.Wrap(_root, _comparers, _count);
}
return this.immutable;
return _immutable;
}
#endregion
......@@ -640,7 +640,7 @@ public void Add(KeyValuePair<TKey, TValue> item)
public void Clear()
{
this.Root = SortedInt32KeyNode<HashBucket>.EmptyNode;
this.count = 0;
_count = 0;
}
/// <summary>
......@@ -726,7 +726,7 @@ IEnumerator IEnumerable.GetEnumerator()
private bool Apply(MutationResult result)
{
this.Root = result.Root;
this.count += result.CountAdjustment;
_count += result.CountAdjustment;
return result.CountAdjustment != 0;
}
}
......@@ -741,12 +741,12 @@ internal class ImmutableDictionaryBuilderDebuggerProxy<TKey, TValue>
/// <summary>
/// The collection to be enumerated.
/// </summary>
private readonly ImmutableDictionary<TKey, TValue>.Builder map;
private readonly ImmutableDictionary<TKey, TValue>.Builder _map;
/// <summary>
/// The simple view of the collection.
/// </summary>
private KeyValuePair<TKey, TValue>[] contents;
private KeyValuePair<TKey, TValue>[] _contents;
/// <summary>
/// Initializes a new instance of the <see cref="ImmutableDictionaryBuilderDebuggerProxy&lt;TKey, TValue&gt;"/> class.
......@@ -755,7 +755,7 @@ internal class ImmutableDictionaryBuilderDebuggerProxy<TKey, TValue>
public ImmutableDictionaryBuilderDebuggerProxy(ImmutableDictionary<TKey, TValue>.Builder map)
{
Requires.NotNull(map, "map");
this.map = map;
_map = map;
}
/// <summary>
......@@ -766,12 +766,12 @@ public ImmutableDictionaryBuilderDebuggerProxy(ImmutableDictionary<TKey, TValue>
{
get
{
if (this.contents == null)
if (_contents == null)
{
this.contents = this.map.ToArray(this.map.Count);
_contents = _map.ToArray(_map.Count);
}
return this.contents;
return _contents;
}
}
}
......
......@@ -29,12 +29,12 @@ internal class Comparers : IEqualityComparer<HashBucket>, IEqualityComparer<KeyV
/// <summary>
/// The equality comparer to use for the key.
/// </summary>
private readonly IEqualityComparer<TKey> keyComparer;
private readonly IEqualityComparer<TKey> _keyComparer;
/// <summary>
/// The value comparer.
/// </summary>
private readonly IEqualityComparer<TValue> valueComparer;
private readonly IEqualityComparer<TValue> _valueComparer;
/// <summary>
/// Initializes a new instance of the <see cref="Comparers"/> class.
......@@ -46,8 +46,8 @@ internal Comparers(IEqualityComparer<TKey> keyComparer, IEqualityComparer<TValue
Requires.NotNull(keyComparer, "keyComparer");
Requires.NotNull(valueComparer, "valueComparer");
this.keyComparer = keyComparer;
this.valueComparer = valueComparer;
_keyComparer = keyComparer;
_valueComparer = valueComparer;
}
/// <summary>
......@@ -58,7 +58,7 @@ internal Comparers(IEqualityComparer<TKey> keyComparer, IEqualityComparer<TValue
/// </value>
internal IEqualityComparer<TKey> KeyComparer
{
get { return this.keyComparer; }
get { return _keyComparer; }
}
/// <summary>
......@@ -80,7 +80,7 @@ internal IEqualityComparer<TKey> KeyComparer
/// </value>
internal IEqualityComparer<TValue> ValueComparer
{
get { return this.valueComparer; }
get { return _valueComparer; }
}
/// <summary>
......@@ -128,7 +128,7 @@ public int GetHashCode(HashBucket obj)
/// </returns>
bool IEqualityComparer<KeyValuePair<TKey, TValue>>.Equals(KeyValuePair<TKey, TValue> x, KeyValuePair<TKey, TValue> y)
{
return this.keyComparer.Equals(x.Key, y.Key);
return _keyComparer.Equals(x.Key, y.Key);
}
/// <summary>
......@@ -140,7 +140,7 @@ public int GetHashCode(HashBucket obj)
/// </returns>
int IEqualityComparer<KeyValuePair<TKey, TValue>>.GetHashCode(KeyValuePair<TKey, TValue> obj)
{
return this.keyComparer.GetHashCode(obj.Key);
return _keyComparer.GetHashCode(obj.Key);
}
/// <summary>
......@@ -169,7 +169,7 @@ internal Comparers WithValueComparer(IEqualityComparer<TValue> valueComparer)
{
Requires.NotNull(valueComparer, "valueComparer");
return this.valueComparer == valueComparer
return _valueComparer == valueComparer
? this
: Get(this.KeyComparer, valueComparer);
}
......
......@@ -17,12 +17,12 @@ internal class ImmutableDictionaryDebuggerProxy<TKey, TValue>
/// <summary>
/// The collection to be enumerated.
/// </summary>
private readonly ImmutableDictionary<TKey, TValue> map;
private readonly ImmutableDictionary<TKey, TValue> _map;
/// <summary>
/// The simple view of the collection.
/// </summary>
private KeyValuePair<TKey, TValue>[] contents;
private KeyValuePair<TKey, TValue>[] _contents;
/// <summary>
/// Initializes a new instance of the <see cref="ImmutableDictionaryDebuggerProxy&lt;TKey, TValue&gt;"/> class.
......@@ -31,7 +31,7 @@ internal class ImmutableDictionaryDebuggerProxy<TKey, TValue>
public ImmutableDictionaryDebuggerProxy(ImmutableDictionary<TKey, TValue> map)
{
Requires.NotNull(map, "map");
this.map = map;
_map = map;
}
/// <summary>
......@@ -42,12 +42,12 @@ public ImmutableDictionaryDebuggerProxy(ImmutableDictionary<TKey, TValue> map)
{
get
{
if (this.contents == null)
if (_contents == null)
{
this.contents = this.map.ToArray(this.map.Count);
_contents = _map.ToArray(_map.Count);
}
return this.contents;
return _contents;
}
}
}
......
......@@ -18,22 +18,22 @@ public struct Enumerator : IEnumerator<KeyValuePair<TKey, TValue>>, IDisposable
/// <summary>
/// The builder being enumerated, if applicable.
/// </summary>
private readonly Builder builder;
private readonly Builder _builder;
/// <summary>
/// The enumerator over the sorted dictionary whose keys are hash values.
/// </summary>
private SortedInt32KeyNode<HashBucket>.Enumerator mapEnumerator;
private SortedInt32KeyNode<HashBucket>.Enumerator _mapEnumerator;
/// <summary>
/// The enumerator in use within an individual HashBucket.
/// </summary>
private HashBucket.Enumerator bucketEnumerator;
private HashBucket.Enumerator _bucketEnumerator;
/// <summary>
/// The version of the builder (when applicable) that is being enumerated.
/// </summary>
private int enumeratingBuilderVersion;
private int _enumeratingBuilderVersion;
/// <summary>
/// Initializes a new instance of the <see cref="ImmutableDictionary&lt;TKey, TValue&gt;.Enumerator"/> struct.
......@@ -42,10 +42,10 @@ public struct Enumerator : IEnumerator<KeyValuePair<TKey, TValue>>, IDisposable
/// <param name="builder">The builder, if applicable.</param>
internal Enumerator(SortedInt32KeyNode<HashBucket> root, Builder builder = null)
{
this.builder = builder;
this.mapEnumerator = new SortedInt32KeyNode<HashBucket>.Enumerator(root);
this.bucketEnumerator = default(HashBucket.Enumerator);
this.enumeratingBuilderVersion = builder != null ? builder.Version : -1;
_builder = builder;
_mapEnumerator = new SortedInt32KeyNode<HashBucket>.Enumerator(root);
_bucketEnumerator = default(HashBucket.Enumerator);
_enumeratingBuilderVersion = builder != null ? builder.Version : -1;
}
/// <summary>
......@@ -55,8 +55,8 @@ internal Enumerator(SortedInt32KeyNode<HashBucket> root, Builder builder = null)
{
get
{
this.mapEnumerator.ThrowIfDisposed();
return this.bucketEnumerator.Current;
_mapEnumerator.ThrowIfDisposed();
return _bucketEnumerator.Current;
}
}
......@@ -79,15 +79,15 @@ public bool MoveNext()
{
this.ThrowIfChanged();
if (this.bucketEnumerator.MoveNext())
if (_bucketEnumerator.MoveNext())
{
return true;
}
if (this.mapEnumerator.MoveNext())
if (_mapEnumerator.MoveNext())
{
this.bucketEnumerator = new HashBucket.Enumerator(this.mapEnumerator.Current.Value);
return this.bucketEnumerator.MoveNext();
_bucketEnumerator = new HashBucket.Enumerator(_mapEnumerator.Current.Value);
return _bucketEnumerator.MoveNext();
}
return false;
......@@ -99,12 +99,12 @@ public bool MoveNext()
/// <exception cref="T:System.InvalidOperationException">The collection was modified after the enumerator was created. </exception>
public void Reset()
{
this.enumeratingBuilderVersion = builder != null ? builder.Version : -1;
this.mapEnumerator.Reset();
_enumeratingBuilderVersion = _builder != null ? _builder.Version : -1;
_mapEnumerator.Reset();
// Resetting the bucket enumerator is pointless because we'll start on a new bucket later anyway.
this.bucketEnumerator.Dispose();
this.bucketEnumerator = default(HashBucket.Enumerator);
_bucketEnumerator.Dispose();
_bucketEnumerator = default(HashBucket.Enumerator);
}
/// <summary>
......@@ -112,8 +112,8 @@ public void Reset()
/// </summary>
public void Dispose()
{
this.mapEnumerator.Dispose();
this.bucketEnumerator.Dispose();
_mapEnumerator.Dispose();
_bucketEnumerator.Dispose();
}
/// <summary>
......@@ -122,7 +122,7 @@ public void Dispose()
/// <exception cref="System.InvalidOperationException">Thrown if the collection has changed.</exception>
private void ThrowIfChanged()
{
if (this.builder != null && this.builder.Version != this.enumeratingBuilderVersion)
if (_builder != null && _builder.Version != _enumeratingBuilderVersion)
{
throw new InvalidOperationException(Strings.CollectionModifiedDuringEnumeration);
}
......
......@@ -19,16 +19,16 @@ internal struct HashBucket : IEnumerable<KeyValuePair<TKey, TValue>>, IEquatable
/// <summary>
/// One of the values in this bucket.
/// </summary>
private readonly KeyValuePair<TKey, TValue> firstValue;
private readonly KeyValuePair<TKey, TValue> _firstValue;
/// <summary>
/// Any other elements that hash to the same value.
/// </summary>
/// <value>
/// This is null if and only if the entire bucket is empty (including <see cref="firstValue"/>).
/// It's empty if <see cref="firstValue"/> has an element but no additional elements.
/// This is null if and only if the entire bucket is empty (including <see cref="_firstValue"/>).
/// It's empty if <see cref="_firstValue"/> has an element but no additional elements.
/// </value>
private readonly ImmutableList<KeyValuePair<TKey, TValue>>.Node additionalElements;
private readonly ImmutableList<KeyValuePair<TKey, TValue>>.Node _additionalElements;
/// <summary>
/// Initializes a new instance of the <see cref="ImmutableDictionary&lt;TKey, TValue&gt;.HashBucket"/> struct.
......@@ -37,8 +37,8 @@ internal struct HashBucket : IEnumerable<KeyValuePair<TKey, TValue>>, IEquatable
/// <param name="additionalElements">The additional elements.</param>
private HashBucket(KeyValuePair<TKey, TValue> firstElement, ImmutableList<KeyValuePair<TKey, TValue>>.Node additionalElements = null)
{
this.firstValue = firstElement;
this.additionalElements = additionalElements ?? ImmutableList<KeyValuePair<TKey, TValue>>.Node.EmptyNode;
_firstValue = firstElement;
_additionalElements = additionalElements ?? ImmutableList<KeyValuePair<TKey, TValue>>.Node.EmptyNode;
}
/// <summary>
......@@ -49,7 +49,7 @@ private HashBucket(KeyValuePair<TKey, TValue> firstElement, ImmutableList<KeyVal
/// </value>
internal bool IsEmpty
{
get { return this.additionalElements == null; }
get { return _additionalElements == null; }
}
/// <summary>
......@@ -64,7 +64,7 @@ internal bool IsEmpty
throw new InvalidOperationException();
}
return this.firstValue;
return _firstValue;
}
}
......@@ -73,7 +73,7 @@ internal bool IsEmpty
/// </summary>
internal ImmutableList<KeyValuePair<TKey, TValue>>.Node AdditionalElements
{
get { return this.additionalElements; }
get { return _additionalElements; }
}
/// <summary>
......@@ -134,18 +134,18 @@ internal HashBucket Add(TKey key, TValue value, IEqualityComparer<KeyValuePair<T
return new HashBucket(kv);
}
if (keyOnlyComparer.Equals(kv, this.firstValue))
if (keyOnlyComparer.Equals(kv, _firstValue))
{
switch (behavior)
{
case KeyCollisionBehavior.SetValue:
result = OperationResult.AppliedWithoutSizeChange;
return new HashBucket(kv, this.additionalElements);
return new HashBucket(kv, _additionalElements);
case KeyCollisionBehavior.Skip:
result = OperationResult.NoChangeRequired;
return this;
case KeyCollisionBehavior.ThrowIfValueDifferent:
if (!valueComparer.Equals(this.firstValue.Value, value))
if (!valueComparer.Equals(_firstValue.Value, value))
{
throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Strings.DuplicateKey, key));
}
......@@ -159,11 +159,11 @@ internal HashBucket Add(TKey key, TValue value, IEqualityComparer<KeyValuePair<T
}
}
int keyCollisionIndex = this.additionalElements.IndexOf(kv, keyOnlyComparer);
int keyCollisionIndex = _additionalElements.IndexOf(kv, keyOnlyComparer);
if (keyCollisionIndex < 0)
{
result = OperationResult.SizeChanged;
return new HashBucket(this.firstValue, this.additionalElements.Add(kv));
return new HashBucket(_firstValue, _additionalElements.Add(kv));
}
else
{
......@@ -171,12 +171,12 @@ internal HashBucket Add(TKey key, TValue value, IEqualityComparer<KeyValuePair<T
{
case KeyCollisionBehavior.SetValue:
result = OperationResult.AppliedWithoutSizeChange;
return new HashBucket(this.firstValue, this.additionalElements.ReplaceAt(keyCollisionIndex, kv));
return new HashBucket(_firstValue, _additionalElements.ReplaceAt(keyCollisionIndex, kv));
case KeyCollisionBehavior.Skip:
result = OperationResult.NoChangeRequired;
return this;
case KeyCollisionBehavior.ThrowIfValueDifferent:
var existingEntry = this.additionalElements[keyCollisionIndex];
var existingEntry = _additionalElements[keyCollisionIndex];
if (!valueComparer.Equals(existingEntry.Value, value))
{
throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Strings.DuplicateKey, key));
......@@ -208,9 +208,9 @@ internal HashBucket Remove(TKey key, IEqualityComparer<KeyValuePair<TKey, TValue
}
var kv = new KeyValuePair<TKey, TValue>(key, default(TValue));
if (keyOnlyComparer.Equals(this.firstValue, kv))
if (keyOnlyComparer.Equals(_firstValue, kv))
{
if (this.additionalElements.IsEmpty)
if (_additionalElements.IsEmpty)
{
result = OperationResult.SizeChanged;
return new HashBucket();
......@@ -219,13 +219,13 @@ internal HashBucket Remove(TKey key, IEqualityComparer<KeyValuePair<TKey, TValue
{
// We can promote any element from the list into the first position, but it's most efficient
// to remove the root node in the binary tree that implements the list.
int indexOfRootNode = this.additionalElements.Left.Count;
int indexOfRootNode = _additionalElements.Left.Count;
result = OperationResult.SizeChanged;
return new HashBucket(this.additionalElements.Key, this.additionalElements.RemoveAt(indexOfRootNode));
return new HashBucket(_additionalElements.Key, _additionalElements.RemoveAt(indexOfRootNode));
}
}
int index = this.additionalElements.IndexOf(kv, keyOnlyComparer);
int index = _additionalElements.IndexOf(kv, keyOnlyComparer);
if (index < 0)
{
result = OperationResult.NoChangeRequired;
......@@ -234,7 +234,7 @@ internal HashBucket Remove(TKey key, IEqualityComparer<KeyValuePair<TKey, TValue
else
{
result = OperationResult.SizeChanged;
return new HashBucket(this.firstValue, this.additionalElements.RemoveAt(index));
return new HashBucket(_firstValue, _additionalElements.RemoveAt(index));
}
}
......@@ -254,20 +254,20 @@ internal bool TryGetValue(TKey key, IEqualityComparer<KeyValuePair<TKey, TValue>
}
var kv = new KeyValuePair<TKey, TValue>(key, default(TValue));
if (keyOnlyComparer.Equals(this.firstValue, kv))
if (keyOnlyComparer.Equals(_firstValue, kv))
{
value = this.firstValue.Value;
value = _firstValue.Value;
return true;
}
var index = this.additionalElements.IndexOf(kv, keyOnlyComparer);
var index = _additionalElements.IndexOf(kv, keyOnlyComparer);
if (index < 0)
{
value = default(TValue);
return false;
}
value = this.additionalElements[index].Value;
value = _additionalElements[index].Value;
return true;
}
......@@ -293,20 +293,20 @@ internal bool TryGetKey(TKey equalKey, IEqualityComparer<KeyValuePair<TKey, TVal
}
var kv = new KeyValuePair<TKey, TValue>(equalKey, default(TValue));
if (keyOnlyComparer.Equals(this.firstValue, kv))
if (keyOnlyComparer.Equals(_firstValue, kv))
{
actualKey = this.firstValue.Key;
actualKey = _firstValue.Key;
return true;
}
var index = this.additionalElements.IndexOf(kv, keyOnlyComparer);
var index = _additionalElements.IndexOf(kv, keyOnlyComparer);
if (index < 0)
{
actualKey = equalKey;
return false;
}
actualKey = this.additionalElements[index].Key;
actualKey = _additionalElements[index].Key;
return true;
}
......@@ -315,9 +315,9 @@ internal bool TryGetKey(TKey equalKey, IEqualityComparer<KeyValuePair<TKey, TVal
/// </summary>
internal void Freeze()
{
if (this.additionalElements != null)
if (_additionalElements != null)
{
this.additionalElements.Freeze();
_additionalElements.Freeze();
}
}
......@@ -329,17 +329,17 @@ internal struct Enumerator : IEnumerator<KeyValuePair<TKey, TValue>>, IDisposabl
/// <summary>
/// The bucket being enumerated.
/// </summary>
private readonly HashBucket bucket;
private readonly HashBucket _bucket;
/// <summary>
/// The current position of this enumerator.
/// </summary>
private Position currentPosition;
private Position _currentPosition;
/// <summary>
/// The enumerator that represents the current position over the additionalValues of the HashBucket.
/// </summary>
private ImmutableList<KeyValuePair<TKey, TValue>>.Enumerator additionalEnumerator;
private ImmutableList<KeyValuePair<TKey, TValue>>.Enumerator _additionalEnumerator;
/// <summary>
/// Initializes a new instance of the <see cref="ImmutableDictionary&lt;TKey, TValue&gt;.HashBucket.Enumerator"/> struct.
......@@ -347,9 +347,9 @@ internal struct Enumerator : IEnumerator<KeyValuePair<TKey, TValue>>, IDisposabl
/// <param name="bucket">The bucket.</param>
internal Enumerator(HashBucket bucket)
{
this.bucket = bucket;
this.currentPosition = Position.BeforeFirst;
this.additionalEnumerator = default(ImmutableList<KeyValuePair<TKey, TValue>>.Enumerator);
_bucket = bucket;
_currentPosition = Position.BeforeFirst;
_additionalEnumerator = default(ImmutableList<KeyValuePair<TKey, TValue>>.Enumerator);
}
/// <summary>
......@@ -393,12 +393,12 @@ object IEnumerator.Current
{
get
{
switch (this.currentPosition)
switch (_currentPosition)
{
case Position.First:
return this.bucket.firstValue;
return _bucket._firstValue;
case Position.Additional:
return this.additionalEnumerator.Current;
return _additionalEnumerator.Current;
default:
throw new InvalidOperationException();
}
......@@ -414,29 +414,29 @@ object IEnumerator.Current
/// <exception cref="T:System.InvalidOperationException">The collection was modified after the enumerator was created. </exception>
public bool MoveNext()
{
if (this.bucket.IsEmpty)
if (_bucket.IsEmpty)
{
this.currentPosition = Position.End;
_currentPosition = Position.End;
return false;
}
switch (this.currentPosition)
switch (_currentPosition)
{
case Position.BeforeFirst:
this.currentPosition = Position.First;
_currentPosition = Position.First;
return true;
case Position.First:
if (this.bucket.additionalElements.IsEmpty)
if (_bucket._additionalElements.IsEmpty)
{
this.currentPosition = Position.End;
_currentPosition = Position.End;
return false;
}
this.currentPosition = Position.Additional;
this.additionalEnumerator = new ImmutableList<KeyValuePair<TKey, TValue>>.Enumerator(this.bucket.additionalElements);
return this.additionalEnumerator.MoveNext();
_currentPosition = Position.Additional;
_additionalEnumerator = new ImmutableList<KeyValuePair<TKey, TValue>>.Enumerator(_bucket._additionalElements);
return _additionalEnumerator.MoveNext();
case Position.Additional:
return this.additionalEnumerator.MoveNext();
return _additionalEnumerator.MoveNext();
case Position.End:
return false;
default:
......@@ -452,8 +452,8 @@ public void Reset()
{
// We can safely dispose of the additional enumerator because if the client reuses this enumerator
// we'll acquire a new one anyway (and so for that matter we should be sure to dispose of this).
this.additionalEnumerator.Dispose();
this.currentPosition = Position.BeforeFirst;
_additionalEnumerator.Dispose();
_currentPosition = Position.BeforeFirst;
}
/// <summary>
......@@ -461,7 +461,7 @@ public void Reset()
/// </summary>
public void Dispose()
{
this.additionalEnumerator.Dispose();
_additionalEnumerator.Dispose();
}
}
}
......
......@@ -19,17 +19,17 @@ private struct MutationInput
/// <summary>
/// The root of the data structure for the collection.
/// </summary>
private readonly SortedInt32KeyNode<HashBucket> root;
private readonly SortedInt32KeyNode<HashBucket> _root;
/// <summary>
/// The comparer used when comparing hash buckets.
/// </summary>
private readonly Comparers comparers;
private readonly Comparers _comparers;
/// <summary>
/// The current number of elements in the collection.
/// </summary>
private readonly int count;
private readonly int _count;
/// <summary>
/// Initializes a new instance of the <see cref="ImmutableDictionary&lt;TKey, TValue&gt;.MutationInput"/> struct.
......@@ -42,9 +42,9 @@ private struct MutationInput
Comparers comparers,
int count)
{
this.root = root;
this.comparers = comparers;
this.count = count;
_root = root;
_comparers = comparers;
_count = count;
}
/// <summary>
......@@ -53,9 +53,9 @@ private struct MutationInput
/// <param name="map">The map.</param>
internal MutationInput(ImmutableDictionary<TKey, TValue> map)
{
this.root = map.root;
this.comparers = map.comparers;
this.count = map.count;
_root = map._root;
_comparers = map._comparers;
_count = map._count;
}
/// <summary>
......@@ -63,7 +63,7 @@ internal MutationInput(ImmutableDictionary<TKey, TValue> map)
/// </summary>
internal SortedInt32KeyNode<HashBucket> Root
{
get { return this.root; }
get { return _root; }
}
/// <summary>
......@@ -71,7 +71,7 @@ internal SortedInt32KeyNode<HashBucket> Root
/// </summary>
internal IEqualityComparer<TKey> KeyComparer
{
get { return this.comparers.KeyComparer; }
get { return _comparers.KeyComparer; }
}
/// <summary>
......@@ -79,7 +79,7 @@ internal IEqualityComparer<TKey> KeyComparer
/// </summary>
internal IEqualityComparer<KeyValuePair<TKey, TValue>> KeyOnlyComparer
{
get { return this.comparers.KeyOnlyComparer; }
get { return _comparers.KeyOnlyComparer; }
}
/// <summary>
......@@ -87,7 +87,7 @@ internal IEqualityComparer<TKey> KeyComparer
/// </summary>
internal IEqualityComparer<TValue> ValueComparer
{
get { return this.comparers.ValueComparer; }
get { return _comparers.ValueComparer; }
}
/// <summary>
......@@ -95,7 +95,7 @@ internal IEqualityComparer<TValue> ValueComparer
/// </summary>
internal IEqualityComparer<HashBucket> HashBucketComparer
{
get { return this.comparers.HashBucketEqualityComparer; }
get { return _comparers.HashBucketEqualityComparer; }
}
/// <summary>
......@@ -103,7 +103,7 @@ internal IEqualityComparer<HashBucket> HashBucketComparer
/// </summary>
internal int Count
{
get { return this.count; }
get { return _count; }
}
}
}
......
......@@ -18,12 +18,12 @@ private struct MutationResult
/// <summary>
/// The root node of the data structure after the mutation.
/// </summary>
private readonly SortedInt32KeyNode<HashBucket> root;
private readonly SortedInt32KeyNode<HashBucket> _root;
/// <summary>
/// The number of elements added or removed from the collection as a result of the operation (a negative number represents removed elements).
/// </summary>
private readonly int countAdjustment;
private readonly int _countAdjustment;
/// <summary>
/// Initializes a new instance of the <see cref="ImmutableDictionary&lt;TKey, TValue&gt;.MutationResult"/> struct.
......@@ -31,8 +31,8 @@ private struct MutationResult
/// <param name="unchangedInput">The unchanged input.</param>
internal MutationResult(MutationInput unchangedInput)
{
this.root = unchangedInput.Root;
this.countAdjustment = 0;
_root = unchangedInput.Root;
_countAdjustment = 0;
}
/// <summary>
......@@ -43,8 +43,8 @@ internal MutationResult(MutationInput unchangedInput)
internal MutationResult(SortedInt32KeyNode<HashBucket> root, int countAdjustment)
{
Requires.NotNull(root, "root");
this.root = root;
this.countAdjustment = countAdjustment;
_root = root;
_countAdjustment = countAdjustment;
}
/// <summary>
......@@ -52,7 +52,7 @@ internal MutationResult(SortedInt32KeyNode<HashBucket> root, int countAdjustment
/// </summary>
internal SortedInt32KeyNode<HashBucket> Root
{
get { return this.root; }
get { return _root; }
}
/// <summary>
......@@ -60,7 +60,7 @@ internal SortedInt32KeyNode<HashBucket> Root
/// </summary>
internal int CountAdjustment
{
get { return this.countAdjustment; }
get { return _countAdjustment; }
}
/// <summary>
......@@ -71,7 +71,7 @@ internal int CountAdjustment
internal ImmutableDictionary<TKey, TValue> Finalize(ImmutableDictionary<TKey, TValue> priorMap)
{
Requires.NotNull(priorMap, "priorMap");
return priorMap.Wrap(this.Root, priorMap.count + this.CountAdjustment);
return priorMap.Wrap(this.Root, priorMap._count + this.CountAdjustment);
}
}
}
......
......@@ -28,22 +28,22 @@ public sealed partial class ImmutableDictionary<TKey, TValue> : IImmutableDictio
/// <summary>
/// The singleton delegate that freezes the contents of hash buckets when the root of the data structure is frozen.
/// </summary>
private static readonly Action<KeyValuePair<int, HashBucket>> FreezeBucketAction = (kv) => kv.Value.Freeze();
private static readonly Action<KeyValuePair<int, HashBucket>> s_FreezeBucketAction = (kv) => kv.Value.Freeze();
/// <summary>
/// The number of elements in the collection.
/// </summary>
private readonly int count;
private readonly int _count;
/// <summary>
/// The root node of the tree that stores this map.
/// </summary>
private readonly SortedInt32KeyNode<HashBucket> root;
private readonly SortedInt32KeyNode<HashBucket> _root;
/// <summary>
/// The comparer used when comparing hash buckets.
/// </summary>
private readonly Comparers comparers;
private readonly Comparers _comparers;
/// <summary>
/// Initializes a new instance of the <see cref="ImmutableDictionary&lt;TKey, TValue&gt;"/> class.
......@@ -56,9 +56,9 @@ private ImmutableDictionary(SortedInt32KeyNode<HashBucket> root, Comparers compa
{
Requires.NotNull(root, "root");
root.Freeze(FreezeBucketAction);
this.root = root;
this.count = count;
root.Freeze(s_FreezeBucketAction);
_root = root;
_count = count;
}
/// <summary>
......@@ -67,8 +67,8 @@ private ImmutableDictionary(SortedInt32KeyNode<HashBucket> root, Comparers compa
/// <param name="comparers">The comparers.</param>
private ImmutableDictionary(Comparers comparers = null)
{
this.comparers = comparers ?? Comparers.Get(EqualityComparer<TKey>.Default, EqualityComparer<TValue>.Default);
this.root = SortedInt32KeyNode<HashBucket>.EmptyNode;
_comparers = comparers ?? Comparers.Get(EqualityComparer<TKey>.Default, EqualityComparer<TValue>.Default);
_root = SortedInt32KeyNode<HashBucket>.EmptyNode;
}
/// <summary>
......@@ -125,7 +125,7 @@ internal enum OperationResult
/// </summary>
public ImmutableDictionary<TKey, TValue> Clear()
{
return this.IsEmpty ? this : EmptyWithComparers(this.comparers);
return this.IsEmpty ? this : EmptyWithComparers(_comparers);
}
/// <summary>
......@@ -133,7 +133,7 @@ internal enum OperationResult
/// </summary>
public int Count
{
get { return this.count; }
get { return _count; }
}
/// <summary>
......@@ -152,7 +152,7 @@ public bool IsEmpty
/// </summary>
public IEqualityComparer<TKey> KeyComparer
{
get { return this.comparers.KeyComparer; }
get { return _comparers.KeyComparer; }
}
/// <summary>
......@@ -160,7 +160,7 @@ public IEqualityComparer<TKey> KeyComparer
/// </summary>
public IEqualityComparer<TValue> ValueComparer
{
get { return this.comparers.ValueComparer; }
get { return _comparers.ValueComparer; }
}
/// <summary>
......@@ -170,7 +170,7 @@ public IEnumerable<TKey> Keys
{
get
{
foreach (var bucket in this.root)
foreach (var bucket in _root)
{
foreach (var item in bucket.Value)
{
......@@ -187,7 +187,7 @@ public IEnumerable<TValue> Values
{
get
{
foreach (var bucket in this.root)
foreach (var bucket in _root)
{
foreach (var item in bucket.Value)
{
......@@ -375,8 +375,8 @@ public Builder ToBuilder()
Requires.NotNull(keys, "keys");
Contract.Ensures(Contract.Result<ImmutableDictionary<TKey, TValue>>() != null);
int count = this.count;
var root = this.root;
int count = _count;
var root = _root;
foreach (var key in keys)
{
int hashCode = this.KeyComparer.GetHashCode(key);
......@@ -384,8 +384,8 @@ public Builder ToBuilder()
if (root.TryGetValue(hashCode, out bucket))
{
OperationResult result;
var newBucket = bucket.Remove(key, this.comparers.KeyOnlyComparer, out result);
root = UpdateRoot(root, hashCode, newBucket, this.comparers.HashBucketEqualityComparer);
var newBucket = bucket.Remove(key, _comparers.KeyOnlyComparer, out result);
root = UpdateRoot(root, hashCode, newBucket, _comparers.HashBucketEqualityComparer);
if (result == OperationResult.SizeChanged)
{
count--;
......@@ -466,8 +466,8 @@ public bool TryGetKey(TKey equalKey, out TKey actualKey)
// When the key comparer is the same but the value comparer is different, we don't need a whole new tree
// because the structure of the tree does not depend on the value comparer.
// We just need a new root node to store the new value comparer.
var comparers = this.comparers.WithValueComparer(valueComparer);
return new ImmutableDictionary<TKey, TValue>(this.root, comparers, this.count);
var comparers = _comparers.WithValueComparer(valueComparer);
return new ImmutableDictionary<TKey, TValue>(_root, comparers, _count);
}
}
else
......@@ -485,7 +485,7 @@ public bool TryGetKey(TKey equalKey, out TKey actualKey)
[Pure]
public ImmutableDictionary<TKey, TValue> WithComparers(IEqualityComparer<TKey> keyComparer)
{
return this.WithComparers(keyComparer, this.comparers.ValueComparer);
return this.WithComparers(keyComparer, _comparers.ValueComparer);
}
/// <summary>
......@@ -503,9 +503,9 @@ public bool TryGetKey(TKey equalKey, out TKey actualKey)
[Pure]
public bool ContainsValue(TValue value)
{
foreach (KeyValuePair<TKey, TValue> item in this)
foreach (KeyValuePair<TKey, TValue> item in this)
{
if (this.ValueComparer.Equals(value, item.Value))
if (this.ValueComparer.Equals(value, item.Value))
{
return true;
}
......@@ -521,7 +521,7 @@ public bool ContainsValue(TValue value)
/// </returns>
public Enumerator GetEnumerator()
{
return new Enumerator(this.root);
return new Enumerator(_root);
}
#endregion
......@@ -705,7 +705,7 @@ ICollection IDictionary.Values
/// </summary>
internal SortedInt32KeyNode<HashBucket> Root
{
get { return this.root; }
get { return _root; }
}
#region IDictionary Methods
......@@ -788,7 +788,7 @@ void ICollection.CopyTo(Array array, int arrayIndex)
Requires.Range(arrayIndex >= 0, "arrayIndex");
Requires.Range(array.Length >= arrayIndex + this.Count, "arrayIndex");
if (this.count == 0)
if (_count == 0)
{
return;
}
......@@ -872,7 +872,7 @@ IEnumerator IEnumerable.GetEnumerator()
{
Requires.NotNull(comparers, "comparers");
return Empty.comparers == comparers
return Empty._comparers == comparers
? Empty
: new ImmutableDictionary<TKey, TValue>(comparers);
}
......@@ -1080,9 +1080,9 @@ private static SortedInt32KeyNode<HashBucket> UpdateRoot(SortedInt32KeyNode<Hash
return this.Clear();
}
if (this.root != root)
if (_root != root)
{
return root.IsEmpty ? this.Clear() : new ImmutableDictionary<TKey, TValue>(root, this.comparers, adjustedCountIfDifferentRoot);
return root.IsEmpty ? this.Clear() : new ImmutableDictionary<TKey, TValue>(root, _comparers, adjustedCountIfDifferentRoot);
}
return this;
......
......@@ -352,7 +352,7 @@ private class ListOfTWrapper<T> : IOrderedCollection<T>
/// <summary>
/// The list being exposed.
/// </summary>
private readonly IList<T> collection;
private readonly IList<T> _collection;
/// <summary>
/// Initializes a new instance of the <see cref="ListOfTWrapper&lt;T&gt;"/> class.
......@@ -361,7 +361,7 @@ private class ListOfTWrapper<T> : IOrderedCollection<T>
internal ListOfTWrapper(IList<T> collection)
{
Requires.NotNull(collection, "collection");
this.collection = collection;
_collection = collection;
}
/// <summary>
......@@ -369,7 +369,7 @@ internal ListOfTWrapper(IList<T> collection)
/// </summary>
public int Count
{
get { return this.collection.Count; }
get { return _collection.Count; }
}
/// <summary>
......@@ -377,7 +377,7 @@ public int Count
/// </summary>
public T this[int index]
{
get { return this.collection[index]; }
get { return _collection[index]; }
}
/// <summary>
......@@ -388,7 +388,7 @@ public int Count
/// </returns>
public IEnumerator<T> GetEnumerator()
{
return this.collection.GetEnumerator();
return _collection.GetEnumerator();
}
/// <summary>
......@@ -412,12 +412,12 @@ private class FallbackWrapper<T> : IOrderedCollection<T>
/// <summary>
/// The original sequence.
/// </summary>
private readonly IEnumerable<T> sequence;
private readonly IEnumerable<T> _sequence;
/// <summary>
/// The list-ified sequence.
/// </summary>
private IList<T> collection;
private IList<T> _collection;
/// <summary>
/// Initializes a new instance of the <see cref="FallbackWrapper&lt;T&gt;"/> class.
......@@ -426,7 +426,7 @@ private class FallbackWrapper<T> : IOrderedCollection<T>
internal FallbackWrapper(IEnumerable<T> sequence)
{
Requires.NotNull(sequence, "sequence");
this.sequence = sequence;
_sequence = sequence;
}
/// <summary>
......@@ -436,18 +436,18 @@ public int Count
{
get
{
if (this.collection == null)
if (_collection == null)
{
int count;
if (this.sequence.TryGetCount(out count))
if (_sequence.TryGetCount(out count))
{
return count;
}
this.collection = this.sequence.ToArray();
_collection = _sequence.ToArray();
}
return this.collection.Count;
return _collection.Count;
}
}
......@@ -458,12 +458,12 @@ public int Count
{
get
{
if (this.collection == null)
if (_collection == null)
{
this.collection = this.sequence.ToArray();
_collection = _sequence.ToArray();
}
return this.collection[index];
return _collection[index];
}
}
......@@ -475,7 +475,7 @@ public int Count
/// </returns>
public IEnumerator<T> GetEnumerator()
{
return this.sequence.GetEnumerator();
return _sequence.GetEnumerator();
}
/// <summary>
......
......@@ -36,28 +36,28 @@ public sealed class Builder : IReadOnlyCollection<T>, ISet<T>
/// <summary>
/// The root of the binary tree that stores the collection. Contents are typically not entirely frozen.
/// </summary>
private SortedInt32KeyNode<HashBucket> root = SortedInt32KeyNode<HashBucket>.EmptyNode;
private SortedInt32KeyNode<HashBucket> _root = SortedInt32KeyNode<HashBucket>.EmptyNode;
/// <summary>
/// The equality comparer.
/// </summary>
private IEqualityComparer<T> equalityComparer;
private IEqualityComparer<T> _equalityComparer;
/// <summary>
/// The number of elements in this collection.
/// </summary>
private int count;
private int _count;
/// <summary>
/// Caches an immutable instance that represents the current state of the collection.
/// </summary>
/// <value>Null if no immutable view has been created for the current version.</value>
private ImmutableHashSet<T> immutable;
private ImmutableHashSet<T> _immutable;
/// <summary>
/// A number that increments every time the builder changes its contents.
/// </summary>
private int version;
private int _version;
/// <summary>
/// Initializes a new instance of the <see cref="ImmutableHashSet&lt;T&gt;.Builder"/> class.
......@@ -66,10 +66,10 @@ public sealed class Builder : IReadOnlyCollection<T>, ISet<T>
internal Builder(ImmutableHashSet<T> set)
{
Requires.NotNull(set, "set");
this.root = set.root;
this.count = set.count;
this.equalityComparer = set.equalityComparer;
this.immutable = set;
_root = set._root;
_count = set._count;
_equalityComparer = set._equalityComparer;
_immutable = set;
}
#region ISet<T> Properties
......@@ -80,7 +80,7 @@ internal Builder(ImmutableHashSet<T> set)
/// <returns>The number of elements contained in the <see cref="T:System.Collections.Generic.ICollection`1"/>.</returns>
public int Count
{
get { return this.count; }
get { return _count; }
}
/// <summary>
......@@ -104,21 +104,21 @@ public IEqualityComparer<T> KeyComparer
{
get
{
return this.equalityComparer;
return _equalityComparer;
}
set
{
Requires.NotNull(value, "value");
if (value != this.equalityComparer)
if (value != _equalityComparer)
{
var result = Union(this, new MutationInput(SortedInt32KeyNode<HashBucket>.EmptyNode, value, 0));
this.immutable = null;
this.equalityComparer = value;
_immutable = null;
_equalityComparer = value;
this.Root = result.Root;
this.count = result.Count; // whether the offset or absolute, since the base is 0, it's no difference.
_count = result.Count; // whether the offset or absolute, since the base is 0, it's no difference.
}
}
}
......@@ -128,7 +128,7 @@ public IEqualityComparer<T> KeyComparer
/// </summary>
internal int Version
{
get { return this.version; }
get { return _version; }
}
/// <summary>
......@@ -136,7 +136,7 @@ internal int Version
/// </summary>
private MutationInput Origin
{
get { return new MutationInput(this.Root, this.equalityComparer, this.count); }
get { return new MutationInput(this.Root, _equalityComparer, _count); }
}
/// <summary>
......@@ -146,7 +146,7 @@ private SortedInt32KeyNode<HashBucket> Root
{
get
{
return this.root;
return _root;
}
set
......@@ -154,14 +154,14 @@ private SortedInt32KeyNode<HashBucket> Root
// We *always* increment the version number because some mutations
// may not create a new value of root, although the existing root
// instance may have mutated.
this.version++;
_version++;
if (this.root != value)
if (_root != value)
{
this.root = value;
_root = value;
// Clear any cached value for the immutable view since it is now invalidated.
this.immutable = null;
_immutable = null;
}
}
}
......@@ -176,7 +176,7 @@ private SortedInt32KeyNode<HashBucket> Root
/// </returns>
public Enumerator GetEnumerator()
{
return new Enumerator(this.root, this);
return new Enumerator(_root, this);
}
/// <summary>
......@@ -192,12 +192,12 @@ public ImmutableHashSet<T> ToImmutable()
// Creating an instance of ImmutableSortedMap<T> with our root node automatically freezes our tree,
// ensuring that the returned instance is immutable. Any further mutations made to this builder
// will clone (and unfreeze) the spine of modified nodes until the next time this method is invoked.
if (this.immutable == null)
if (_immutable == null)
{
this.immutable = ImmutableHashSet<T>.Wrap(this.root, this.equalityComparer, this.count);
_immutable = ImmutableHashSet<T>.Wrap(_root, _equalityComparer, _count);
}
return this.immutable;
return _immutable;
}
#endregion
......@@ -249,7 +249,7 @@ public bool Contains(T item)
/// <exception cref="T:System.NotSupportedException">The <see cref="T:System.Collections.Generic.ICollection`1"/> is read-only. </exception>
public void Clear()
{
this.count = 0;
_count = 0;
this.Root = SortedInt32KeyNode<HashBucket>.EmptyNode;
}
......@@ -259,7 +259,7 @@ public void Clear()
/// <param name="other">The collection of items to remove from the set.</param>
public void ExceptWith(IEnumerable<T> other)
{
var result = ImmutableHashSet<T>.Except(other, this.equalityComparer, this.root);
var result = ImmutableHashSet<T>.Except(other, _equalityComparer, _root);
this.Apply(result);
}
......@@ -424,11 +424,11 @@ private void Apply(MutationResult result)
this.Root = result.Root;
if (result.CountType == CountType.Adjustment)
{
this.count += result.Count;
_count += result.Count;
}
else
{
this.count = result.Count;
_count = result.Count;
}
}
}
......
......@@ -16,12 +16,12 @@ internal class ImmutableHashSetDebuggerProxy<T>
/// <summary>
/// The collection to be enumerated.
/// </summary>
private readonly ImmutableHashSet<T> set;
private readonly ImmutableHashSet<T> _set;
/// <summary>
/// The simple view of the collection.
/// </summary>
private T[] contents;
private T[] _contents;
/// <summary>
/// Initializes a new instance of the <see cref="ImmutableHashSetDebuggerProxy&lt;T&gt;"/> class.
......@@ -30,7 +30,7 @@ internal class ImmutableHashSetDebuggerProxy<T>
public ImmutableHashSetDebuggerProxy(ImmutableHashSet<T> set)
{
Requires.NotNull(set, "set");
this.set = set;
_set = set;
}
/// <summary>
......@@ -41,12 +41,12 @@ public T[] Contents
{
get
{
if (this.contents == null)
if (_contents == null)
{
this.contents = this.set.ToArray(this.set.Count);
_contents = _set.ToArray(_set.Count);
}
return this.contents;
return _contents;
}
}
}
......
......@@ -18,22 +18,22 @@ public struct Enumerator : IEnumerator<T>, IStrongEnumerator<T>
/// <summary>
/// The builder being enumerated, if applicable.
/// </summary>
private readonly Builder builder;
private readonly Builder _builder;
/// <summary>
/// The enumerator over the sorted dictionary whose keys are hash values.
/// </summary>
private SortedInt32KeyNode<HashBucket>.Enumerator mapEnumerator;
private SortedInt32KeyNode<HashBucket>.Enumerator _mapEnumerator;
/// <summary>
/// The enumerator in use within an individual HashBucket.
/// </summary>
private HashBucket.Enumerator bucketEnumerator;
private HashBucket.Enumerator _bucketEnumerator;
/// <summary>
/// The version of the builder (when applicable) that is being enumerated.
/// </summary>
private int enumeratingBuilderVersion;
private int _enumeratingBuilderVersion;
/// <summary>
/// Initializes a new instance of the <see cref="ImmutableHashSet&lt;T&gt;.Enumerator" /> struct.
......@@ -42,10 +42,10 @@ public struct Enumerator : IEnumerator<T>, IStrongEnumerator<T>
/// <param name="builder">The builder, if applicable.</param>
internal Enumerator(SortedInt32KeyNode<HashBucket> root, Builder builder = null)
{
this.builder = builder;
this.mapEnumerator = new SortedInt32KeyNode<HashBucket>.Enumerator(root);
this.bucketEnumerator = default(HashBucket.Enumerator);
this.enumeratingBuilderVersion = builder != null ? builder.Version : -1;
_builder = builder;
_mapEnumerator = new SortedInt32KeyNode<HashBucket>.Enumerator(root);
_bucketEnumerator = default(HashBucket.Enumerator);
_enumeratingBuilderVersion = builder != null ? builder.Version : -1;
}
/// <summary>
......@@ -55,8 +55,8 @@ public T Current
{
get
{
this.mapEnumerator.ThrowIfDisposed();
return this.bucketEnumerator.Current;
_mapEnumerator.ThrowIfDisposed();
return _bucketEnumerator.Current;
}
}
......@@ -79,15 +79,15 @@ public bool MoveNext()
{
this.ThrowIfChanged();
if (this.bucketEnumerator.MoveNext())
if (_bucketEnumerator.MoveNext())
{
return true;
}
if (this.mapEnumerator.MoveNext())
if (_mapEnumerator.MoveNext())
{
this.bucketEnumerator = new HashBucket.Enumerator(this.mapEnumerator.Current.Value);
return this.bucketEnumerator.MoveNext();
_bucketEnumerator = new HashBucket.Enumerator(_mapEnumerator.Current.Value);
return _bucketEnumerator.MoveNext();
}
return false;
......@@ -99,12 +99,12 @@ public bool MoveNext()
/// <exception cref="T:System.InvalidOperationException">The collection was modified after the enumerator was created. </exception>
public void Reset()
{
this.enumeratingBuilderVersion = builder != null ? builder.Version : -1;
this.mapEnumerator.Reset();
_enumeratingBuilderVersion = _builder != null ? _builder.Version : -1;
_mapEnumerator.Reset();
// Reseting the bucket enumerator is pointless because we'll start on a new bucket later anyway.
this.bucketEnumerator.Dispose();
this.bucketEnumerator = default(HashBucket.Enumerator);
_bucketEnumerator.Dispose();
_bucketEnumerator = default(HashBucket.Enumerator);
}
/// <summary>
......@@ -112,8 +112,8 @@ public void Reset()
/// </summary>
public void Dispose()
{
this.mapEnumerator.Dispose();
this.bucketEnumerator.Dispose();
_mapEnumerator.Dispose();
_bucketEnumerator.Dispose();
}
/// <summary>
......@@ -122,7 +122,7 @@ public void Dispose()
/// <exception cref="System.InvalidOperationException">Thrown if the collection has changed.</exception>
private void ThrowIfChanged()
{
if (this.builder != null && this.builder.Version != this.enumeratingBuilderVersion)
if (_builder != null && _builder.Version != _enumeratingBuilderVersion)
{
throw new InvalidOperationException(Strings.CollectionModifiedDuringEnumeration);
}
......
......@@ -34,16 +34,16 @@ internal struct HashBucket
/// <summary>
/// One of the values in this bucket.
/// </summary>
private readonly T firstValue;
private readonly T _firstValue;
/// <summary>
/// Any other elements that hash to the same value.
/// </summary>
/// <value>
/// This is null if and only if the entire bucket is empty (including <see cref="firstValue"/>).
/// It's empty if <see cref="firstValue"/> has an element but no additional elements.
/// This is null if and only if the entire bucket is empty (including <see cref="_firstValue"/>).
/// It's empty if <see cref="_firstValue"/> has an element but no additional elements.
/// </value>
private readonly ImmutableList<T>.Node additionalElements;
private readonly ImmutableList<T>.Node _additionalElements;
/// <summary>
/// Initializes a new instance of the <see cref="HashBucket"/> struct.
......@@ -52,8 +52,8 @@ internal struct HashBucket
/// <param name="additionalElements">The additional elements.</param>
private HashBucket(T firstElement, ImmutableList<T>.Node additionalElements = null)
{
this.firstValue = firstElement;
this.additionalElements = additionalElements ?? ImmutableList<T>.Node.EmptyNode;
_firstValue = firstElement;
_additionalElements = additionalElements ?? ImmutableList<T>.Node.EmptyNode;
}
/// <summary>
......@@ -64,7 +64,7 @@ private HashBucket(T firstElement, ImmutableList<T>.Node additionalElements = nu
/// </value>
internal bool IsEmpty
{
get { return this.additionalElements == null; }
get { return _additionalElements == null; }
}
/// <summary>
......@@ -90,14 +90,14 @@ internal HashBucket Add(T value, IEqualityComparer<T> valueComparer, out Operati
return new HashBucket(value);
}
if (valueComparer.Equals(value, this.firstValue) || this.additionalElements.IndexOf(value, valueComparer) >= 0)
if (valueComparer.Equals(value, _firstValue) || _additionalElements.IndexOf(value, valueComparer) >= 0)
{
result = OperationResult.NoChangeRequired;
return this;
}
result = OperationResult.SizeChanged;
return new HashBucket(this.firstValue, this.additionalElements.Add(value));
return new HashBucket(_firstValue, _additionalElements.Add(value));
}
/// <summary>
......@@ -112,7 +112,7 @@ internal bool Contains(T value, IEqualityComparer<T> valueComparer)
return false;
}
return valueComparer.Equals(value, this.firstValue) || this.additionalElements.IndexOf(value, valueComparer) >= 0;
return valueComparer.Equals(value, _firstValue) || _additionalElements.IndexOf(value, valueComparer) >= 0;
}
/// <summary>
......@@ -128,16 +128,16 @@ internal bool TryExchange(T value, IEqualityComparer<T> valueComparer, out T exi
{
if (!this.IsEmpty)
{
if (valueComparer.Equals(value, this.firstValue))
if (valueComparer.Equals(value, _firstValue))
{
existingValue = this.firstValue;
existingValue = _firstValue;
return true;
}
int index = this.additionalElements.IndexOf(value, valueComparer);
int index = _additionalElements.IndexOf(value, valueComparer);
if (index >= 0)
{
existingValue = this.additionalElements[index];
existingValue = _additionalElements[index];
return true;
}
}
......@@ -161,9 +161,9 @@ internal HashBucket Remove(T value, IEqualityComparer<T> equalityComparer, out O
return this;
}
if (equalityComparer.Equals(this.firstValue, value))
if (equalityComparer.Equals(_firstValue, value))
{
if (this.additionalElements.IsEmpty)
if (_additionalElements.IsEmpty)
{
result = OperationResult.SizeChanged;
return new HashBucket();
......@@ -172,13 +172,13 @@ internal HashBucket Remove(T value, IEqualityComparer<T> equalityComparer, out O
{
// We can promote any element from the list into the first position, but it's most efficient
// to remove the root node in the binary tree that implements the list.
int indexOfRootNode = this.additionalElements.Left.Count;
int indexOfRootNode = _additionalElements.Left.Count;
result = OperationResult.SizeChanged;
return new HashBucket(this.additionalElements.Key, this.additionalElements.RemoveAt(indexOfRootNode));
return new HashBucket(_additionalElements.Key, _additionalElements.RemoveAt(indexOfRootNode));
}
}
int index = this.additionalElements.IndexOf(value, equalityComparer);
int index = _additionalElements.IndexOf(value, equalityComparer);
if (index < 0)
{
result = OperationResult.NoChangeRequired;
......@@ -187,7 +187,7 @@ internal HashBucket Remove(T value, IEqualityComparer<T> equalityComparer, out O
else
{
result = OperationResult.SizeChanged;
return new HashBucket(this.firstValue, this.additionalElements.RemoveAt(index));
return new HashBucket(_firstValue, _additionalElements.RemoveAt(index));
}
}
......@@ -196,9 +196,9 @@ internal HashBucket Remove(T value, IEqualityComparer<T> equalityComparer, out O
/// </summary>
internal void Freeze()
{
if (this.additionalElements != null)
if (_additionalElements != null)
{
this.additionalElements.Freeze();
_additionalElements.Freeze();
}
}
......@@ -210,22 +210,22 @@ internal struct Enumerator : IEnumerator<T>, IDisposable
/// <summary>
/// The bucket being enumerated.
/// </summary>
private readonly HashBucket bucket;
private readonly HashBucket _bucket;
/// <summary>
/// A value indicating whether this enumerator has been disposed.
/// </summary>
private bool disposed;
private bool _disposed;
/// <summary>
/// The current position of this enumerator.
/// </summary>
private Position currentPosition;
private Position _currentPosition;
/// <summary>
/// The enumerator that represents the current position over the additionalValues of the HashBucket.
/// </summary>
private ImmutableList<T>.Enumerator additionalEnumerator;
private ImmutableList<T>.Enumerator _additionalEnumerator;
/// <summary>
/// Initializes a new instance of the <see cref="ImmutableHashSet&lt;T&gt;.HashBucket.Enumerator"/> struct.
......@@ -233,10 +233,10 @@ internal struct Enumerator : IEnumerator<T>, IDisposable
/// <param name="bucket">The bucket.</param>
internal Enumerator(HashBucket bucket)
{
this.disposed = false;
this.bucket = bucket;
this.currentPosition = Position.BeforeFirst;
this.additionalEnumerator = default(ImmutableList<T>.Enumerator);
_disposed = false;
_bucket = bucket;
_currentPosition = Position.BeforeFirst;
_additionalEnumerator = default(ImmutableList<T>.Enumerator);
}
/// <summary>
......@@ -281,12 +281,12 @@ public T Current
get
{
this.ThrowIfDisposed();
switch (this.currentPosition)
switch (_currentPosition)
{
case Position.First:
return this.bucket.firstValue;
return _bucket._firstValue;
case Position.Additional:
return this.additionalEnumerator.Current;
return _additionalEnumerator.Current;
default:
throw new InvalidOperationException();
}
......@@ -303,29 +303,29 @@ public T Current
public bool MoveNext()
{
this.ThrowIfDisposed();
if (this.bucket.IsEmpty)
if (_bucket.IsEmpty)
{
this.currentPosition = Position.End;
_currentPosition = Position.End;
return false;
}
switch (this.currentPosition)
switch (_currentPosition)
{
case Position.BeforeFirst:
this.currentPosition = Position.First;
_currentPosition = Position.First;
return true;
case Position.First:
if (this.bucket.additionalElements.IsEmpty)
if (_bucket._additionalElements.IsEmpty)
{
this.currentPosition = Position.End;
_currentPosition = Position.End;
return false;
}
this.currentPosition = Position.Additional;
this.additionalEnumerator = new ImmutableList<T>.Enumerator(this.bucket.additionalElements);
return this.additionalEnumerator.MoveNext();
_currentPosition = Position.Additional;
_additionalEnumerator = new ImmutableList<T>.Enumerator(_bucket._additionalElements);
return _additionalEnumerator.MoveNext();
case Position.Additional:
return this.additionalEnumerator.MoveNext();
return _additionalEnumerator.MoveNext();
case Position.End:
return false;
default:
......@@ -340,8 +340,8 @@ public bool MoveNext()
public void Reset()
{
this.ThrowIfDisposed();
this.additionalEnumerator.Dispose();
this.currentPosition = Position.BeforeFirst;
_additionalEnumerator.Dispose();
_currentPosition = Position.BeforeFirst;
}
/// <summary>
......@@ -349,8 +349,8 @@ public void Reset()
/// </summary>
public void Dispose()
{
this.disposed = true;
this.additionalEnumerator.Dispose();
_disposed = true;
_additionalEnumerator.Dispose();
}
/// <summary>
......@@ -358,7 +358,7 @@ public void Dispose()
/// </summary>
private void ThrowIfDisposed()
{
if (this.disposed)
if (_disposed)
{
Validation.Requires.FailObjectDisposed(this);
}
......
......@@ -20,17 +20,17 @@ private struct MutationInput
/// <summary>
/// The root of the data structure for the collection.
/// </summary>
private readonly SortedInt32KeyNode<HashBucket> root;
private readonly SortedInt32KeyNode<HashBucket> _root;
/// <summary>
/// The equality comparer.
/// </summary>
private readonly IEqualityComparer<T> equalityComparer;
private readonly IEqualityComparer<T> _equalityComparer;
/// <summary>
/// The current number of elements in the collection.
/// </summary>
private readonly int count;
private readonly int _count;
/// <summary>
/// Initializes a new instance of the <see cref="ImmutableHashSet&lt;T&gt;.MutationInput"/> struct.
......@@ -39,9 +39,9 @@ private struct MutationInput
internal MutationInput(ImmutableHashSet<T> set)
{
Requires.NotNull(set, "set");
this.root = set.root;
this.equalityComparer = set.equalityComparer;
this.count = set.count;
_root = set._root;
_equalityComparer = set._equalityComparer;
_count = set._count;
}
/// <summary>
......@@ -55,9 +55,9 @@ internal MutationInput(SortedInt32KeyNode<HashBucket> root, IEqualityComparer<T>
Requires.NotNull(root, "root");
Requires.NotNull(equalityComparer, "equalityComparer");
Requires.Range(count >= 0, "count");
this.root = root;
this.equalityComparer = equalityComparer;
this.count = count;
_root = root;
_equalityComparer = equalityComparer;
_count = count;
}
/// <summary>
......@@ -65,7 +65,7 @@ internal MutationInput(SortedInt32KeyNode<HashBucket> root, IEqualityComparer<T>
/// </summary>
internal SortedInt32KeyNode<HashBucket> Root
{
get { return this.root; }
get { return _root; }
}
/// <summary>
......@@ -73,7 +73,7 @@ internal SortedInt32KeyNode<HashBucket> Root
/// </summary>
internal IEqualityComparer<T> EqualityComparer
{
get { return this.equalityComparer; }
get { return _equalityComparer; }
}
/// <summary>
......@@ -81,7 +81,7 @@ internal IEqualityComparer<T> EqualityComparer
/// </summary>
internal int Count
{
get { return this.count; }
get { return _count; }
}
}
}
......
......@@ -34,19 +34,19 @@ private struct MutationResult
/// <summary>
/// The root node of the data structure after the mutation.
/// </summary>
private readonly SortedInt32KeyNode<HashBucket> root;
private readonly SortedInt32KeyNode<HashBucket> _root;
/// <summary>
/// Either the number of elements added or removed from the collection as a result of the operation (a negative number represents removed elements),
/// or the total number of elements in the collection after the mutation. The appropriate interpretation of this value is indicated by the
/// <see cref="countType"/> field.
/// <see cref="_countType"/> field.
/// </summary>
private readonly int count;
private readonly int _count;
/// <summary>
/// Whether to consider the <see cref="count"/> field to be a count adjustment or total count.
/// Whether to consider the <see cref="_count"/> field to be a count adjustment or total count.
/// </summary>
private readonly CountType countType;
private readonly CountType _countType;
/// <summary>
/// Initializes a new instance of the <see cref="ImmutableHashSet&lt;T&gt;.MutationResult"/> struct.
......@@ -57,9 +57,9 @@ private struct MutationResult
internal MutationResult(SortedInt32KeyNode<HashBucket> root, int count, CountType countType = ImmutableHashSet<T>.CountType.Adjustment)
{
Requires.NotNull(root, "root");
this.root = root;
this.count = count;
this.countType = countType;
_root = root;
_count = count;
_countType = countType;
}
/// <summary>
......@@ -67,7 +67,7 @@ internal MutationResult(SortedInt32KeyNode<HashBucket> root, int count, CountTyp
/// </summary>
internal SortedInt32KeyNode<HashBucket> Root
{
get { return this.root; }
get { return _root; }
}
/// <summary>
......@@ -77,7 +77,7 @@ internal SortedInt32KeyNode<HashBucket> Root
/// </summary>
internal int Count
{
get { return this.count; }
get { return _count; }
}
/// <summary>
......@@ -85,7 +85,7 @@ internal int Count
/// </summary>
internal CountType CountType
{
get { return this.countType; }
get { return _countType; }
}
/// <summary>
......@@ -99,7 +99,7 @@ internal ImmutableHashSet<T> Finalize(ImmutableHashSet<T> priorSet)
int count = this.Count;
if (this.CountType == ImmutableHashSet<T>.CountType.Adjustment)
{
count += priorSet.count;
count += priorSet._count;
}
return priorSet.Wrap(this.Root, count);
......
......@@ -20,7 +20,7 @@ private struct NodeEnumerable : IEnumerable<T>
/// <summary>
/// The root of the sorted dictionary to enumerate.
/// </summary>
private readonly SortedInt32KeyNode<HashBucket> root;
private readonly SortedInt32KeyNode<HashBucket> _root;
/// <summary>
/// Initializes a new instance of the <see cref="ImmutableHashSet&lt;T&gt;.NodeEnumerable"/> struct.
......@@ -29,7 +29,7 @@ private struct NodeEnumerable : IEnumerable<T>
internal NodeEnumerable(SortedInt32KeyNode<HashBucket> root)
{
Requires.NotNull(root, "root");
this.root = root;
_root = root;
}
/// <summary>
......@@ -40,7 +40,7 @@ internal NodeEnumerable(SortedInt32KeyNode<HashBucket> root)
/// </returns>
public Enumerator GetEnumerator()
{
return new Enumerator(this.root);
return new Enumerator(_root);
}
/// <summary>
......
......@@ -27,22 +27,22 @@ public sealed partial class ImmutableHashSet<T> : IImmutableSet<T>, IHashKeyColl
/// <summary>
/// The singleton delegate that freezes the contents of hash buckets when the root of the data structure is frozen.
/// </summary>
private static readonly Action<KeyValuePair<int, HashBucket>> FreezeBucketAction = (kv) => kv.Value.Freeze();
private static readonly Action<KeyValuePair<int, HashBucket>> s_FreezeBucketAction = (kv) => kv.Value.Freeze();
/// <summary>
/// The equality comparer used to hash the elements in the collection.
/// </summary>
private readonly IEqualityComparer<T> equalityComparer;
private readonly IEqualityComparer<T> _equalityComparer;
/// <summary>
/// The number of elements in this collection.
/// </summary>
private readonly int count;
private readonly int _count;
/// <summary>
/// The sorted dictionary that this hash set wraps. The key is the hash code and the value is the bucket of all items that hashed to it.
/// </summary>
private readonly SortedInt32KeyNode<HashBucket> root;
private readonly SortedInt32KeyNode<HashBucket> _root;
/// <summary>
/// Initializes a new instance of the <see cref="ImmutableHashSet&lt;T&gt;"/> class.
......@@ -64,10 +64,10 @@ private ImmutableHashSet(SortedInt32KeyNode<HashBucket> root, IEqualityComparer<
Requires.NotNull(root, "root");
Requires.NotNull(equalityComparer, "equalityComparer");
root.Freeze(FreezeBucketAction);
this.root = root;
this.count = count;
this.equalityComparer = equalityComparer;
root.Freeze(s_FreezeBucketAction);
_root = root;
_count = count;
_equalityComparer = equalityComparer;
}
/// <summary>
......@@ -77,7 +77,7 @@ public ImmutableHashSet<T> Clear()
{
Contract.Ensures(Contract.Result<ImmutableHashSet<T>>() != null);
Contract.Ensures(Contract.Result<ImmutableHashSet<T>>().IsEmpty);
return this.IsEmpty ? this : ImmutableHashSet<T>.Empty.WithComparer(this.equalityComparer);
return this.IsEmpty ? this : ImmutableHashSet<T>.Empty.WithComparer(_equalityComparer);
}
/// <summary>
......@@ -85,7 +85,7 @@ public ImmutableHashSet<T> Clear()
/// </summary>
public int Count
{
get { return this.count; }
get { return _count; }
}
/// <summary>
......@@ -103,7 +103,7 @@ public bool IsEmpty
/// </summary>
public IEqualityComparer<T> KeyComparer
{
get { return this.equalityComparer; }
get { return _equalityComparer; }
}
#endregion
......@@ -152,7 +152,7 @@ bool ICollection.IsSynchronized
/// </summary>
internal IBinaryTree Root
{
get { return this.root; }
get { return _root; }
}
/// <summary>
......@@ -225,11 +225,11 @@ public bool TryGetValue(T equalValue, out T actualValue)
{
Requires.NotNullAllowStructs(equalValue, "value");
int hashCode = this.equalityComparer.GetHashCode(equalValue);
int hashCode = _equalityComparer.GetHashCode(equalValue);
HashBucket bucket;
if (this.root.TryGetValue(hashCode, out bucket))
if (_root.TryGetValue(hashCode, out bucket))
{
return bucket.TryExchange(equalValue, this.equalityComparer, out actualValue);
return bucket.TryExchange(equalValue, _equalityComparer, out actualValue);
}
actualValue = equalValue;
......@@ -268,7 +268,7 @@ public ImmutableHashSet<T> Except(IEnumerable<T> other)
{
Requires.NotNull(other, "other");
var result = Except(other, this.equalityComparer, this.root);
var result = Except(other, _equalityComparer, _root);
return result.Finalize(this);
}
......@@ -451,7 +451,7 @@ public ImmutableHashSet<T> WithComparer(IEqualityComparer<T> equalityComparer)
equalityComparer = EqualityComparer<T>.Default;
}
if (equalityComparer == this.equalityComparer)
if (equalityComparer == _equalityComparer)
{
return this;
}
......@@ -573,7 +573,7 @@ void ICollection.CopyTo(Array array, int arrayIndex)
Requires.Range(arrayIndex >= 0, "arrayIndex");
Requires.Range(array.Length >= arrayIndex + this.Count, "arrayIndex");
if (this.count == 0)
if (_count == 0)
{
return;
}
......@@ -598,7 +598,7 @@ void ICollection.CopyTo(Array array, int arrayIndex)
/// </returns>
public Enumerator GetEnumerator()
{
return new Enumerator(this.root);
return new Enumerator(_root);
}
/// <summary>
......@@ -1017,7 +1017,7 @@ private static ImmutableHashSet<T> Wrap(SortedInt32KeyNode<HashBucket> root, IEq
/// <returns>The immutable collection.</returns>
private ImmutableHashSet<T> Wrap(SortedInt32KeyNode<HashBucket> root, int adjustedCountIfDifferentRoot)
{
return (root != this.root) ? new ImmutableHashSet<T>(root, this.equalityComparer, adjustedCountIfDifferentRoot) : this;
return (root != _root) ? new ImmutableHashSet<T>(root, _equalityComparer, adjustedCountIfDifferentRoot) : this;
}
/// <summary>
......
// Copyright (c) Microsoft. All rights reserved.
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
......@@ -38,23 +38,23 @@ public sealed class Builder : IList<T>, IList, IOrderedCollection<T>, IImmutable
/// <summary>
/// The binary tree used to store the contents of the list. Contents are typically not entirely frozen.
/// </summary>
private Node root = Node.EmptyNode;
private Node _root = Node.EmptyNode;
/// <summary>
/// Caches an immutable instance that represents the current state of the collection.
/// </summary>
/// <value>Null if no immutable view has been created for the current version.</value>
private ImmutableList<T> immutable;
private ImmutableList<T> _immutable;
/// <summary>
/// A number that increments every time the builder changes its contents.
/// </summary>
private int version;
private int _version;
/// <summary>
/// The object callers may use to synchronize access to this collection.
/// </summary>
private object syncRoot;
private object _syncRoot;
/// <summary>
/// Initializes a new instance of the <see cref="Builder"/> class.
......@@ -63,8 +63,8 @@ public sealed class Builder : IList<T>, IList, IOrderedCollection<T>, IImmutable
internal Builder(ImmutableList<T> list)
{
Requires.NotNull(list, "list");
this.root = list.root;
this.immutable = list;
_root = list._root;
_immutable = list;
}
#region IList<T> Properties
......@@ -93,7 +93,7 @@ public int Count
/// </summary>
internal int Version
{
get { return this.version; }
get { return _version; }
}
/// <summary>
......@@ -103,7 +103,7 @@ internal Node Root
{
get
{
return this.root;
return _root;
}
private set
......@@ -111,14 +111,14 @@ private set
// We *always* increment the version number because some mutations
// may not create a new value of root, although the existing root
// instance may have mutated.
this.version++;
_version++;
if (this.root != value)
if (_root != value)
{
this.root = value;
_root = value;
// Clear any cached value for the immutable view since it is now invalidated.
this.immutable = null;
_immutable = null;
}
}
}
......@@ -286,7 +286,7 @@ public void CopyTo(T[] array)
{
Requires.NotNull(array, "array");
Requires.Range(array.Length >= this.Count, "array");
this.root.CopyTo(array);
_root.CopyTo(array);
}
/// <summary>
......@@ -305,7 +305,7 @@ public void CopyTo(T[] array, int arrayIndex)
{
Requires.NotNull(array, "array");
Requires.Range(array.Length >= arrayIndex + this.Count, "arrayIndex");
this.root.CopyTo(array, arrayIndex);
_root.CopyTo(array, arrayIndex);
}
/// <summary>
......@@ -326,7 +326,7 @@ public void CopyTo(T[] array, int arrayIndex)
/// <param name="count">The number of elements to copy.</param>
public void CopyTo(int index, T[] array, int arrayIndex, int count)
{
this.root.CopyTo(index, array, arrayIndex, count);
_root.CopyTo(index, array, arrayIndex, count);
}
/// <summary>
......@@ -368,7 +368,7 @@ public ImmutableList<T> GetRange(int index, int count)
public ImmutableList<TOutput> ConvertAll<TOutput>(Func<T, TOutput> converter)
{
Requires.NotNull(converter, "converter");
return ImmutableList<TOutput>.WrapNode(this.root.ConvertAll(converter));
return ImmutableList<TOutput>.WrapNode(_root.ConvertAll(converter));
}
/// <summary>
......@@ -387,7 +387,7 @@ public ImmutableList<TOutput> ConvertAll<TOutput>(Func<T, TOutput> converter)
public bool Exists(Predicate<T> match)
{
Requires.NotNull(match, "match");
return this.root.Exists(match);
return _root.Exists(match);
}
/// <summary>
......@@ -405,7 +405,7 @@ public bool Exists(Predicate<T> match)
public T Find(Predicate<T> match)
{
Requires.NotNull(match, "match");
return this.root.Find(match);
return _root.Find(match);
}
/// <summary>
......@@ -424,7 +424,7 @@ public T Find(Predicate<T> match)
public ImmutableList<T> FindAll(Predicate<T> match)
{
Requires.NotNull(match, "match");
return this.root.FindAll(match);
return _root.FindAll(match);
}
/// <summary>
......@@ -443,7 +443,7 @@ public ImmutableList<T> FindAll(Predicate<T> match)
public int FindIndex(Predicate<T> match)
{
Requires.NotNull(match, "match");
return this.root.FindIndex(match);
return _root.FindIndex(match);
}
/// <summary>
......@@ -463,7 +463,7 @@ public int FindIndex(int startIndex, Predicate<T> match)
Requires.NotNull(match, "match");
Requires.Range(startIndex >= 0, "startIndex");
Requires.Range(startIndex <= this.Count, "startIndex");
return this.root.FindIndex(startIndex, match);
return _root.FindIndex(startIndex, match);
}
/// <summary>
......@@ -486,7 +486,7 @@ public int FindIndex(int startIndex, int count, Predicate<T> match)
Requires.Range(count >= 0, "count");
Requires.Range(startIndex + count <= this.Count, "count");
return this.root.FindIndex(startIndex, count, match);
return _root.FindIndex(startIndex, count, match);
}
/// <summary>
......@@ -504,7 +504,7 @@ public int FindIndex(int startIndex, int count, Predicate<T> match)
public T FindLast(Predicate<T> match)
{
Requires.NotNull(match, "match");
return this.root.FindLast(match);
return _root.FindLast(match);
}
/// <summary>
......@@ -523,7 +523,7 @@ public T FindLast(Predicate<T> match)
public int FindLastIndex(Predicate<T> match)
{
Requires.NotNull(match, "match");
return this.root.FindLastIndex(match);
return _root.FindLastIndex(match);
}
/// <summary>
......@@ -544,7 +544,7 @@ public int FindLastIndex(int startIndex, Predicate<T> match)
Requires.NotNull(match, "match");
Requires.Range(startIndex >= 0, "startIndex");
Requires.Range(startIndex == 0 || startIndex < this.Count, "startIndex");
return this.root.FindLastIndex(startIndex, match);
return _root.FindLastIndex(startIndex, match);
}
/// <summary>
......@@ -570,7 +570,7 @@ public int FindLastIndex(int startIndex, int count, Predicate<T> match)
Requires.Range(count <= this.Count, "count");
Requires.Range(startIndex - count + 1 >= 0, "startIndex");
return this.root.FindLastIndex(startIndex, count, match);
return _root.FindLastIndex(startIndex, count, match);
}
/// <summary>
......@@ -594,7 +594,7 @@ public int FindLastIndex(int startIndex, int count, Predicate<T> match)
[Pure]
public int IndexOf(T item, int index)
{
return this.root.IndexOf(item, index, this.Count - index, EqualityComparer<T>.Default);
return _root.IndexOf(item, index, this.Count - index, EqualityComparer<T>.Default);
}
/// <summary>
......@@ -621,7 +621,7 @@ public int IndexOf(T item, int index)
[Pure]
public int IndexOf(T item, int index, int count)
{
return this.root.IndexOf(item, index, count, EqualityComparer<T>.Default);
return _root.IndexOf(item, index, count, EqualityComparer<T>.Default);
}
/// <summary>
......@@ -651,7 +651,7 @@ public int IndexOf(T item, int index, int count, IEqualityComparer<T> equalityCo
{
Requires.NotNull(equalityComparer, "equalityComparer");
return this.root.IndexOf(item, index, count, equalityComparer);
return _root.IndexOf(item, index, count, equalityComparer);
}
/// <summary>
......@@ -677,7 +677,7 @@ public int LastIndexOf(T item)
return -1;
}
return this.root.LastIndexOf(item, this.Count - 1, this.Count, EqualityComparer<T>.Default);
return _root.LastIndexOf(item, this.Count - 1, this.Count, EqualityComparer<T>.Default);
}
/// <summary>
......@@ -704,7 +704,7 @@ public int LastIndexOf(T item, int startIndex)
return -1;
}
return this.root.LastIndexOf(item, startIndex, startIndex + 1, EqualityComparer<T>.Default);
return _root.LastIndexOf(item, startIndex, startIndex + 1, EqualityComparer<T>.Default);
}
/// <summary>
......@@ -727,7 +727,7 @@ public int LastIndexOf(T item, int startIndex)
[Pure]
public int LastIndexOf(T item, int startIndex, int count)
{
return this.root.LastIndexOf(item, startIndex, count, EqualityComparer<T>.Default);
return _root.LastIndexOf(item, startIndex, count, EqualityComparer<T>.Default);
}
/// <summary>
......@@ -751,7 +751,7 @@ public int LastIndexOf(T item, int startIndex, int count)
[Pure]
public int LastIndexOf(T item, int startIndex, int count, IEqualityComparer<T> equalityComparer)
{
return this.root.LastIndexOf(item, startIndex, count, equalityComparer);
return _root.LastIndexOf(item, startIndex, count, equalityComparer);
}
/// <summary>
......@@ -770,7 +770,7 @@ public int LastIndexOf(T item, int startIndex, int count, IEqualityComparer<T> e
public bool TrueForAll(Predicate<T> match)
{
Requires.NotNull(match, "match");
return this.root.TrueForAll(match);
return _root.TrueForAll(match);
}
#endregion
......@@ -1006,12 +1006,12 @@ public ImmutableList<T> ToImmutable()
// Creating an instance of ImmutableList<T> with our root node automatically freezes our tree,
// ensuring that the returned instance is immutable. Any further mutations made to this builder
// will clone (and unfreeze) the spine of modified nodes until the next time this method is invoked.
if (this.immutable == null)
if (_immutable == null)
{
this.immutable = ImmutableList<T>.WrapNode(this.Root);
_immutable = ImmutableList<T>.WrapNode(this.Root);
}
return this.immutable;
return _immutable;
}
#endregion
......@@ -1160,12 +1160,12 @@ object ICollection.SyncRoot
{
get
{
if (this.syncRoot == null)
if (_syncRoot == null)
{
System.Threading.Interlocked.CompareExchange<Object>(ref this.syncRoot, new Object(), null);
System.Threading.Interlocked.CompareExchange<Object>(ref _syncRoot, new Object(), null);
}
return this.syncRoot;
return _syncRoot;
}
}
#endregion
......@@ -1181,13 +1181,13 @@ internal class ImmutableListBuilderDebuggerProxy<T>
/// <summary>
/// The collection to be enumerated.
/// </summary>
private readonly ImmutableList<T>.Builder list;
private readonly ImmutableList<T>.Builder _list;
/// <summary>
/// The simple view of the collection.
/// </summary>
private T[] cachedContents;
private T[] _cachedContents;
/// <summary>
/// Initializes a new instance of the <see cref="ImmutableListBuilderDebuggerProxy&lt;T&gt;"/> class.
/// </summary>
......@@ -1195,7 +1195,7 @@ internal class ImmutableListBuilderDebuggerProxy<T>
public ImmutableListBuilderDebuggerProxy(ImmutableList<T>.Builder builder)
{
Requires.NotNull(builder, "builder");
this.list = builder;
_list = builder;
}
/// <summary>
......@@ -1206,12 +1206,12 @@ public T[] Contents
{
get
{
if (this.cachedContents == null)
if (_cachedContents == null)
{
this.cachedContents = this.list.ToArray(this.list.Count);
_cachedContents = _list.ToArray(_list.Count);
}
return this.cachedContents;
return _cachedContents;
}
}
}
......
......@@ -28,22 +28,22 @@ public sealed class ImmutableQueue<T> : IImmutableQueue<T>
/// Additional instances representing the empty queue may exist on deserialized instances.
/// Actually since this queue is a struct, instances don't even apply and there are no singletons.
/// </remarks>
private static readonly ImmutableQueue<T> EmptyField = new ImmutableQueue<T>(ImmutableStack<T>.Empty, ImmutableStack<T>.Empty);
private static readonly ImmutableQueue<T> s_EmptyField = new ImmutableQueue<T>(ImmutableStack<T>.Empty, ImmutableStack<T>.Empty);
/// <summary>
/// The end of the queue that enqueued elements are pushed onto.
/// </summary>
private readonly ImmutableStack<T> backwards;
private readonly ImmutableStack<T> _backwards;
/// <summary>
/// The end of the queue from which elements are dequeued.
/// </summary>
private readonly ImmutableStack<T> forwards;
private readonly ImmutableStack<T> _forwards;
/// <summary>
/// Backing field for the <see cref="BackwardsReversed"/> property.
/// </summary>
private ImmutableStack<T> backwardsReversed;
private ImmutableStack<T> _backwardsReversed;
/// <summary>
/// Initializes a new instance of the <see cref="ImmutableQueue&lt;T&gt;"/> class.
......@@ -55,9 +55,9 @@ private ImmutableQueue(ImmutableStack<T> forward, ImmutableStack<T> backward)
Requires.NotNull(forward, "forward");
Requires.NotNull(backward, "backward");
this.forwards = forward;
this.backwards = backward;
this.backwardsReversed = null;
_forwards = forward;
_backwards = backward;
_backwardsReversed = null;
}
/// <summary>
......@@ -66,7 +66,7 @@ private ImmutableQueue(ImmutableStack<T> forward, ImmutableStack<T> backward)
public ImmutableQueue<T> Clear()
{
Contract.Ensures(Contract.Result<ImmutableQueue<T>>().IsEmpty);
Contract.Assume(EmptyField.IsEmpty);
Contract.Assume(s_EmptyField.IsEmpty);
return Empty;
}
......@@ -78,7 +78,7 @@ public ImmutableQueue<T> Clear()
/// </value>
public bool IsEmpty
{
get { return this.forwards.IsEmpty && this.backwards.IsEmpty; }
get { return _forwards.IsEmpty && _backwards.IsEmpty; }
}
/// <summary>
......@@ -89,8 +89,8 @@ public static ImmutableQueue<T> Empty
get
{
Contract.Ensures(Contract.Result<ImmutableQueue<T>>().IsEmpty);
Contract.Assume(EmptyField.IsEmpty);
return EmptyField;
Contract.Assume(s_EmptyField.IsEmpty);
return s_EmptyField;
}
}
......@@ -99,12 +99,12 @@ public static ImmutableQueue<T> Empty
/// </summary>
IImmutableQueue<T> IImmutableQueue<T>.Clear()
{
Contract.Assume(EmptyField.IsEmpty);
Contract.Assume(s_EmptyField.IsEmpty);
return this.Clear();
}
/// <summary>
/// Gets the reversed <see cref="backwards"/> stack.
/// Gets the reversed <see cref="_backwards"/> stack.
/// </summary>
private ImmutableStack<T> BackwardsReversed
{
......@@ -115,12 +115,12 @@ private ImmutableStack<T> BackwardsReversed
// Although this is a lazy-init pattern, no lock is required because
// this instance is immutable otherwise, and a double-assignment from multiple
// threads is harmless.
if (this.backwardsReversed == null)
if (_backwardsReversed == null)
{
this.backwardsReversed = this.backwards.Reverse();
_backwardsReversed = _backwards.Reverse();
}
return this.backwardsReversed;
return _backwardsReversed;
}
}
......@@ -136,7 +136,7 @@ public T Peek()
throw new InvalidOperationException(Strings.InvalidEmptyOperation);
}
return this.forwards.Peek();
return _forwards.Peek();
}
/// <summary>
......@@ -157,7 +157,7 @@ public ImmutableQueue<T> Enqueue(T value)
}
else
{
return new ImmutableQueue<T>(this.forwards, this.backwards.Push(value));
return new ImmutableQueue<T>(_forwards, _backwards.Push(value));
}
}
......@@ -187,12 +187,12 @@ public ImmutableQueue<T> Dequeue()
throw new InvalidOperationException(Strings.InvalidEmptyOperation);
}
ImmutableStack<T> f = this.forwards.Pop();
ImmutableStack<T> f = _forwards.Pop();
if (!f.IsEmpty)
{
return new ImmutableQueue<T>(f, this.backwards);
return new ImmutableQueue<T>(f, _backwards);
}
else if (this.backwards.IsEmpty)
else if (_backwards.IsEmpty)
{
return ImmutableQueue<T>.Empty;
}
......@@ -272,18 +272,18 @@ public struct Enumerator
/// <summary>
/// The original queue being enumerated.
/// </summary>
private readonly ImmutableQueue<T> originalQueue;
private readonly ImmutableQueue<T> _originalQueue;
/// <summary>
/// The remaining forwards stack of the queue being enumerated.
/// </summary>
private ImmutableStack<T> remainingForwardsStack;
private ImmutableStack<T> _remainingForwardsStack;
/// <summary>
/// The remaining backwards stack of the queue being enumerated.
/// Its order is reversed when the field is first initialized.
/// </summary>
private ImmutableStack<T> remainingBackwardsStack;
private ImmutableStack<T> _remainingBackwardsStack;
/// <summary>
/// Initializes a new instance of the <see cref="Enumerator"/> struct.
......@@ -291,11 +291,11 @@ public struct Enumerator
/// <param name="queue">The queue to enumerate.</param>
internal Enumerator(ImmutableQueue<T> queue)
{
this.originalQueue = queue;
_originalQueue = queue;
// The first call to MoveNext will initialize these.
this.remainingForwardsStack = null;
this.remainingBackwardsStack = null;
_remainingForwardsStack = null;
_remainingBackwardsStack = null;
}
/// <summary>
......@@ -305,19 +305,19 @@ public T Current
{
get
{
if (this.remainingForwardsStack == null)
if (_remainingForwardsStack == null)
{
// The initial call to MoveNext has not yet been made.
throw new InvalidOperationException();
}
if (!this.remainingForwardsStack.IsEmpty)
if (!_remainingForwardsStack.IsEmpty)
{
return this.remainingForwardsStack.Peek();
return _remainingForwardsStack.Peek();
}
else if (!this.remainingBackwardsStack.IsEmpty)
else if (!_remainingBackwardsStack.IsEmpty)
{
return this.remainingBackwardsStack.Peek();
return _remainingBackwardsStack.Peek();
}
else
{
......@@ -333,23 +333,23 @@ public T Current
/// <returns>A value indicating whether there is another element in the enumeration.</returns>
public bool MoveNext()
{
if (this.remainingForwardsStack == null)
if (_remainingForwardsStack == null)
{
// This is the initial step.
// Empty queues have no forwards or backwards
this.remainingForwardsStack = this.originalQueue.forwards;
this.remainingBackwardsStack = this.originalQueue.BackwardsReversed;
_remainingForwardsStack = _originalQueue._forwards;
_remainingBackwardsStack = _originalQueue.BackwardsReversed;
}
else if (!this.remainingForwardsStack.IsEmpty)
else if (!_remainingForwardsStack.IsEmpty)
{
this.remainingForwardsStack = this.remainingForwardsStack.Pop();
_remainingForwardsStack = _remainingForwardsStack.Pop();
}
else if (!this.remainingBackwardsStack.IsEmpty)
else if (!_remainingBackwardsStack.IsEmpty)
{
this.remainingBackwardsStack = this.remainingBackwardsStack.Pop();
_remainingBackwardsStack = _remainingBackwardsStack.Pop();
}
return !this.remainingForwardsStack.IsEmpty || !this.remainingBackwardsStack.IsEmpty;
return !_remainingForwardsStack.IsEmpty || !_remainingBackwardsStack.IsEmpty;
}
}
......@@ -361,23 +361,23 @@ private class EnumeratorObject : IEnumerator<T>
/// <summary>
/// The original queue being enumerated.
/// </summary>
private readonly ImmutableQueue<T> originalQueue;
private readonly ImmutableQueue<T> _originalQueue;
/// <summary>
/// The remaining forwards stack of the queue being enumerated.
/// </summary>
private ImmutableStack<T> remainingForwardsStack;
private ImmutableStack<T> _remainingForwardsStack;
/// <summary>
/// The remaining backwards stack of the queue being enumerated.
/// Its order is reversed when the field is first initialized.
/// </summary>
private ImmutableStack<T> remainingBackwardsStack;
private ImmutableStack<T> _remainingBackwardsStack;
/// <summary>
/// A value indicating whether this enumerator has been disposed.
/// </summary>
private bool disposed;
private bool _disposed;
/// <summary>
/// Initializes a new instance of the <see cref="Enumerator"/> struct.
......@@ -385,7 +385,7 @@ private class EnumeratorObject : IEnumerator<T>
/// <param name="queue">The queue to enumerate.</param>
internal EnumeratorObject(ImmutableQueue<T> queue)
{
this.originalQueue = queue;
_originalQueue = queue;
}
/// <summary>
......@@ -396,19 +396,19 @@ public T Current
get
{
this.ThrowIfDisposed();
if (this.remainingForwardsStack == null)
if (_remainingForwardsStack == null)
{
// The initial call to MoveNext has not yet been made.
throw new InvalidOperationException();
}
if (!this.remainingForwardsStack.IsEmpty)
if (!_remainingForwardsStack.IsEmpty)
{
return this.remainingForwardsStack.Peek();
return _remainingForwardsStack.Peek();
}
else if (!this.remainingBackwardsStack.IsEmpty)
else if (!_remainingBackwardsStack.IsEmpty)
{
return this.remainingBackwardsStack.Peek();
return _remainingBackwardsStack.Peek();
}
else
{
......@@ -433,23 +433,23 @@ object IEnumerator.Current
public bool MoveNext()
{
this.ThrowIfDisposed();
if (this.remainingForwardsStack == null)
if (_remainingForwardsStack == null)
{
// This is the initial step.
// Empty queues have no forwards or backwards
this.remainingForwardsStack = this.originalQueue.forwards;
this.remainingBackwardsStack = this.originalQueue.BackwardsReversed;
_remainingForwardsStack = _originalQueue._forwards;
_remainingBackwardsStack = _originalQueue.BackwardsReversed;
}
else if (!this.remainingForwardsStack.IsEmpty)
else if (!_remainingForwardsStack.IsEmpty)
{
this.remainingForwardsStack = this.remainingForwardsStack.Pop();
_remainingForwardsStack = _remainingForwardsStack.Pop();
}
else if (!this.remainingBackwardsStack.IsEmpty)
else if (!_remainingBackwardsStack.IsEmpty)
{
this.remainingBackwardsStack = this.remainingBackwardsStack.Pop();
_remainingBackwardsStack = _remainingBackwardsStack.Pop();
}
return !this.remainingForwardsStack.IsEmpty || !this.remainingBackwardsStack.IsEmpty;
return !_remainingForwardsStack.IsEmpty || !_remainingBackwardsStack.IsEmpty;
}
/// <summary>
......@@ -458,8 +458,8 @@ public bool MoveNext()
public void Reset()
{
this.ThrowIfDisposed();
this.remainingBackwardsStack = null;
this.remainingForwardsStack = null;
_remainingBackwardsStack = null;
_remainingForwardsStack = null;
}
/// <summary>
......@@ -467,7 +467,7 @@ public void Reset()
/// </summary>
public void Dispose()
{
this.disposed = true;
_disposed = true;
}
/// <summary>
......@@ -476,7 +476,7 @@ public void Dispose()
/// </summary>
private void ThrowIfDisposed()
{
if (this.disposed)
if (_disposed)
{
Validation.Requires.FailObjectDisposed(this);
}
......@@ -493,12 +493,12 @@ internal class ImmutableQueueDebuggerProxy<T>
/// <summary>
/// The collection to be enumerated.
/// </summary>
private readonly ImmutableQueue<T> queue;
private readonly ImmutableQueue<T> _queue;
/// <summary>
/// The simple view of the collection.
/// </summary>
private T[] contents;
private T[] _contents;
/// <summary>
/// Initializes a new instance of the <see cref="ImmutableQueueDebuggerProxy&lt;T&gt;"/> class.
......@@ -506,7 +506,7 @@ internal class ImmutableQueueDebuggerProxy<T>
/// <param name="queue">The collection to display in the debugger</param>
public ImmutableQueueDebuggerProxy(ImmutableQueue<T> queue)
{
this.queue = queue;
_queue = queue;
}
/// <summary>
......@@ -517,13 +517,13 @@ public T[] Contents
{
get
{
if (this.contents == null)
if (_contents == null)
{
this.contents = this.queue.ToArray();
_contents = _queue.ToArray();
}
return this.contents;
return _contents;
}
}
}
}
}
......@@ -36,38 +36,38 @@ public sealed class Builder : IDictionary<TKey, TValue>, IReadOnlyDictionary<TKe
/// <summary>
/// The binary tree used to store the contents of the map. Contents are typically not entirely frozen.
/// </summary>
private Node root = Node.EmptyNode;
private Node _root = Node.EmptyNode;
/// <summary>
/// The key comparer.
/// </summary>
private IComparer<TKey> keyComparer = Comparer<TKey>.Default;
private IComparer<TKey> _keyComparer = Comparer<TKey>.Default;
/// <summary>
/// The value comparer.
/// </summary>
private IEqualityComparer<TValue> valueComparer = EqualityComparer<TValue>.Default;
private IEqualityComparer<TValue> _valueComparer = EqualityComparer<TValue>.Default;
/// <summary>
/// The number of entries in the map.
/// </summary>
private int count;
private int _count;
/// <summary>
/// Caches an immutable instance that represents the current state of the collection.
/// </summary>
/// <value>Null if no immutable view has been created for the current version.</value>
private ImmutableSortedDictionary<TKey, TValue> immutable;
private ImmutableSortedDictionary<TKey, TValue> _immutable;
/// <summary>
/// A number that increments every time the builder changes its contents.
/// </summary>
private int version;
private int _version;
/// <summary>
/// The object callers may use to synchronize access to this collection.
/// </summary>
private object syncRoot;
private object _syncRoot;
/// <summary>
/// Initializes a new instance of the <see cref="Builder"/> class.
......@@ -76,11 +76,11 @@ public sealed class Builder : IDictionary<TKey, TValue>, IReadOnlyDictionary<TKe
internal Builder(ImmutableSortedDictionary<TKey, TValue> map)
{
Requires.NotNull(map, "map");
this.root = map.root;
this.keyComparer = map.KeyComparer;
this.valueComparer = map.ValueComparer;
this.count = map.Count;
this.immutable = map;
_root = map._root;
_keyComparer = map.KeyComparer;
_valueComparer = map.ValueComparer;
_count = map.Count;
_immutable = map;
}
#region IDictionary<TKey, TValue> Properties and Indexer
......@@ -122,7 +122,7 @@ public IEnumerable<TValue> Values
/// </summary>
public int Count
{
get { return this.count; }
get { return _count; }
}
/// <summary>
......@@ -141,7 +141,7 @@ public int Count
/// </summary>
internal int Version
{
get { return this.version; }
get { return _version; }
}
/// <summary>
......@@ -151,7 +151,7 @@ private Node Root
{
get
{
return this.root;
return _root;
}
set
......@@ -159,14 +159,14 @@ private Node Root
// We *always* increment the version number because some mutations
// may not create a new value of root, although the existing root
// instance may have mutated.
this.version++;
_version++;
if (this.root != value)
if (_root != value)
{
this.root = value;
_root = value;
// Clear any cached value for the immutable view since it is now invalidated.
this.immutable = null;
_immutable = null;
}
}
}
......@@ -194,10 +194,10 @@ private Node Root
set
{
bool replacedExistingValue, mutated;
this.Root = this.root.SetItem(key, value, this.keyComparer, this.valueComparer, out replacedExistingValue, out mutated);
this.Root = _root.SetItem(key, value, _keyComparer, _valueComparer, out replacedExistingValue, out mutated);
if (mutated && !replacedExistingValue)
{
this.count++;
_count++;
}
}
}
......@@ -260,12 +260,12 @@ object ICollection.SyncRoot
{
get
{
if (this.syncRoot == null)
if (_syncRoot == null)
{
Threading.Interlocked.CompareExchange<Object>(ref this.syncRoot, new Object(), null);
Threading.Interlocked.CompareExchange<Object>(ref _syncRoot, new Object(), null);
}
return this.syncRoot;
return _syncRoot;
}
}
......@@ -289,29 +289,29 @@ public IComparer<TKey> KeyComparer
{
get
{
return this.keyComparer;
return _keyComparer;
}
set
{
Requires.NotNull(value, "value");
if (value != this.keyComparer)
if (value != _keyComparer)
{
var newRoot = Node.EmptyNode;
int count = 0;
foreach (var item in this)
{
bool mutated;
newRoot = newRoot.Add(item.Key, item.Value, value, this.valueComparer, out mutated);
newRoot = newRoot.Add(item.Key, item.Value, value, _valueComparer, out mutated);
if (mutated)
{
count++;
}
}
this.keyComparer = value;
_keyComparer = value;
this.Root = newRoot;
this.count = count;
_count = count;
}
}
}
......@@ -326,19 +326,19 @@ public IEqualityComparer<TValue> ValueComparer
{
get
{
return this.valueComparer;
return _valueComparer;
}
set
{
Requires.NotNull(value, "value");
if (value != this.valueComparer)
if (value != _valueComparer)
{
// When the key comparer is the same but the value comparer is different, we don't need a whole new tree
// because the structure of the tree does not depend on the value comparer.
// We just need a new root node to store the new value comparer.
this.valueComparer = value;
this.immutable = null; // invalidate cached immutable
_valueComparer = value;
_immutable = null; // invalidate cached immutable
}
}
}
......@@ -425,10 +425,10 @@ void ICollection.CopyTo(Array array, int index)
public void Add(TKey key, TValue value)
{
bool mutated;
this.Root = this.Root.Add(key, value, this.keyComparer, this.valueComparer, out mutated);
this.Root = this.Root.Add(key, value, _keyComparer, _valueComparer, out mutated);
if (mutated)
{
this.count++;
_count++;
}
}
......@@ -437,7 +437,7 @@ public void Add(TKey key, TValue value)
/// </summary>
public bool ContainsKey(TKey key)
{
return this.Root.ContainsKey(key, this.keyComparer);
return this.Root.ContainsKey(key, _keyComparer);
}
/// <summary>
......@@ -446,10 +446,10 @@ public bool ContainsKey(TKey key)
public bool Remove(TKey key)
{
bool mutated;
this.Root = this.Root.Remove(key, this.keyComparer, out mutated);
this.Root = this.Root.Remove(key, _keyComparer, out mutated);
if (mutated)
{
this.count--;
_count--;
}
return mutated;
......@@ -460,7 +460,7 @@ public bool Remove(TKey key)
/// </summary>
public bool TryGetValue(TKey key, out TValue value)
{
return this.Root.TryGetValue(key, this.keyComparer, out value);
return this.Root.TryGetValue(key, _keyComparer, out value);
}
/// <summary>
......@@ -469,7 +469,7 @@ public bool TryGetValue(TKey key, out TValue value)
public bool TryGetKey(TKey equalKey, out TKey actualKey)
{
Requires.NotNullAllowStructs(equalKey, "equalKey");
return this.Root.TryGetKey(equalKey, this.keyComparer, out actualKey);
return this.Root.TryGetKey(equalKey, _keyComparer, out actualKey);
}
/// <summary>
......@@ -486,7 +486,7 @@ public void Add(KeyValuePair<TKey, TValue> item)
public void Clear()
{
this.Root = ImmutableSortedDictionary<TKey, TValue>.Node.EmptyNode;
this.count = 0;
_count = 0;
}
/// <summary>
......@@ -494,7 +494,7 @@ public void Clear()
/// </summary>
public bool Contains(KeyValuePair<TKey, TValue> item)
{
return this.Root.Contains(item, this.keyComparer, this.valueComparer);
return this.Root.Contains(item, _keyComparer, _valueComparer);
}
/// <summary>
......@@ -561,7 +561,7 @@ IEnumerator IEnumerable.GetEnumerator()
[Pure]
public bool ContainsValue(TValue value)
{
return this.root.ContainsValue(value, this.valueComparer);
return _root.ContainsValue(value, _valueComparer);
}
/// <summary>
......@@ -639,14 +639,13 @@ public TValue GetValueOrDefault(TKey key, TValue defaultValue)
// Creating an instance of ImmutableSortedMap<T> with our root node automatically freezes our tree,
// ensuring that the returned instance is immutable. Any further mutations made to this builder
// will clone (and unfreeze) the spine of modified nodes until the next time this method is invoked.
if (this.immutable == null)
if (_immutable == null)
{
this.immutable = Wrap(this.Root, this.count, this.keyComparer, this.valueComparer);
_immutable = Wrap(this.Root, _count, _keyComparer, _valueComparer);
}
return this.immutable;
return _immutable;
}
#endregion
}
}
......@@ -659,12 +658,12 @@ internal class ImmutableSortedDictionaryBuilderDebuggerProxy<TKey, TValue>
/// <summary>
/// The collection to be enumerated.
/// </summary>
private readonly ImmutableSortedDictionary<TKey, TValue>.Builder map;
private readonly ImmutableSortedDictionary<TKey, TValue>.Builder _map;
/// <summary>
/// The simple view of the collection.
/// </summary>
private KeyValuePair<TKey, TValue>[] contents;
private KeyValuePair<TKey, TValue>[] _contents;
/// <summary>
/// Initializes a new instance of the <see cref="ImmutableSortedDictionaryBuilderDebuggerProxy&lt;TKey, TValue&gt;"/> class.
......@@ -673,7 +672,7 @@ internal class ImmutableSortedDictionaryBuilderDebuggerProxy<TKey, TValue>
public ImmutableSortedDictionaryBuilderDebuggerProxy(ImmutableSortedDictionary<TKey, TValue>.Builder map)
{
Requires.NotNull(map, "map");
this.map = map;
_map = map;
}
/// <summary>
......@@ -684,12 +683,12 @@ public ImmutableSortedDictionaryBuilderDebuggerProxy(ImmutableSortedDictionary<T
{
get
{
if (this.contents == null)
if (_contents == null)
{
this.contents = this.map.ToArray(this.map.Count);
_contents = _map.ToArray(_map.Count);
}
return this.contents;
return _contents;
}
}
}
......
......@@ -18,12 +18,12 @@ internal abstract class KeysOrValuesCollectionAccessor<TKey, TValue, T> : IColle
/// <summary>
/// The underlying wrapped dictionary.
/// </summary>
private readonly IImmutableDictionary<TKey, TValue> dictionary;
private readonly IImmutableDictionary<TKey, TValue> _dictionary;
/// <summary>
/// The key or value enumerable that this instance wraps.
/// </summary>
private readonly IEnumerable<T> keysOrValues;
private readonly IEnumerable<T> _keysOrValues;
/// <summary>
/// Initializes a new instance of the <see cref="KeysOrValuesCollectionAccessor{TKey, TValue, T}"/> class.
......@@ -35,8 +35,8 @@ protected KeysOrValuesCollectionAccessor(IImmutableDictionary<TKey, TValue> dict
Requires.NotNull(dictionary, "dictionary");
Requires.NotNull(keysOrValues, "keysOrValues");
this.dictionary = dictionary;
this.keysOrValues = keysOrValues;
_dictionary = dictionary;
_keysOrValues = keysOrValues;
}
/// <summary>
......@@ -53,7 +53,7 @@ public bool IsReadOnly
/// <returns>The number of elements contained in the <see cref="T:System.Collections.Generic.ICollection`1"/>.</returns>
public int Count
{
get { return this.dictionary.Count; }
get { return _dictionary.Count; }
}
/// <summary>
......@@ -61,7 +61,7 @@ public int Count
/// </summary>
protected IImmutableDictionary<TKey, TValue> Dictionary
{
get { return this.dictionary; }
get { return _dictionary; }
}
/// <summary>
......@@ -113,7 +113,7 @@ public bool Remove(T item)
/// </summary>
public IEnumerator<T> GetEnumerator()
{
return this.keysOrValues.GetEnumerator();
return _keysOrValues.GetEnumerator();
}
/// <summary>
......
......@@ -15,7 +15,7 @@ internal class SecureObjectPool
/// <summary>
/// The ever-incrementing (and wrap-on-overflow) integer for owner id's.
/// </summary>
private static int poolUserIdCounter;
private static int s_poolUserIdCounter;
/// <summary>
/// The ID reserved for unassigned objects.
......@@ -30,7 +30,7 @@ internal static int NewId()
int result;
do
{
result = Interlocked.Increment(ref poolUserIdCounter);
result = Interlocked.Increment(ref s_poolUserIdCounter);
}
while (result == UnassignedId);
......@@ -81,13 +81,13 @@ internal interface ISecurePooledObjectUser
internal class SecurePooledObject<T>
{
private readonly T value;
private int owner;
private readonly T _value;
private int _owner;
internal SecurePooledObject(T newValue)
{
Requires.NotNullAllowStructs(newValue, "newValue");
this.value = newValue;
_value = newValue;
}
/// <summary>
......@@ -95,8 +95,8 @@ internal SecurePooledObject(T newValue)
/// </summary>
internal int Owner
{
get { return this.owner; }
set { this.owner = value; }
get { return _owner; }
set { _owner = value; }
}
/// <summary>
......@@ -111,7 +111,7 @@ internal T Use<TCaller>(ref TCaller caller)
{
if (!IsOwned(ref caller))
Requires.FailObjectDisposed(caller);
return this.value;
return _value;
}
internal bool TryUse<TCaller>(ref TCaller caller, out T value)
......@@ -119,7 +119,7 @@ internal bool TryUse<TCaller>(ref TCaller caller, out T value)
{
if (IsOwned(ref caller))
{
value = this.value;
value = _value;
return true;
}
else
......@@ -133,7 +133,7 @@ internal bool TryUse<TCaller>(ref TCaller caller, out T value)
internal bool IsOwned<TCaller>(ref TCaller caller)
where TCaller : struct, ISecurePooledObjectUser
{
return caller.PoolUserId == this.owner;
return caller.PoolUserId == _owner;
}
}
}
// Copyright (c) Microsoft. All rights reserved.
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using Validation;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册