Show / Hide Table of Contents

    Class TreeDictionary<TKey, TValue>

    A sorted generic dictionary based on a red-black tree set.

    A TreeDictionary<TKey, TValue> provides similar behavior to a , except that TreeDictionary<TKey, TValue> allows elements with null or duplicate keys to be created, where a does not.

    Inheritance
    System.Object
    TreeDictionary<TKey, TValue>
    Implements
    Lucene.Net.Support.C5.IDictionary
    System.Collections.Generic.IReadOnlyCollection<System.Collections.Generic.KeyValuePair<TKey, TValue>>
    System.Collections.Generic.IReadOnlyDictionary<TKey, TValue>
    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 Source

    TreeDictionary()

    Create a red-black tree dictionary using the default for the key type. if the key type K is not comparable.

    Declaration
    public TreeDictionary()
    | Improve this Doc View Source

    TreeDictionary(System.Collections.Generic.IComparer<TKey>)

    Create a red-black tree dictionary using the specified for the key type.

    Declaration
    public TreeDictionary(System.Collections.Generic.IComparer<TKey> comparer)
    Parameters
    Type Name Description
    System.Collections.Generic.IComparer<TKey> comparer

    The implementation to use when comparing keys, or null to use the default for the type of the key.

    | Improve this Doc View Source

    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 for the key type.

    Declaration
    public TreeDictionary(System.Collections.Generic.IDictionary<TKey, TValue> dictionary)
    Parameters
    Type Name Description
    System.Collections.Generic.IDictionary<TKey, TValue> dictionary
    | Improve this Doc View Source

    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 for the key type.

    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 implementation to use when comparing keys, or null to use the default for the type of the key.

    Properties

    | Improve this Doc View Source

    Comparer

    Gets the used to order the elements of the TreeDictionary<TKey, TValue>.

    Declaration
    public System.Collections.Generic.IComparer<TKey> Comparer { get; }
    Property Value
    Type Description
    System.Collections.Generic.IComparer<TKey>
    | Improve this Doc View Source

    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
    | Improve this Doc View Source

    IsReadOnly

    Gets a value indicating whether the is read-only.

    Declaration
    public bool IsReadOnly { get; }
    Property Value
    Type Description
    System.Boolean
    | Improve this Doc View Source

    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 , and a set operation creates a new element with the specified key.

    | Improve this Doc View Source

    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>
    | Improve this Doc View Source

    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 Source

    Add(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 null for reference types.

    | Improve this Doc View Source

    Clear()

    Removes all elements from the TreeDictionary<TKey, TValue>.

    Declaration
    public void Clear()
    | Improve this Doc View Source

    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

    true if the TreeDictionary<TKey, TValue> contains an element with the specified key; otherwise, false.

    | Improve this Doc View Source

    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

    true if the TreeDictionary<TKey, TValue> contains an element with the specified value; otherwise, false.

    | Improve this Doc View Source

    CopyTo(System.Collections.Generic.KeyValuePair<TKey, TValue>[], Int32)

    Copies the elements of the TreeDictionary<TKey, TValue> to the specified array of structures, starting at the specified 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 structures that is the destination of the elements copied from the current TreeDictionary<TKey, TValue>. The array must have zero-based indexing.

    System.Int32 index

    The zero-based index in array at which copying begins.

    | Improve this Doc View Source

    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

    true if the specified object's values are equal to this dictionary.

    | Improve this Doc View Source

    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>.

    | Improve this Doc View Source

    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.

    | Improve this Doc View Source

    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

    true if the element is successfully removed; otherwise, false. This method also returns false if key is not found in the TreeDictionary<TKey, TValue>.

    | Improve this Doc View Source

    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.

    | Improve this Doc View Source

    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 key, if the key is found; otherwise, the default value for the type of the value parameter.

    Returns
    Type Description
    System.Boolean

    Implements

    Lucene.Net.Support.C5.IDictionary
    System.Collections.Generic.IReadOnlyCollection<>
    System.Collections.Generic.IReadOnlyDictionary<, >
    • Improve this Doc
    • View Source
    Back to top Copyright © 2020 Licensed to the Apache Software Foundation (ASF)