Qt (Generic Containers) Java STL <QtAlgorithms> STL (Generic Algorithms) QList<T>, QLinkedList<T>, QVector<T>, QStack<T>, QQueue<T> QMap<Key,

Similar documents
(STL) STL 1 (deta structure) (algorithm) (deta structure) 2 STL STL (Standard Template Library) 2.1 STL STL ( ) vector<int> x; for(int i = 0; i < 10;

1.3 ( ) ( ) C

cpp2.dvi

Green with White Lines

r07.dvi

ohp07.dvi

放射線専門医認定試験(2009・20回)/HOHS‐01(基礎一次)

tnbp59-17_Web:プO1/ky079888509610003201

joho07-1.ppt

C言語によるアルゴリズムとデータ構造

( ) ( ) 30 ( ) 27 [1] p LIFO(last in first out, ) (push) (pup) 1

ohp03.dvi

cpp1.dvi

r08.dvi

r03.dvi

ohp08.dvi

一般演題(ポスター)

programmingII2019-v01

untitled

ALG2012-A.ppt

日本内科学会雑誌第98巻第3号

untitled

yakuri06023‡Ì…R…s†[

untitled

jigp60-★WEB用★/ky494773452500058730

プログラム



tuat1.dvi


SystemC言語概論


27巻3号/FUJSYU03‐107(プログラム)

第101回 日本美容外科学会誌/nbgkp‐01(大扉)

パーキンソン病治療ガイドライン2002

本文27/A(CD-ROM

tnbp59-20_Web:P1/ky108679509610002943

yacc.dvi

ex01.dvi

O(N) ( ) log 2 N

第2回

cpp4.dvi

1.ppt

exec.dvi

/ SCHEDULE /06/07(Tue) / Basic of Programming /06/09(Thu) / Fundamental structures /06/14(Tue) / Memory Management /06/1

6-1

第5回お試しアカウント付き並列プログラミング講習会

Quartus II ハンドブック Volume 5、セクションIV. マルチプロセッサの調整


Condition DAQ condition condition 2 3 XML key value

RubyKaigi2009 COBOL

新版明解C言語 実践編

SystemC 2.0を用いた簡易CPUバスモデルの設計

program.dvi

日本糖尿病学会誌第58巻第3号

ex01.dvi

£Ã¥×¥í¥°¥é¥ß¥ó¥°ÆþÌç (2018) - Â裶²ó ¨¡ À©¸æ¹½Â¤¡§·«¤êÊÖ¤· ¨¡

Boo Boo 2 Boo 2.NET Framework SDK 2 Subversion 2 2 Java 4 NAnt 5 Boo 5 5 Boo if 11 for 11 range 12 break continue 13 pass

受賞講演要旨2012cs3

Microsoft Word - 第56回日本脂質生化学会プログラムv1.doc

BW BW

日本糖尿病学会誌第58巻第2号

2

memo

RHEA key

アルゴリズムとデータ構造1

2008 IIA (program) pro(before)+gram(write) (artificial language) (programming languege) (programming) (machine language) (assembly language) ( )

とても使いやすい Boost の serialization

文字列操作と正規表現


Microsoft Word - Cプログラミング演習(12)

日本分子第4巻2号_10ポスター発表.indd

Ł\”ƒ-2005

Original : Hello World! (0x0xbfab85e0) Copy : Hello World! (0x0x804a050) fgets mstrcpy malloc mstrcpy (main ) mstrcpy malloc free fgets stream 1 ( \n

Microsoft Word - NonGenList.doc

‚æ4›ñ

コーディング基準.PDF

PowerPoint Presentation

slide5.pptx

新・明解C言語 実践編

untitled

para02-2.dvi

£Ã¥×¥í¥°¥é¥ß¥ó¥°(2018) - Âè11²ó – ½ÉÂꣲ¤Î²òÀ⡤±é½¬£² –


dプログラム_1

10/ / /30 3. ( ) 11/ 6 4. UNIX + C socket 11/13 5. ( ) C 11/20 6. http, CGI Perl 11/27 7. ( ) Perl 12/ 4 8. Windows Winsock 12/11 9. JAV

WinHPC ppt

10-C.._241_266_.Z

日本内科学会雑誌第101巻第12号

第85 回日本感染症学会総会学術集会後抄録(I)

日本内科学会雑誌第97巻第3号

class IntCell { private int value ; int getvalue() {return value; private IntCell next; IntCell next() {return next; IntCell(int value) {this.value =

2 T 1 N n T n α = T 1 nt n (1) α = 1 100% OpenMP MPI OpenMP OpenMP MPI (Message Passing Interface) MPI MPICH OpenMPI 1 OpenMP MPI MPI (trivial p

1. ( ) SPH 1. 1: 2: 2.

第86回日本感染症学会総会学術集会後抄録(II)

program7app.ppt

第89回日本感染症学会学術講演会後抄録(I)

higp-15(プロ1日目)/ky220147284100029951

±é½¬£²¡§£Í£Ð£É½éÊâ

Chapter 20. [ ] ; [ ] = new [ ] ; Color colors [ ] = new Color[ 20 ]; // 20 Button operations [ ] = new Button[ 10 ]; // 10 colors[ 3 ] = new Color( 1

Transcription:

1 5 5.1 Qt (Generic Containers) Java STL <QtAlgorithms> STL (Generic Algorithms) QList<T>, QLinkedList<T>, QVector<T>, QStack<T>, QQueue<T> QMap<Key, T>, QMultiMap<Key, T>. QHash<Key, T>, QMultiHash<Key, T> QSet<T> 5.1.1 QList<T> T QList QList::append() QList::prepend() QList::insert() QList QLinkedList<T> QList QList QList QLinkedList QVector<T> QStack<T> QVector (LIFO) QVector push(), pop(), top() QQueue<T> QList (FIFO) QList enqueue(), dequeue(), head()

2 5 5.1.2 QMap<Key, T> Key T ( ) 1 1 QMap QHash QMultiMap<Key, T> QMap 1 QHash<Key, T> QMap API QHash QMultiHash<Key, T> QHash QSet<T> 5.1.3 QByteArray QString QByteArray char * QString Unicode QString 16 QChar QChar Unicode 4.0 5.2 QList QMap Qt 5.2.1 QList void QList::append ( const T & value ) QList & QList::operator<< ( const T & value ) QList & QList::operator<< ( const QList & other ) append() operator<< operator<< T QList::value ( int i ) const T QList::value ( int i, const T & defaultvalue ) const i i i at() T & QList::operator[] ( int i )

5.2 3 const T & QList::operator[] ( int i ) const const T & QList::at ( int i ) const i i (0 <= i < size()) int QList::size () const bool QList::isEmpty () const void QList::clear () size() 1 isempty() clear() QDataStream & operator<< ( QDataStream & out, const QList<T> & list ) QDataStream & operator>> ( QDataStream & in, QList<T> & list 5.2.2 QMap iterator QMap::insert ( const Key & key, const T & value ) iterator QMap::insertMulti ( const Key & key, const T & value ) key value insert() *1 insertmulti() iterator STL const T QMap::value ( const Key & key ) const const T QMap::value ( const Key & key, const T & defaultvalue ) const T & QMap::operator[] ( const Key & key ) const T QMap::operator[] ( const Key & key ) const values() int QMap::size () const bool QMap::isEmpty () const void QMap::clear () size() isempty() 1 clear() *1 insertmulti()

4 5 QDataStream & operator<< ( QDataStream & out, const QMap<Key, T> & map ) QDataStream & operator>> ( QDataStream & in, QMap<Key, T> & map ) QList<Key> QMap::keys () const QList<Key> QMap::keys ( const T & value ) const QList<T> QMap::values () const QList<T> QMap::values ( const Key & key ) const keys() QList<Key> values() QList<T> insertmulti() 5.3 Qt 5.3.1 QList<T> O(1) O(n) O(log n) O(log n) QLinkedList<T> O(n) O(1) O(1) O(1) QVector<T> O(1) O(n) O(n) O(log n) 5.1 5.3.2 QMap<Key, T> O(log n) O(log n) O(log n) O(log n) QHash<Key, T> O(1) O(n) O(log n) O(n) QSet<Key> O(1) O(n) O(log n) O(n) 5.2

5.4 Java 5 5.4 Java Qt 4 Java Java Qt STL QList<T>, QQueue<T> QListIterator<T> QMutableListIterator<T> QLinkedList<T> QLinkedListIterator<T> QMutableLinkedListIterator<T> QVector<T>, QStack<T> QVectorIterator<T> QMutableVectorIterator<T> QSet<T> QSetIterator<T> N/A QMap<Key, T>, QMultiMap<Key, T> QMapIterator<Key, T> QMutableMapIterator<Key, T> QHash<Key, T>, QMultiHash<Key, T> QHashIterator<Key, T> QMutableHashIterator<Key, T> 5.3 Java Java next() previous() 5.4.1 QListIterator QList<T>, QLinkedList<T>, QVector<T>, QSet<T> QListIterator const T & QListIterator::next () const T & QListIterator::previous () void QListIterator::toFront () ( ) void QListIterator::toBack ()

6 5 ( ) bool QListIterator::hasNext () const bool QListIterator::hasPrevious () const const T & QListIterator::peekNext () const const T & QListIterator::peekPrevious () const bool QListIterator::findNext ( const T & value ) bool QListIterator::findPrevious ( const T & value ) QListIterator 1 #include <QtCore> 2 3 int main(int argc, char *argv[]) 4 { 5 QList<int> list; 6 list << 1 << 2 << 3; 7 8 QListIterator<int> i(list); 9 i.tofront(); // 10 while (i.hasnext()) { 11 qdebug() << i.next(); 12 }

5.4 Java 7 13 14 i.toback(); 15 while (i.hasprevious()) { 16 qdebug() << i.previous(); 17 } 18 19 return 0; 20 } 5,6 int 8 9 12 14 17 STL 5.4.2 QMutableListIterator QListIterator QMutableListIterator QMutableListIterator QListIterator void QMutableListIterator::remove () void QMutableListIterator::setValue ( const T & value ) const 100 remove(). 1 QMutableListIterator<int> i(list); 2 3 while(i.hasnext()){ 4 if(qabs<int>(i.next()) >= 100){ 5 i.remove(); 6 } 7 } -99 99 1 while(i.hasnext()){ 2 i.setvalue(qbound<int>(-99, i.next(), 99)); 3 }

8 5 5.4.3 QMapIterator QMapIterator QListIterator next(), previous(), tofront(), toback(), hasnext(), hasprevious(), peeknext(), peekprevious(), findnext(), findprevious() next(), previous(), peeknext(), peekprevious() key() value() QMap<T> QHash<T> QMapIterator QMap 1 #include <QtCore> 2 3 int main(int argc, char *argv[]) 4 { 5 QMap<QString, QString> map; 6 map.insert("japan", QString::fromLocal8Bit(" ")); 7 map.insert("norway", QString::fromLocal8Bit(" ")); 8 9 QMapIterator<QString, QString> i(map); 10 while (i.hasnext()) { 11 qdebug() << i.peeknext().key() << i.peeknext().value(); 12 i.next(); 13 } 14 15 return 0; 16 } 10 13 while(i.hasnext()){ QMap<QString, QString>::const_iterator ci = i.next(); qdebug() << ci.key() << ci.value(); } while(i.hasnext()){ qdebug() << i.peeknext().key() << i.next().value(); // } C++ peeknext() next()

5.5 STL 9 5.4.4 QMutableMapIterator QMutableListIterator QListIterator QMutableMapIterator QMapIterator remove(), setvalue() 1 #include <QtCore> 2 3 int main(int argc, char *argv[]) 4 { 5 QMap<QString, QString> map; 6 map.insert("japan", "Tokyo"); 7 map.insert("norway", "Oslo"); 8 9 QMutableMapIterator<QString, QString> i(map); 10 while (i.hasnext()) { 11 i.setvalue(i.next().value().toupper()); 12 qdebug() << i.peekprevious().value(); 13 } 14 15 return 0; 16 } 5.5 STL Qt Java STL STL Java Qt STL STL

10 5 QList<T>, QQueue<T> QList<T>::const_iterator QList<T>::iterator QLinkedList<T> QLinkedList<T>::const_iterator QLinkedList<T>::iterator QVector<T>, QStack<T> QVector<T>::const_iterator QVector<T>::iterator QSet<T> QSet<T>::const_iterator N/A QMap<Key, T>, QMultiMap<Key, T> QMap<Key, T>::const_iterator QMap<Key, T>::iterator QHash<Key, T>, QMultiHash<Key, T> QHash<Key, T>::const_iterator QHash<Key, T>::iterator 5.4 STL Java STL begin() end() *2 end() STL ++ * QList::const_iterator 1 #include <QtCore> 2 3 int main(int argc, char *argv[]) 4 { 5 QList<int> list; 6 list << 1 << 2 << 3; 7 8 QList<int>::const_iterator i; 9 i = list.begin(); 10 while (i!= list.end()) { 11 qdebug() << *i++; 12 } 13 14 i = list.end(); 15 while (i!= list.begin()) { 16 qdebug() << *--i; 17 } *2 past-the-end [begin, end) begin end

5.6 foreach 11 18 19 return 0; 20 } 5.6 foreach foreach Qt C++ Qt C++ foreach foreach (variable, container) statement; foreach QList<int> 1 #include <QtCore> 2 3 int main(int argc, char *argv[]) 4 { 5 QList<int> list; 6 list << 300 << 400 << 250 << 600; 7 8 int sum = 0; 9 foreach (int n, list) { 10 sum += n; 11 } 12 qdebug("sum: %d", sum); 13 14 return 0; 15 } keys() foreach 1 #include <QtCore> 2 3 int main(int argc, char *argv[]) 4 { 5 QMap<QString, QString> map; 6 map.insert("japan", QString::fromLocal8Bit(" ")); 7 map.insert("norway", QString::fromLocal8Bit(" ")); 8 9 foreach (QString s, map.keys()) {

12 5 10 qdebug() << s << map.value(s); 11 } 12 13 return 0; 14 } 5.7 Qt <QtAlgorithms> Qt STL <algorithm> <QtAlgorithms> STL <algorithm> STL 5.7.1 STL STL 5 STL 5 2 ==!= * ++ Qt * ++ Qt const Qt const -- Qt const

5.7 13 i += n i -= n i + n n + i i - n i - j i[n] i < j i n i n i n i n i j *(i + n) j i QList, QLinkedList, QVector const 5.7.2 <QtAlgorithm> InputIterator OutputIterator ForwardIterator BiIterator RandomAccessIterator InputIterator qfind ( InputIterator begin, InputIterator end, const T & value ) [begin, end) value value end RandomAccessIterator qbinaryfind ( RandomAccessIterator begin, RandomAccessIterator end, const T & value ) RandomAccessIterator qlowerbound ( RandomAccessIterator begin, RandomAccessIterator end, const T & value ) RandomAccessIterator qupperbound ( RandomAccessIterator begin, RandomAccessIterator end, const T & value ) [begin, end) value value end [begin, end) qbinaryfind() qlowerbound() qupperbound() value void qsort ( BiIterator begin, BiIterator end ) void qsort ( BiIterator begin, BiIterator end, LessThan lessthan )

14 5 void qsort ( Container & container ) void qstablesort ( BiIterator begin, BiIterator end ) void qstablesort ( BiIterator begin, BiIterator end, LessThan lessthan ) void qstablesort ( Container & container ) qsort() [begin, end) lessthan operator<() container qsort(container.begin(), container.end()) qstablesort() qsort() 1 class caseinsensitivelessthan 2 { 3 public: 4 inline bool operator()(const QString &s1, const QString &s2) const 5 { 6 return s1.tolower() < s2.tolower(); 7 } 8 }; 9... 10 QList<QString> list; 11 list << "alpha" << "BETA" << "gamma" << "DELTA"; 12 qsort(list.begin(), list.end(), caseinsensitivelessthan()); 13... qgreater<t>() qgreater<t>() <QtAlgorithm> 12 qsort(list.begin(), list.end(), qgreater<qstring>()); STL <functional> STL 12 qsort(list.begin(), list.end(), std::greater<qstring>()); OutputIterator qcopy ( InputIterator begin1, InputIterator end1, OutputIterator begin2 ) BiIterator2 qcopybackward ( BiIterator1 begin1, BiIterator1 end1, BiIterator2 end2 ) qcopy() [begin1, end1) [begin2,...) qcopybackward() [begin1, end1) [..., end2) bool qequal ( InputIterator1 begin1, InputIterator1 end1, InputIterator2 begin2 ) [begin1, end1) [begin2,...)

5.8 15 void qcount ( InputIterator begin, InputIterator end, const T & value, Size & n ) [begin, end) value n void qfill ( ForwardIterator begin, ForwardIterator end, const T & value ) [begin, end) value void qdeleteall ( ForwardIterator begin, ForwardIterator end ) void qdeleteall ( const Container & container ) [begin, end) C++ delete container qdeleteall(container.begin(), container.end()) void qswap ( T & var1, T & var2 ) var1 var2 5.8 5.8.1 Qt Qt (Implicit Data Sharing) Qt delete qdeleteall() clear() 1 #include <QtCore> 2 3 int main(void) 4 { 5 QList<QString*> list; 6 list.append(new QString("alpha")); 7 list.append(new QString("beta")); 8 list.append(new QString("gamma")); 9 10 QListIterator<QString*> i(list); 11 while (i.hasnext()) { 12 qdebug() << *i.next();

16 5 13 } 14 15 qdeleteall(list); // 16 list.clear(); // i 17 18 return 0; 19 } 5.8.2 Qt QBitArray QBitmap QBrush QByteArray QCursor QDir QDomImplementation QDomNodeList QDomNode QDomNamedNodeMap QFileInfo QFont QFontInfo QFontMetrics QFontMetricsF QGLColormap QHash QIcon QImage QKeySequence QLinkedList QList QLocale QMap QMovie QMultiHash QMultiMap QPalette QPen QPicture QPixmap QPointArray QQueue QRegExp QRegion QSqlField QSqlQuery QSqlRecord QStack QString QStringList QTextCursor QTextDocumentFragment QTextFormat QUrl QVariant QVector QX11Info 1 0 (shallow copy) (deep copy) 1 QString s1, s2;

5.8 17 2 s1 = "hello, "; // 1 3 s2 = s1; // 2 4 5 s2.append("world."); // 1 CPU : STL 5.8.3 QList<T>, QByteArray, QString ( Qt 4.0.0 ) 1. IP32 *3 QList<T> 20 QByteArray QString 16 2. a 64 8 24, 32, 40, 48, 56, 64 b 64 4096 2 64, 128, 256, 512, 1024, 2048, 4096 c 4096 4096 4096, 8192, 12288, 16384, 20480, 24576, 28672,... QVector<T> memcpy() 1.5 QHash<T> 2 QVector<T>, QHash<Key, T>, QSet<T>, QString, QByteArray 3 capacity() (QHash QSet ) *3 IP32 int 32

18 5 reserve(size) size squeeze() reserve() squeeze()