Show / Hide Table of Contents

Class LiteDictionary

An implementation of IDictionary that is optimal (in terms of both size and speed) for very small sets of data but still works excellently with large sets of data.

Inheritance
object
LiteDictionary
Implements
IDictionary
ICollection
IEnumerable
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Tangosol.Util
Assembly: Coherence.dll
Syntax
public class LiteDictionary : IDictionary, ICollection, IEnumerable
Remarks

This implementation is not thread-safe.

The LiteDictionary implementation switches at runtime between several different sub-implementations for storing the IDictionary of objects, described here:

  1. "empty dictionary" - a dictionary that contains no data;
  2. "single entry" - a reference directly to a single dictionary entry;
  3. "object[]" - a reference to an array of entries; the item limit for this implementation is determined by the THRESHOLD constant;
  4. "delegation" - for more than THRESHOLD items, a dictionary is created to delegate the dictionary management to; sub-classes can override the default delegation class Hashtable by overriding the factory method InstantiateDictionary().

The LiteDictionary implementation supports the null key value.

Constructors

LiteDictionary()

Constructs a LiteDictionary.

Declaration
public LiteDictionary()

LiteDictionary(IDictionary)

Construct a LiteDictionary with the same mappings as the given dictionary.

Declaration
public LiteDictionary(IDictionary dictionary)
Parameters
Type Name Description
IDictionary dictionary

The dictionary whose mappings are to be placed in this dictionary.

Properties

Count

Gets the number of elements contained in this dictionary.

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

The number of elements contained in this dictionary.

IsEmpty

Gets true if this dictionary contains no key-value mappings.

Declaration
public virtual bool IsEmpty { get; }
Property Value
Type Description
bool

true if this dictionary contains no key-value mappings.

IsFixedSize

Gets a value indicating whether the IDictionary object has a fixed size.

Declaration
public virtual bool IsFixedSize { get; }
Property Value
Type Description
bool

Always false for LiteDictionary.

IsReadOnly

Gets a value indicating whether the IDictionary object is read-only.

Declaration
public virtual bool IsReadOnly { get; }
Property Value
Type Description
bool

Always false for LiteDictionary.

IsSynchronized

Gets a value indicating whether access to the ICollection is synchronized (thread safe).

Declaration
public virtual bool IsSynchronized { get; }
Property Value
Type Description
bool

Always false for LiteDictionary.

this[object]

Returns the value to which this dictionary maps the specified key.

Declaration
public virtual 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 value to which this dictionary maps the specified key, or null if the dictionary contains no mapping for this key.

Keys

Gets a collection containing the keys of the LiteDictionary.

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

A collection containing the keys of the LiteDictionary.

SyncRoot

Gets an object that can be used to synchronize access to the ICollection.

Declaration
public virtual object SyncRoot { get; }
Property Value
Type Description
object

An object that can be used to synchronize access to the ICollection">.

Values

Gets a collection containing the values in the LiteDictionary.

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

A collection containing the values in the LiteDictionary.

Methods

Add(object, object)

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

Declaration
public virtual 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.

CheckShrinkFromOther()

After a mutation operation has reduced the size of an underlying dictionary, check if the delegation model should be replaced with a more size-efficient storage approach, and switch accordingly.

Declaration
protected virtual void CheckShrinkFromOther()

Clear()

Removes all elements from the dictionary.

Declaration
public virtual void Clear()

Contains(object)

Returns true if this dictionary contains a mapping for the specified key.

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

The key to locate in the dictionary.

Returns
Type Description
bool

true if this dictionary contains a mapping for the specified key, false otherwise.

CopyTo(Array, int)

Copies the elements of the ICollection to an Array, starting at a particular index.

Declaration
public virtual 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 ICollection.

int index

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

GetEnumerator()

Returns an IEnumerator object for this LiteDictionary.

Declaration
public virtual IEnumerator GetEnumerator()
Returns
Type Description
IEnumerator

An IEnumerator object for this LiteDictionary.

InstantiateDictionary()

Instantiate an IDictionary object to store entries in once the "lite" threshold has been exceeded.

Declaration
protected virtual IDictionary InstantiateDictionary()
Returns
Type Description
IDictionary

An instance of IDictionary.

InstantiateEntry(object, object)

Instantiate a DictionaryEntry.

Declaration
protected virtual DictionaryEntry InstantiateEntry(object key, object value)
Parameters
Type Name Description
object key

The key.

object value

The value.

Returns
Type Description
DictionaryEntry

An instance of DictionaryEntry.

Remove(object)

Removes the mapping for this key from this dictionary if present.

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

The key of the element to remove.

RemoveEx(object)

Removes the mapping for this key from this map if present.

Declaration
public virtual object RemoveEx(object key)
Parameters
Type Name Description
object key

The key of the element to remove.

Returns
Type Description
object

Previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the dictionary previously associated null with the specified key, if the implementation supports null values.

Remarks

Expensive: updates both the underlying cache and the local cache.

Implements

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