Show / Hide Table of Contents

Class HashDictionary

Hashtable-based IDictionary implementation that allows null keys.

Inheritance
object
Hashtable
HashDictionary
Implements
IDictionary
ICollection
ICloneable
IDeserializationCallback
ISerializable
IEnumerable
Inherited Members
Hashtable.GetHash(object)
Hashtable.KeyEquals(object, object)
Hashtable.OnDeserialization(object)
Hashtable.Synchronized(Hashtable)
Hashtable.comparer
Hashtable.EqualityComparer
Hashtable.hcp
Hashtable.IsFixedSize
Hashtable.IsReadOnly
Hashtable.IsSynchronized
Hashtable.SyncRoot
object.Equals(object, object)
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
Namespace: Tangosol.Util.Collections
Assembly: Coherence.dll
Syntax
[Serializable]
public class HashDictionary : Hashtable, IDictionary, ICollection, ICloneable, IDeserializationCallback, ISerializable, IEnumerable
Remarks

Note that null keys support intentionally breaks the IDictionary contract, which states that an ArgumentNullException should be raised if the key is null.

However, this is necessary in order to match the behavior in Java and C++, where some Map implementations support null keys.

Note: This implementation is not thread safe. If you need it to be, you should wrap it with the SynchronizedDictionary.

Constructors

HashDictionary()

Initializes a new instance of the HashDictionary class using the default initial capacity, load factor, hash code provider, and comparer.

Declaration
public HashDictionary()

HashDictionary(IDictionary)

Initializes a new instance of the HashDictionary class by copying the elements from the specified dictionary to the new HashDictionary object. The new HashDictionary object has an initial capacity equal to the number of elements copied, and uses the default load factor, hash code provider, and comparer.

Declaration
public HashDictionary(IDictionary d)
Parameters
Type Name Description
IDictionary d

The IDictionary object to copy to a new HashDictionary object.

Exceptions
Type Condition
ArgumentNullException

d is null.

HashDictionary(IDictionary, IEqualityComparer)

Initializes a new instance of the HashDictionary class by copying the elements from the specified dictionary to the new HashDictionary object. The new HashDictionary object has an initial capacity equal to the number of elements copied, and uses the default load factor and the specified IEqualityComparer object.

Declaration
public HashDictionary(IDictionary d, IEqualityComparer equalityComparer)
Parameters
Type Name Description
IDictionary d

The IDictionary object to copy to a new HashDictionary object.

IEqualityComparer equalityComparer

The IEqualityComparer object that defines the hash code provider and the comparer to use with the HashDictionary. -or- null to use the default hash code provider and the default comparer. The default hash code provider is each key's implementation of GetHashCode() and the default comparer is each key's implementation of Equals(object).

Exceptions
Type Condition
ArgumentNullException

d is null.

HashDictionary(IDictionary, float)

Initializes a new instance of the HashDictionary class by copying the elements from the specified dictionary to the new HashDictionary object. The new HashDictionary object has an initial capacity equal to the number of elements copied, and uses the specified load factor, and the default hash code provider and comparer.

Declaration
public HashDictionary(IDictionary d, float loadFactor)
Parameters
Type Name Description
IDictionary d

The IDictionary object to copy to a new HashDictionary object.

float loadFactor

A number in the range from 0.1 through 1.0 that is multiplied by the default value which provides the best performance. The result is the maximum ratio of elements to buckets.

Exceptions
Type Condition
ArgumentNullException

d is null.

ArgumentOutOfRangeException

loadFactor is less than 0.1.-or- loadFactor is greater than 1.0.

HashDictionary(IDictionary, float, IEqualityComparer)

Initializes a new instance of the HashDictionary class by copying the elements from the specified dictionary to the new HashDictionary object. The new HashDictionary object has an initial capacity equal to the number of elements copied, and uses the specified load factor and IEqualityComparer object.

Declaration
public HashDictionary(IDictionary d, float loadFactor, IEqualityComparer equalityComparer)
Parameters
Type Name Description
IDictionary d

The IDictionary object to copy to a new HashDictionary object.

float loadFactor

A number in the range from 0.1 through 1.0 that is multiplied by the default value which provides the best performance. The result is the maximum ratio of elements to buckets.

IEqualityComparer equalityComparer

The IEqualityComparer object that defines the hash code provider and the comparer to use with the HashDictionary. -or- null to use the default hash code provider and the default comparer. The default hash code provider is each key's implementation of GetHashCode() and the default comparer is each key's implementation of Equals(object).

Exceptions
Type Condition
ArgumentNullException

d is null.

ArgumentOutOfRangeException

loadFactor is less than 0.1.-or- loadFactor is greater than 1.0.

HashDictionary(IEqualityComparer)

Initializes a new instance of the HashDictionary class using the default initial capacity and load factor, and the specified IEqualityComparer object.

Declaration
public HashDictionary(IEqualityComparer equalityComparer)
Parameters
Type Name Description
IEqualityComparer equalityComparer

