QT的容器

  • QList <T > is implemented using an array, with space preallocated at both ends. It is optimized for index-based random access and, for lists with less than a thousand items, it also gives good performance with operations like prepend() and append() .

  • QStringList is a convenience class that is derived from QList <QString >.

  • QLinkedList <T > is optimized for sequential access with iterators and quick, constant-time inserts anywhere in the list. Sorting and searching are slow. It has several convenience functions for frequently-used operations.

  • QVector <T > stores its data in contiguous memory locations and is optimized for random access by index. Generally, QVector objects are constructed with an initial size. There is no automatic preallocation of memory at either end so insertions, appends, and prepends are expensive.

  • QStack <T > is publicly derived from QVector <T > so the public interface of QVector is available to QStack objects. However, the Last-in-first-out semantics are offered by the push(), pop() , and top() functions.

  • QMap <Key,T > is an ordered associative container that stores (key, value) pairs and is designed for fast lookup of the value associated with a key. It is also designed to support reasonably fast insertions and removals. It keeps its keys in sorted order, for fast searching and subranging, by means of a skip-list dictionary which is probabilistically balanced and uses memory very efficiently. The Key type must have an operator<() and operator==() .

  • QHash <Key,T > is also an associative container that uses a hash table to facilitate key lookups. It provides very fast lookups (exact key match) and insertions, but slow searching, and no sorting. The Key type must have an operator==() .

  • QMultiMap <Key,T > is a subclass of QMap and QMultiHash <Key,T > is a subclass of QHash . These two classes allow multiple values to be associated with a single key.

  • QCache <Key,T > is also an associative container but it provides fastest access to recently used items and automatic removal of infrequently used items based on cost functions.

  • QSet <T > stores values of type T using a QHash with keys in T and a dummy value associated with each key. This arrangement optimizes lookups and insertions. QSet has functionss for the usual set operations (e.g., union, intersection, set difference, etc.). The default constructor creates an empty set.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章