Class TreeDictionary<TKey, TValue>
A sorted generic dictionary based on a red-black tree set.
A TreeDictionary<TKey, TValue> provides similar behavior to a
Inheritance
Implements
Namespace: Lucene.Net.Support
Assembly: Lucene.Net.dll
Syntax
public sealed class TreeDictionary<TKey, TValue> : System.Collections.Generic.IDictionary<TKey, TValue>, IDictionary, System.Collections.Generic.IReadOnlyCollection<System.Collections.Generic.KeyValuePair<TKey, TValue>>, System.Collections.Generic.IReadOnlyDictionary<TKey, TValue>
Type Parameters
Name | Description |
---|---|
TKey | The type of keys in the dictionary |
TValue | The type of values in the dictionary |
Remarks
Unordered Dictionaries
- use when order is not important and all keys are non-null. - HashMap<TKey, TValue> - use when order is not important and support for a null key is required.
Ordered Dictionaries
- LinkedHashMap<TKey, TValue> - use when you need to preserve entry insertion order. Keys are nullable.
- use when you need natural sort order. Keys must be unique. - TreeDictionary<TKey, TValue> - use when you need natural sort order. Keys are nullable.
- LurchTable<TKey, TValue> - use when you need to sort by most recent access or most recent update. Works well for LRU caching.
Constructors
| Improve this Doc View SourceTreeDictionary()
Create a red-black tree dictionary using the default
Declaration
public TreeDictionary()
TreeDictionary(System.Collections.Generic.IComparer<TKey>)
Create a red-black tree dictionary using the specified
Declaration
public TreeDictionary(System.Collections.Generic.IComparer<TKey> comparer)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IComparer<TKey> | comparer | The |
TreeDictionary(System.Collections.Generic.IDictionary<TKey, TValue>)
Create a red-black tree dictionary that contains the elements copied from the specified IDictionary<K, V>
and uses the default
Declaration
public TreeDictionary(System.Collections.Generic.IDictionary<TKey, TValue> dictionary)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IDictionary<TKey, TValue> | dictionary |
TreeDictionary(System.Collections.Generic.IDictionary<TKey, TValue>, System.Collections.Generic.IComparer<TKey>)
Create a red-black tree dictionary that contains the elements copied from the specified IDictionary<K, V>
and uses the specified
Declaration
public TreeDictionary(System.Collections.Generic.IDictionary<TKey, TValue> dictionary, System.Collections.Generic.IComparer<TKey> comparer)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IDictionary<TKey, TValue> | dictionary | |
System.Collections.Generic.IComparer<TKey> | comparer | The |
Properties
| Improve this Doc View SourceComparer
Gets the
Declaration
public System.Collections.Generic.IComparer<TKey> Comparer { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IComparer<TKey> |
Count
Gets the number of key/value pairs contained in the TreeDictionary<TKey, TValue>.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
System.Int32 |
IsReadOnly
Gets a value indicating whether the
Declaration
public bool IsReadOnly { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
Item[TKey]
Gets or sets the value associated with the specified key.
Declaration
public TValue this[TKey key] { get; set; }
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key of the value to get or set. |
Property Value
Type | Description |
---|---|
TValue | The value associated with the specified key. If the specified key is not found, a get operation throws a
|
Keys
Gets a collection containing the keys in the TreeDictionary<TKey, TValue>.
Declaration
public System.Collections.Generic.ICollection<TKey> Keys { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.ICollection<TKey> |
Values
Gets a collection containing the values in the TreeDictionary<TKey, TValue>.
Declaration
public System.Collections.Generic.ICollection<TValue> Values { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.ICollection<TValue> |
Methods
| Improve this Doc View SourceAdd(TKey, TValue)
Adds an element with the specified key and value into the TreeDictionary<TKey, TValue>.
Declaration
public void Add(TKey key, TValue value)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key of the element to add. |
TValue | value | The value of the element to add. The value can be |
Clear()
Removes all elements from the TreeDictionary<TKey, TValue>.
Declaration
public void Clear()
ContainsKey(TKey)
Determines whether the TreeDictionary<TKey, TValue> contains an element with the specified key.
Declaration
public bool ContainsKey(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key to locate in the TreeDictionary<TKey, TValue>. |
Returns
Type | Description |
---|---|
System.Boolean |
|
ContainsValue(TValue)
Determines whether the TreeDictionary<TKey, TValue> contains an element with the specified value.
Declaration
public bool ContainsValue(TValue value)
Parameters
Type | Name | Description |
---|---|---|
TValue | value | The value to locate in the TreeDictionary<TKey, TValue>. The value can be null for reference types. |
Returns
Type | Description |
---|---|
System.Boolean |
|
CopyTo(System.Collections.Generic.KeyValuePair<TKey, TValue>[], Int32)
Copies the elements of the TreeDictionary<TKey, TValue> to the specified
array
of index
.
Declaration
public void CopyTo(System.Collections.Generic.KeyValuePair<TKey, TValue>[] array, int index)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.KeyValuePair<TKey, TValue>[] | array | The one-dimensional array of |
System.Int32 | index | The zero-based index in |
Equals(Object)
Compares the specified object with this dictionary for equality. Returns true
if the
given object is also a map and the two maps represent the same mappings. More formally,
two dictionaries m1
and m2
represent the same mappings if the values of obj
match the values of this dictionary (without regard to order, but with regard to any nested collections).
Declaration
public override bool Equals(object obj)
Parameters
Type | Name | Description |
---|---|---|
System.Object | obj | Object to be compared for equality with this dictionary. |
Returns
Type | Description |
---|---|
System.Boolean |
|
GetEnumerator()
Returns an enumerator that iterates through the TreeDictionary<TKey, TValue>.
Declaration
public TreeDictionary<TKey, TValue>.Enumerator GetEnumerator()
Returns
Type | Description |
---|---|
TreeDictionary.Enumerator<> | An enumerator for the TreeDictionary<TKey, TValue>. |
GetHashCode()
Returns the hash code value for this dictionary. The hash code of a dictionary is defined to be
the sum of the hash codes of each entry in the dictionary. This ensures that m1.Equals(m2)
implies that m1.GetHashCode() == m2.GetHashCode()
for any two dictionaries m1
and m2
.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
System.Int32 | The hash code value for this dictionary. |
Remove(TKey)
Removes the element with the specified key from the TreeDictionary<TKey, TValue>.
Declaration
public bool Remove(TKey key)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key of the element to remove. |
Returns
Type | Description |
---|---|
System.Boolean |
|
ToString()
Returns a string representation of this dictionary. The string representation consists of a list of key-value mappings in the order returned by the dictionary's iterator, enclosed in braces ("{}"). Adjacent mappings are separated by the characters ", " (comma and space). Each key-value mapping is rendered as the key followed by an equals sign ("=") followed by the associated value.
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
System.String | A string representation of this dictionary. |
TryGetValue(TKey, out TValue)
Gets the value associated with the specified key.
Declaration
public bool TryGetValue(TKey key, out TValue value)
Parameters
Type | Name | Description |
---|---|---|
TKey | key | The key of the value to get. |
TValue | value | When this method returns, the value associated with the specified |
Returns
Type | Description |
---|---|
System.Boolean |