The IEqualityComparer object that defines the hash code provider and the comparer to use with the HashDictionary. -or- null to use the default hash code provider and the default comparer. The default hash code provider is each key's implementation of GetHashCode() and the default comparer is each key's implementation of Equals(object).

HashDictionary(int)

Initializes a new instance of the HashDictionary class using the specified initial capacity, and the default load factor, hash code provider, and comparer.

Declaration
public HashDictionary(int capacity)
Parameters
Type Name Description
int capacity

The approximate number of elements the HashDictionary object can initially contain.

Exceptions
Type Condition
ArgumentOutOfRangeException

capacity is less than zero.

HashDictionary(int, IEqualityComparer)

Initializes a new instance of the HashDictionary class using the specified initial capacity and IEqualityComparer, and the default load factor.

Declaration
public HashDictionary(int capacity, IEqualityComparer equalityComparer)
Parameters
Type Name Description
int capacity

The approximate number of elements the HashDictionary object can initially contain.

IEqualityComparer equalityComparer

The IEqualityComparer object that defines the hash code provider and the comparer to use with the HashDictionary. -or- null to use the default hash code provider and the default comparer. The default hash code provider is each key's implementation of GetHashCode() and the default comparer is each key's implementation of Equals(object).

Exceptions
Type Condition
ArgumentOutOfRangeException

capacity is less than zero.

HashDictionary(int, float)

Initializes a new instance of the HashDictionary class using the specified initial capacity and load factor, and the default hash code provider and comparer.

Declaration
public HashDictionary(int capacity, float loadFactor)
Parameters
Type Name Description
int capacity

The approximate number of elements the HashDictionary object can initially contain.

float loadFactor

A number in the range from 0.1 through 1.0 that is multiplied by the default value which provides the best performance. The result is the maximum ratio of elements to buckets.

Exceptions
Type Condition
ArgumentOutOfRangeException

capacity is less than zero.-or- loadFactor is less than 0.1.-or- loadFactor is greater than 1.0.

ArgumentException

capacity is causing an overflow.

HashDictionary(int, float, IEqualityComparer)

Initializes a new instance of the HashDictionary class using the specified initial capacity, load factor, and IEqualityComparer object.

Declaration
public HashDictionary(int capacity, float loadFactor, IEqualityComparer equalityComparer)
Parameters
Type Name Description
int capacity

The approximate number of elements the HashDictionary object can initially contain.

float loadFactor

A number in the range from 0.1 through 1.0 that is multiplied by the default value which provides the best performance. The result is the maximum ratio of elements to buckets.

IEqualityComparer equalityComparer

The IEqualityComparer object that defines the hash code provider and the comparer to use with the HashDictionary. -or- null to use the default hash code provider and the default comparer. The default hash code provider is each key's implementation of GetHashCode() and the default comparer is each key's implementation of Equals(object).

Exceptions
Type Condition
ArgumentOutOfRangeException

capacity is less than zero. -or- loadFactor is less than 0.1.-or- loadFactor is greater than 1.0.

HashDictionary(SerializationInfo, StreamingContext)

Initializes a new instance of the HashDictionary class that is serializable using the specified SerializationInfo and StreamingContext objects.

Declaration
protected HashDictionary(SerializationInfo info, StreamingContext context)
Parameters
Type Name Description
SerializationInfo info

A SerializationInfo object containing the information required to serialize the HashDictionary object.

StreamingContext context

A StreamingContext object containing the source and destination of the serialized stream associated with the HashDictionary.

Exceptions
Type Condition
ArgumentNullException

info is null.

Properties

Count

Gets the number of elements contained in the ICollection.

Declaration
public override int Count { get; }
Property Value
Type Description
int

The number of elements contained in the ICollection.

Overrides
Hashtable.Count

IsNullValueSet

Returns true is the value for the null key is set, false otherwise.

Declaration
protected bool IsNullValueSet { get; }
Property Value
Type Description
bool

true is the value for the null key is set, false otherwise.

this[object]

Gets or sets the element with the specified key.

Declaration
public override object this[object key] { get; set; }
Parameters
Type Name Description
object key

The key of the element to get or set.

Property Value
Type Description
object

The element with the specified key.

Overrides
Hashtable.this[object]
Exceptions
Type Condition
NotSupportedException

The property is set and the dictionary is read-only. -or- The property is set, key does not exist in the collection, and the dictionary has a fixed size.

Keys

Gets an ICollection object containing the keys of this dictionary.

Declaration
public override ICollection Keys { get; }
Property Value
Type Description
ICollection

An ICollection object containing the keys of this dictionary object.

Overrides
Hashtable.Keys

Values

Gets an ICollection object containing the values in this dictionary.

Declaration
public override ICollection Values { get; }
Property Value
Type Description
ICollection

An ICollection object containing the values in this dictionary object.

Overrides
Hashtable.Values

Methods

Add(object, object)

Adds an element with the provided key and value to the IDictionary object.

