Q3Dict Class ReferenceThe Q3Dict class is a template class that provides a dictionary based on QString keys. Далее... #include <Q3Dict> Данный класс является частью библиотеки поддержки Qt 3. Он предоставлен для поддержки ранее написанного кода. Мы настоятельно не рекомендуем использовать этот класс в новом коде. Для получения дополнительной информации смотрите Портирование на Qt 4. Унаследован от: Q3PtrCollection. Открытые функции
Переопределённые открытые функции
Защищенные функции
Подробное описаниеThe Q3Dict class is a template class that provides a dictionary based on QString keys. Q3Dict is implemented as a template class. Define a template instance Q3Dict<X> to create a dictionary that operates on pointers to X (X *). A dictionary is a collection of key-value pairs. The key is a QString used for insertion, removal and lookup. The value is a pointer. Dictionaries provide very fast insertion and lookup. If you want to use non-Unicode, plain 8-bit char* keys, use the Q3AsciiDict template. A Q3Dict has the same performance as a Q3AsciiDict. If you want to have a dictionary that maps QStrings to QStrings use QMap. The size() of the dictionary is very important. In order to get good performance, you should use a suitably large prime number. Suitable means equal to or larger than the maximum expected number of dictionary items. Size is set in the constructor but may be changed with resize(). Items are inserted with insert(); 0 pointers cannot be inserted. Items are removed with remove(). All the items in a dictionary can be removed with clear(). The number of items in the dictionary is returned by count(). If the dictionary contains no items isEmpty() returns TRUE. You can change an item's value with replace(). Items are looked up with operator[](), or with find() which return a pointer to the value or 0 if the given key does not exist. You can take an item out of the dictionary with take(). Calling setAutoDelete(TRUE) for a dictionary tells it to delete items that are removed. The default behavior is not to delete items when they are removed. When an item is inserted, the key is converted (hashed) to an integer index into an internal hash array. This makes lookup very fast. Items with equal keys are allowed. When inserting two items with the same key, only the last inserted item will be accessible (last in, first out) until it is removed. The Q3DictIterator class can traverse the dictionary, but only in an arbitrary order. Multiple iterators may independently traverse the same dictionary. When inserting an item into a dictionary, only the pointer is copied, not the item itself, i.e. a shallow copy is made. It is possible to make the dictionary copy all of the item's data (a deep copy) when an item is inserted. insert() calls the virtual function Q3PtrCollection::newItem() for the item to be inserted. Inherit a dictionary and reimplement newItem() if you want deep copies. When removing a dictionary item, the virtual function Q3PtrCollection::deleteItem() is called. Q3Dict's default implementation is to delete the item if auto-deletion is enabled. See also Q3DictIterator, Q3AsciiDict, Q3IntDict, and Q3PtrDict. Описание функций-членовQ3Dict::Q3Dict ( int size = 17, bool caseSensitive = true )Constructs a dictionary optimized for less than size entries. We recommend setting size to a suitably large prime number (e.g. a prime that's slightly larger than the expected number of entries). This makes the hash distribution better which will lead to faster lookup. If caseSensitive is TRUE (the default), keys which differ only by case are considered different. Q3Dict::Q3Dict ( const Q3Dict<type> & dict )Constructs a copy of dict. Each item in dict is inserted into this dictionary. Only the pointers are copied (shallow copy). Q3Dict::~Q3Dict ()Removes all items from the dictionary and destroys it. If setAutoDelete() is TRUE, each value is deleted. All iterators that access this dictionary will be reset. Смотрите также setAutoDelete(). void Q3Dict::clear () [virtual]Reimplemented from Q3PtrCollection::clear(). Removes all items from the dictionary. The removed items are deleted if auto-deletion is enabled. All dictionary iterators that operate on the dictionary are reset. Смотрите также remove(), take() и setAutoDelete(). uint Q3Dict::count () const [virtual]Reimplemented from Q3PtrCollection::count(). Returns the number of items in the dictionary. Смотрите также isEmpty(). type * Q3Dict::find ( const QString & key ) constReturns the item with key key, or 0 if the key does not exist in the dictionary. If there are two or more items with equal keys, then the most recently inserted item will be found. Equivalent to the [] operator. Смотрите также operator[](). void Q3Dict::insert ( const QString & key, const type * item )Inserts the key key with value item into the dictionary. Multiple items can have the same key, in which case only the last item will be accessible using operator[](). item may not be 0. Смотрите также replace(). bool Q3Dict::isEmpty () constReturns TRUE if the dictionary is empty, i.e. count() == 0; otherwise returns FALSE. Смотрите также count(). QDataStream & Q3Dict::read ( QDataStream & s, Q3PtrCollection::Item & item ) [virtual protected]Reads a dictionary item from the stream s and returns a reference to the stream. The default implementation sets item to 0. Смотрите также write(). bool Q3Dict::remove ( const QString & key )Removes the item with key from the dictionary. Returns TRUE if successful, i.e. if the item is in the dictionary; otherwise returns FALSE. If there are two or more items with equal keys, then the last item that was inserted will be removed. The removed item is deleted if auto-deletion is enabled. All dictionary iterators that refer to the removed item will be set to point to the next item in the dictionary's traversal order. Смотрите также take(), clear() и setAutoDelete(). void Q3Dict::replace ( const QString & key, const type * item )Replaces the value of the key, key with item. If the item does not already exist, it will be inserted. item may not be 0. Equivalent to: Q3Dict<char> dict; ... if ( dict.find( key ) ) dict.remove( key ); dict.insert( key, item ); If there are two or more items with equal keys, then the last item that was inserted will be replaced. Смотрите также insert(). void Q3Dict::resize ( uint newsize )Changes the size of the hash table to newsize. The contents of the dictionary are preserved, but all iterators on the dictionary become invalid. uint Q3Dict::size () constReturns the size of the internal hash array (as specified in the constructor). Смотрите также count(). void Q3Dict::statistics () constDebugging-only function that prints out the dictionary distribution using qDebug(). type * Q3Dict::take ( const QString & key )Takes the item with key out of the dictionary without deleting it (even if auto-deletion is enabled). If there are two or more items with equal keys, then the last item that was inserted will be taken. Returns a pointer to the item taken out, or 0 if the key does not exist in the dictionary. All dictionary iterators that refer to the taken item will be set to point to the next item in the dictionary traversal order. Смотрите также remove(), clear() и setAutoDelete(). QDataStream & Q3Dict::write ( QDataStream & s, Q3PtrCollection::Item item ) const [virtual protected]Writes a dictionary item to the stream s and returns a reference to the stream. Смотрите также read(). Q3Dict<type> & Q3Dict::operator= ( const Q3Dict<type> & dict )Assigns dict to this dictionary and returns a reference to this dictionary. This dictionary is first cleared, then each item in dict is inserted into this dictionary. Only the pointers are copied (shallow copy), unless newItem() has been reimplemented. type * Q3Dict::operator[] ( const QString & key ) constReturns the item with key key, or 0 if the key does not exist in the dictionary. If there are two or more items with equal keys, then the most recently inserted item will be found. Equivalent to the find() function. Смотрите также find(). |
Попытка перевода Qt документации. Если есть желание присоединиться, или если есть замечания или пожелания, то заходите на форум: Перевод Qt документации на русский язык... Люди внесшие вклад в перевод: Команда переводчиков |