Show / Hide Table of Contents

    Class HashMap<TKey, TValue>

    A C# emulation of the Java Hashmap

    A is a close equivalent to the Java Hashmap. One difference java implementation of the class is that the Hashmap supports both null keys and values, where the C# Dictionary only supports null values not keys. Also, V Get(TKey) method in Java returns null if the key doesn't exist, instead of throwing an exception. In .NET, using TryGetValue(TKey, out TValue) will provide similar behavior as V Get(TKey) This class is slower than using a , because of extra checks that have to be done on each access, to check for null.

    Consider also implementing IDictionary, IEnumerable, and ICollection like does, so HashMap can be used in substituted in place for the same interfaces it implements.

    Inheritance
    System.Object
    HashMap<TKey, TValue>
    IdentityHashMap<TKey, TValue>
    LinkedHashMap<TKey, TValue>
    Namespace: Lucene.Net.Support
    Assembly: Lucene.Net.dll
    Syntax
    public class HashMap<TKey, TValue> : IDictionary<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. Null keys are not supported.
    • 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

    HashMap()

    Declaration
    public HashMap()
    | Improve this Doc View Source

    HashMap(IEnumerable<KeyValuePair<TKey, TValue>>)

    Declaration
    public HashMap(IEnumerable<KeyValuePair<TKey, TValue>> other)
    Parameters
    Type Name Description
    IEnumerable<KeyValuePair<TKey, TValue>> other
    | Improve this Doc View Source

    HashMap(IEqualityComparer<TKey>)

    Declaration
    public HashMap(IEqualityComparer<TKey> comparer)
    Parameters
    Type Name Description
    IEqualityComparer<TKey> comparer
    | Improve this Doc View Source

    HashMap(Int32)

    Declaration
    public HashMap(int initialCapacity)
    Parameters
    Type Name Description
    System.Int32 initialCapacity
    | Improve this Doc View Source

    HashMap(Int32, IEqualityComparer<TKey>)

    Declaration
    public HashMap(int initialCapacity, IEqualityComparer<TKey> comparer)
    Parameters
    Type Name Description
    System.Int32 initialCapacity
    IEqualityComparer<TKey> comparer

    Properties

    | Improve this Doc View Source

    Count

    Declaration
    public virtual int Count { get; }
    Property Value
    Type Description
    System.Int32
    | Improve this Doc View Source

    IsReadOnly

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

    Item[TKey]

    Declaration
    public virtual TValue this[TKey key] { get; set; }
    Parameters
    Type Name Description
    TKey key
    Property Value
    Type Description
    TValue
    | Improve this Doc View Source

    Keys

    Declaration
    public virtual ICollection<TKey> Keys { get; }
    Property Value
    Type Description
    ICollection<TKey>
    | Improve this Doc View Source

    Values

    Declaration
    public virtual ICollection<TValue> Values { get; }
    Property Value
    Type Description
    ICollection<TValue>

    Methods

    | Improve this Doc View Source

    Add(TKey, TValue)

    Declaration
    public virtual void Add(TKey key, TValue value)
    Parameters
    Type Name Description
    TKey key
    TValue value
    | Improve this Doc View Source

    Add(KeyValuePair<TKey, TValue>)

    Declaration
    public virtual void Add(KeyValuePair<TKey, TValue> item)
    Parameters
    Type Name Description
    KeyValuePair<TKey, TValue> item
    | Improve this Doc View Source

    AddIfAbsent(TKey, TValue)

    Declaration
    public TValue AddIfAbsent(TKey key, TValue value)
    Parameters
    Type Name Description
    TKey key
    TValue value
    Returns
    Type Description
    TValue
    | Improve this Doc View Source

    Clear()

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

    Contains(KeyValuePair<TKey, TValue>)

    Declaration
    public virtual bool Contains(KeyValuePair<TKey, TValue> item)
    Parameters
    Type Name Description
    KeyValuePair<TKey, TValue> item
    Returns
    Type Description
    System.Boolean
    | Improve this Doc View Source

    ContainsKey(TKey)

    Declaration
    public virtual bool ContainsKey(TKey key)
    Parameters
    Type Name Description
    TKey key
    Returns
    Type Description
    System.Boolean
    | Improve this Doc View Source

    ContainsValue(TValue)

    Declaration
    public bool ContainsValue(TValue value)
    Parameters
    Type Name Description
    TValue value
    Returns
    Type Description
    System.Boolean
    | Improve this Doc View Source

    CopyTo(KeyValuePair<TKey, TValue>[], Int32)

    Declaration
    public virtual void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
    Parameters
    Type Name Description
    KeyValuePair<TKey, TValue>[] array
    System.Int32 arrayIndex
    | Improve this Doc View Source

    Equals(Object)

    Declaration
    public override bool Equals(object obj)
    Parameters
    Type Name Description
    System.Object obj
    Returns
    Type Description
    System.Boolean
    | Improve this Doc View Source

    GetEnumerator()

    Declaration
    public virtual IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
    Returns
    Type Description
    IEnumerator<KeyValuePair<TKey, TValue>>
    | Improve this Doc View Source

    GetHashCode()

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    System.Int32
    | Improve this Doc View Source

    Remove(TKey)

    Declaration
    public virtual bool Remove(TKey key)
    Parameters
    Type Name Description
    TKey key
    Returns
    Type Description
    System.Boolean
    | Improve this Doc View Source

    Remove(KeyValuePair<TKey, TValue>)

    Declaration
    public virtual bool Remove(KeyValuePair<TKey, TValue> item)
    Parameters
    Type Name Description
    KeyValuePair<TKey, TValue> item
    Returns
    Type Description
    System.Boolean
    | Improve this Doc View Source

    ToString()

    Declaration
    public override string ToString()
    Returns
    Type Description
    System.String
    | Improve this Doc View Source

    TryGetValue(TKey, out TValue)

    Declaration
    public virtual bool TryGetValue(TKey key, out TValue value)
    Parameters
    Type Name Description
    TKey key
    TValue value
    Returns
    Type Description
    System.Boolean
    • Improve this Doc
    • View Source
    Back to top Copyright © 2020 Licensed to the Apache Software Foundation (ASF)