Declaration
public override void Add(object key, object value)
Parameters
Type Name Description
object key

The object to use as the key of the element to add.

object value

The object to use as the value of the element to add.

Overrides
Hashtable.Add(object, object)
Exceptions
Type Condition
ArgumentException

An element with the same key already exists in the IDictionary object.

NotSupportedException

The IDictionary is read-only. -or- The IDictionary has a fixed size.

AssertIsVariableSize()

Throw an exception if this dictionary is fixed size.

Declaration
protected void AssertIsVariableSize()

AssertIsWriteable()

Throw an exception if this dictionary is read-only.

Declaration
protected void AssertIsWriteable()

Clear()

Removes all elements from the IDictionary object.

Declaration
public override void Clear()
Overrides
Hashtable.Clear()
Exceptions
Type Condition
NotSupportedException

The IDictionary object is read-only.

Clone()

Creates a new object that is a copy of the current instance.

Declaration
public override object Clone()
Returns
Type Description
object

A new object that is a copy of this instance.

Overrides
Hashtable.Clone()

Contains(object)

Determines whether this dictionary contains an entry with the specified key.

Declaration
public override bool Contains(object key)
Parameters
Type Name Description
object key

The key to locate in this dictionary.

Returns
Type Description
bool

true if the dictionary contains an element with the key; otherwise, false.

Overrides
Hashtable.Contains(object)

ContainsKey(object)

Determines whether the HashDictionary contains a specific key.

Declaration
public override bool ContainsKey(object key)
Parameters
Type Name Description
object key

The key to locate in the HashDictionary.

Returns
Type Description
bool

true if the HashDictionary contains an element with the specified key; otherwise, false.

Overrides
Hashtable.ContainsKey(object)

ContainsValue(object)

Determines whether the HashDictionary contains a specific value.

Declaration
public override bool ContainsValue(object value)
Parameters
Type Name Description
object value

The value to locate in the HashDictionary. The value can be null.

Returns
Type Description
bool

true if the HashDictionary contains an element with the specified value; otherwise, false.

Overrides
Hashtable.ContainsValue(object)

CopyTo(Array, int)

Copies the elements of the collection to an array, starting at a particular array index.

Declaration
public override void CopyTo(Array array, int index)
Parameters
Type Name Description
Array array

The one-dimensional array that is the destination of the elements copied from the collection. The array must have zero-based indexing.

int index

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

Overrides
Hashtable.CopyTo(Array, int)
Exceptions
Type Condition
ArgumentNullException

array is null.

ArgumentOutOfRangeException

index is less than zero.

ArgumentException

array is multidimensional.-or- index is equal to or greater than the length of array.-or- The number of elements in the source collection is greater than the available space from index to the end of the destination array.

ArgumentException

The type of the source collection cannot be cast automatically to the type of the destination array.

Equals(IDictionary)

Compares this dictionary with another dictionary for equality.

Declaration
public virtual bool Equals(IDictionary dict)
Parameters
Type Name Description
IDictionary dict

Dictionary to compare this dictionary with.

Returns
Type Description
bool

true if the two dictionaries are equal; false otherwise.

Remarks

This method returns true if this dictionary and the specified dictionary have exactly the same entry set.

Equals(object)

Determines whether the specified object is equal to this object.

Declaration
public override bool Equals(object obj)
Parameters
Type Name Description
object obj

The object to compare with this object.

Returns
Type Description
bool

true if the specified object is equal to this object; otherwise, false.

Overrides
object.Equals(object)

GetEnumerator()

Returns an IDictionaryEnumerator object for this dictionary.

Declaration
public override IDictionaryEnumerator GetEnumerator()
Returns
Type Description
IDictionaryEnumerator

An IDictionaryEnumerator object for this dictionary.

Overrides
Hashtable.GetEnumerator()

GetHashCode()

Returns a hash code for this object.

Declaration
public override int GetHashCode()
Returns
Type Description
int

A hash code for this object.

Overrides
object.GetHashCode()

GetObjectData(SerializationInfo, StreamingContext)

Overrides serialization method to add support for null value serialization.

Declaration
public override void GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
Type Name Description
SerializationInfo info

Serialization info.

StreamingContext context

Serialization context.

Overrides
Hashtable.GetObjectData(SerializationInfo, StreamingContext)

Remove(object)

Removes the element with the specified key from the IDictionary object.

Declaration
public override void Remove(object key)
Parameters
Type Name Description
object key

The key of the element to remove.

Overrides
Hashtable.Remove(object)
Exceptions
Type Condition
NotSupportedException

The dictionary is read-only. -or- The dictionary has a fixed size.

ToString()

Returns string representation of this instance.

Declaration
public override string ToString()
Returns
Type Description
string

String representation of this instance.

Overrides
object.ToString()

Implements

IDictionary
ICollection
ICloneable
IDeserializationCallback
ISerializable
IEnumerable
In this article
Back to top Copyright © 2000, 2024, Oracle and/or its affiliates.