Library | File

Class xbooldictionary

# include <stdcols.h>

class xbooldictionary
 : public xobject
{
    xdeclare(xbooldictionary)
    ...
};



Description

Dictionary of booleans.

A dictionary cannot contain duplicate keys, each key can map to at most one value. Dictionary provides methods for accessing a value by its key, for inserting and removing values as well as for iterating through the dictionary elements.



Method Summary

voidclearall ()
 
static xbooldictionary *create ()
Creates a new empty dictionary.
static xbooldictionary *createCapacity (xint count)
Creates a new empty dictionary with a specified initial capacity. Capacity is the number of elements, that can be added to the dictionary without having to reallocate its internal buffers.
xboolfind (xrstring key, xbool *value)
Finds an element with the specified key in the dictionary. If an element is found, returns xtrue and sets the value pointer to point to the found value, otherwise returns xfalse. If the value pointer is 0, this method only verifies if an element with the specified key exists in the dictionary without returning its value.
xboolgetbyindex (xint idx, xbool *value)
Gets the value of an element with the specified index from a dictionary. If an element is found, returns yxtrue and sets the value pointer to point to the found value, otherwise returns xfalse. If the value pointer is 0, this method only verifies if an element with the specified index exists in the dictionary without returning its value. Use this method together with methods getmapsize and getkeybyindex to iterate through the dictionary.
xboolgetkeybyindex (xint idx, xstring *key)
Gets the key of an element with the specified index from a dictionary. If an element is found, returns xtrue and sets the key pointer to point to the found string value, otherwise returns xfalse. If the key pointer is 0, this method only verifies if an element with the specified index exists in the dictionary without returning its key. Use this method together with methods getmapsize and getbyindex to iterate through the dictionary.
xintgetmapsize ()
Returns the dictionary size. This size can be greater than the current number of elements in the dictionary, in fact this is a size of the dictionary hashtable.
voidremove (xrstring key)
Removes an element with the specified key from a dictionary.
voidremovebyindex (xint idx)
Removes an element with the specified index from a dictionary. If an element with this index does not exist in the dictionary, throws exception cipXInvalidDictIndex.
voidset (xrstring key, xbool value)
Assigns a new value to the dictionary element with the specified key, if such an element exists, otherwise adds a new element with the given key and value to the dictionary.
voidsetbyindex (xint idx, xbool value)
Changes the value of a dictionary element with the specified index to the specified value. If an element with the specified index does not exist in the dictionary, throws exception cipXInvalidDictIndex.



Method Detail

xintgetmapsize ()

Returns the dictionary size. This size can be greater than the current number of elements in the dictionary, in fact this is a size of the dictionary hashtable.
Returns:
Size of the dictionary.



xboolfind (xrstring key, xbool *value)

Finds an element with the specified key in the dictionary. If an element is found, returns xtrue and sets the value pointer to point to the found value, otherwise returns xfalse. If the value pointer is 0, this method only verifies if an element with the specified key exists in the dictionary without returning its value.
Parameters:
key
Key to be found.
value
Pointer to the return value.
Returns:
Specifies if the value is found.



voidset (xrstring key, xbool value)

Assigns a new value to the dictionary element with the specified key, if such an element exists, otherwise adds a new element with the given key and value to the dictionary.
Parameters:
key
Key of an element.
value
New value of an element.
Returns:



voidsetbyindex (xint idx, xbool value)

Changes the value of a dictionary element with the specified index to the specified value. If an element with the specified index does not exist in the dictionary, throws exception cipXInvalidDictIndex.
Parameters:
idx
Element index.
value
New element value.
Returns:



voidremove (xrstring key)

Removes an element with the specified key from a dictionary.
Parameters:
key
Key of an element to remove.
Returns:



voidremovebyindex (xint idx)

Removes an element with the specified index from a dictionary. If an element with this index does not exist in the dictionary, throws exception cipXInvalidDictIndex.
Parameters:
idx
Index of an element to remove.
Returns:



xboolgetbyindex (xint idx, xbool *value)

Gets the value of an element with the specified index from a dictionary. If an element is found, returns yxtrue and sets the value pointer to point to the found value, otherwise returns xfalse. If the value pointer is 0, this method only verifies if an element with the specified index exists in the dictionary without returning its value. Use this method together with methods getmapsize and getkeybyindex to iterate through the dictionary.
Parameters:
idx
Element index.
value
Pointer to the return value.
Returns:
Specifies if the index is found.



xboolgetkeybyindex (xint idx, xstring *key)

Gets the key of an element with the specified index from a dictionary. If an element is found, returns xtrue and sets the key pointer to point to the found string value, otherwise returns xfalse. If the key pointer is 0, this method only verifies if an element with the specified index exists in the dictionary without returning its key. Use this method together with methods getmapsize and getbyindex to iterate through the dictionary.
Parameters:
idx
Element index.
key
Pointer to the returned key.
Returns:
Specifies if the index is found.



voidclearall ()

 
Returns:



static xbooldictionary *create ()

Creates a new empty dictionary.
Returns:
Created dictionary.



static xbooldictionary *createCapacity (xint count)

Creates a new empty dictionary with a specified initial capacity. Capacity is the number of elements, that can be added to the dictionary without having to reallocate its internal buffers.
Parameters:
count
Returns:
Created dictionary.