Dictionary template

From Solid Graphics Wiki

Jump to: navigation, search
Dictionary template
Namespace: SKL
Base type: (None)
Include: SklDictionary.h
Lib (Release): SKL.lib
Lib (Debug): SKL_D.lib


The Dictionary template is a C++ template for making sorted key-to-value maps. The template is defined as:

template < class _Key, class _Value, bool useConstructorAndDestructor = true >
class Dictionary;

The _Key is type of the dictionary keys, the _Value is type of the dictionary values . The useConstructorAndDestructor template argument specifies whether the methods of the template should use constructor and destructors while adding, copying, and deleting the T objects into/in/from the list. If the useConstructorAndDestructor is specified as false then the template uses memcpy functions to copy/clone objects and does not call a destructor when an object is removed from the list.

Contrary to similar dictionary templates used in other libraries such as STL, the SolidKit's dictionary does not automatically sort key-value pairs as they are added to dictionary. Explicit call to the dictionary's Sort method is needed to sort the dictionary items. This is for performance reasons as sorting the dictionary once after all it's items are added to it is usually much faster than sorting it during inserting of each item.


Constructors

The Dictionary template provides only basic constructors - a constructor with no parameters and a copy constructor.

Fields

The template provides no public fields.

Methods

Method name Description
Clear Removes all key-value pairs from the dictionary and sets the dictionary capacity to zero.
Append Appends key-value pair to the end of the dictionary.
Insert Inserts key-value pair to specified dictionary position.
InsertOrReplace Inserts key-value pair at specified position, or if the key already exists there then it replaces it's value with the new value.
Erase Erases key-value pair at specified dictionary position.
EraseItem To use this method the dictionary must be sorted in ascending order. Erases key-value pair with specieid key.
SetCount Sets count of the dictionary items to specified value. If the value is less than current count then the item past the specified count are erased. If the value is more than current count then new dictionary items are initialized by key and value type constructors. If the dictionary is defined with useConstructorAndDestructor argumend as false then the new dictionary items are left uninitialized.
Sort Sorts items in the dictionary in ascending order using items keys to determine the sort order.
Find To use this method the dictionary must be sorted in ascending order. Finds and returns index of dictionary item with the specified key using binary-search algorithm. If there are more key-value pairs using the same key then the method does not necessarily returns first's such key-value pair index. If the key is not present in the dictionary then the method returns -1.
GetItemValue Returns value of dictionary item with specified index.
Reserve Sets the dictionary capacity to specified value. Setting the capacity first ensures that the internal data buffer for the dictionary items won't be reallocated if number of items added to the dictionary does not exceed the capacity value.
Count Returns current number of items in the dictionary.
Capacity Returns current dictionary's capacity. The capacity of the dictionary is the size of its internal buffer allocated for holding the key-value pair items.

Operators

= Allows to assign one dictionary to another.
[ ] Allows to access dictionary's key-value pairs by the pair index.

See Also


   


SolidKit Library Documentation

Personal tools