Public Member Functions | Protected Types | Protected Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
QGDict Class Reference

The QGDict class is an internal class for implementing QDict template classes. More...

#include <qgdict.h>

Inheritance diagram for QGDict:
QCollection QAsciiDict< type > QAsciiDict< Entry > QCDict QIntDict< type > QIntDict< char > QIntDict< ClassDef > QIntDict< Definition > QIntDict< MemberDef > QIntDict< MemberGroup > QIntDict< MemberGroupInfo > QIntDict< RefItem > QIntDict< SearchIndexList > QIntDict< T > QIntDict< uint > QIntDict< URL > QIntDict< URLInfo > QPtrDict< type >

Public Member Functions

uint count () const
 
uint size () const
 
QCollection::Item look_string (const QString &key, QCollection::Item, int)
 
QCollection::Item look_ascii (const char *key, QCollection::Item, int)
 
QCollection::Item look_int (long key, QCollection::Item, int)
 
QCollection::Item look_ptr (void *key, QCollection::Item, int)
 
QDataStreamread (QDataStream &)
 
QDataStreamwrite (QDataStream &) const
 
- Public Member Functions inherited from QCollection
bool autoDelete () const
 
void setAutoDelete (bool enable)
 

Protected Types

enum  KeyType { StringKey, AsciiKey, IntKey, PtrKey }
 

Protected Member Functions

 QGDict (uint len, KeyType kt, bool cs, bool ck)
 
 QGDict (const QGDict &)
 
 ~QGDict ()
 
QGDictoperator= (const QGDict &)
 
bool remove_string (const QString &key, QCollection::Item item=0)
 
bool remove_ascii (const char *key, QCollection::Item item=0)
 
bool remove_int (long key, QCollection::Item item=0)
 
bool remove_ptr (void *key, QCollection::Item item=0)
 
QCollection::Item take_string (const QString &key)
 
QCollection::Item take_ascii (const char *key)
 
QCollection::Item take_int (long key)
 
QCollection::Item take_ptr (void *key)
 
void clear ()
 
void resize (uint)
 
int hashKeyString (const QString &)
 
int hashKeyAscii (const char *)
 
void statistics () const
 
virtual QDataStreamread (QDataStream &, QCollection::Item &)
 
virtual QDataStreamwrite (QDataStream &, QCollection::Item) const
 
- Protected Member Functions inherited from QCollection
 QCollection ()
 
 QCollection (const QCollection &)
 
virtual ~QCollection ()
 
virtual Item newItem (Item)
 
virtual void deleteItem (Item)
 

Private Member Functions

void unlink_common (int, QBaseBucket *, QBaseBucket *)
 
QStringBucketunlink_string (const QString &, QCollection::Item item=0)
 
QAsciiBucketunlink_ascii (const char *, QCollection::Item item=0)
 
QIntBucketunlink_int (long, QCollection::Item item=0)
 
QPtrBucketunlink_ptr (void *, QCollection::Item item=0)
 
void init (uint, KeyType, bool, bool)
 

Private Attributes

QBaseBucket ** vec
 
uint vlen
 
uint numItems
 
uint keytype: 2
 
uint cases: 1
 
uint copyk: 1
 
QGDItListiterators
 

Friends

class QGDictIterator
 

Additional Inherited Members

- Public Types inherited from QCollection
typedef void * Item
 
- Protected Attributes inherited from QCollection
bool del_item
 

Detailed Description

The QGDict class is an internal class for implementing QDict template classes.

QGDict is a strictly internal class that acts as a base class for the collection classes QDict and QIntDict.

QGDict has some virtual functions that can be reimplemented to customize the subclasses.

Normally, you do not have to reimplement any of these functions.

Definition at line 104 of file qgdict.h.

Member Enumeration Documentation

enum QGDict::KeyType
protected
Enumerator
StringKey 
AsciiKey 
IntKey 
PtrKey 

Definition at line 119 of file qgdict.h.

Constructor & Destructor Documentation

QGDict::QGDict ( uint  len,
KeyType  kt,
bool  cs,
bool  ck 
)
protected

Definition at line 222 of file qgdict.cpp.

223 {
224  init( len, kt, caseSensitive, copyKeys );
225 }
void init(uint, KeyType, bool, bool)
Definition: qgdict.cpp:228
QGDict::QGDict ( const QGDict dict)
protected

Definition at line 259 of file qgdict.cpp.

260  : QCollection( dict )
261 {
262  init( dict.vlen, (KeyType)dict.keytype, dict.cases, dict.copyk );
263  QGDictIterator it( dict );
264  while ( it.get() ) { // copy from other dict
265  switch ( keytype ) {
266  case StringKey:
267  look_string( it.getKeyString(), it.get(), op_insert );
268  break;
269  case AsciiKey:
270  look_ascii( it.getKeyAscii(), it.get(), op_insert );
271  break;
272  case IntKey:
273  look_int( it.getKeyInt(), it.get(), op_insert );
274  break;
275  case PtrKey:
276  look_ptr( it.getKeyPtr(), it.get(), op_insert );
277  break;
278  }
279  ++it;
280  }
281 }
uint vlen
Definition: qgdict.h:150
QCollection::Item look_int(long key, QCollection::Item, int)
Definition: qgdict.cpp:461
QCollection::Item look_ascii(const char *key, QCollection::Item, int)
Definition: qgdict.cpp:422
void init(uint, KeyType, bool, bool)
Definition: qgdict.cpp:228
QCollection::Item look_ptr(void *key, QCollection::Item, int)
Definition: qgdict.cpp:492
An internal class for implementing QDictIterator and QIntDictIterator.
Definition: qgdict.h:167
uint cases
Definition: qgdict.h:153
uint keytype
Definition: qgdict.h:152
static const int op_insert
Definition: qgdict.cpp:62
uint copyk
Definition: qgdict.h:154
KeyType
Definition: qgdict.h:119
QCollection::Item look_string(const QString &key, QCollection::Item, int)
Definition: qgdict.cpp:382
QGDict::~QGDict ( )
protected

Definition at line 289 of file qgdict.cpp.

290 {
291  clear(); // delete everything
292  delete [] vec;
293  if ( !iterators ) // no iterators for this dict
294  return;
296  while ( i ) { // notify all iterators that
297  i->dict = 0; // this dict is deleted
298  i = iterators->next();
299  }
300  delete iterators;
301 }
type * first()
Definition: qinternallist.h:87
QBaseBucket ** vec
Definition: qgdict.h:149
void clear()
Definition: qgdict.cpp:857
An internal class for implementing QDictIterator and QIntDictIterator.
Definition: qgdict.h:167
type * next()
Definition: qinternallist.h:89
QGDict * dict
Definition: qgdict.h:189
QGDItList * iterators
Definition: qgdict.h:155

Member Function Documentation

void QGDict::clear ( )
protectedvirtual

Removes all objects from the collection. The objects will be deleted if auto-delete has been enabled.

See also
setAutoDelete()

Implements QCollection.

Reimplemented in QAsciiDict< Entry >, QIntDict< type >, QPtrDict< type >, QIntDict< MemberDef >, QIntDict< Definition >, QIntDict< MemberGroup >, QIntDict< T >, QIntDict< MemberGroupInfo >, QIntDict< URL >, QIntDict< URLInfo >, QIntDict< ClassDef >, QIntDict< RefItem >, QIntDict< char >, QIntDict< uint >, and QIntDict< SearchIndexList >.

Definition at line 857 of file qgdict.cpp.

858 {
859  if ( !numItems )
860  return;
861  numItems = 0; // disable remove() function
862  for ( uint j=0; j<vlen; j++ ) { // destroy hash table
863  if ( vec[j] ) {
864  switch ( keytype ) {
865  case StringKey:
866  {
868  while ( n ) {
869  QStringBucket *next = (QStringBucket*)n->getNext();
870  deleteItem( n->getData() );
871  delete n;
872  n = next;
873  }
874  }
875  break;
876  case AsciiKey:
877  {
878  QAsciiBucket *n=(QAsciiBucket *)vec[j];
879  while ( n ) {
880  QAsciiBucket *next = (QAsciiBucket*)n->getNext();
881  if ( copyk )
882  delete [] (char *)n->getKey();
883  deleteItem( n->getData() );
884  delete n;
885  n = next;
886  }
887  }
888  break;
889  case IntKey:
890  {
891  QIntBucket *n=(QIntBucket *)vec[j];
892  while ( n ) {
893  QIntBucket *next = (QIntBucket*)n->getNext();
894  deleteItem( n->getData() );
895  delete n;
896  n = next;
897  }
898  }
899  break;
900  case PtrKey:
901  {
902  QPtrBucket *n=(QPtrBucket *)vec[j];
903  while ( n ) {
904  QPtrBucket *next = (QPtrBucket*)n->getNext();
905  deleteItem( n->getData() );
906  delete n;
907  n = next;
908  }
909  }
910  break;
911  }
912  vec[j] = 0; // detach list of buckets
913  }
914  }
915  if ( iterators && iterators->count() ) { // invalidate all iterators
917  while ( i ) {
918  i->curNode = 0;
919  i = iterators->next();
920  }
921  }
922 }
type * first()
Definition: qinternallist.h:87
QBaseBucket ** vec
Definition: qgdict.h:149
QCollection::Item getData()
Definition: qgdict.h:53
QBaseBucket * curNode
Definition: qgdict.h:192
uint vlen
Definition: qgdict.h:150
QBaseBucket * getNext()
Definition: qgdict.h:55
uint numItems
Definition: qgdict.h:151
std::void_t< T > n
const char * getKey() const
Definition: qgdict.h:78
An internal class for implementing QDictIterator and QIntDictIterator.
Definition: qgdict.h:167
type * next()
Definition: qinternallist.h:89
uint keytype
Definition: qgdict.h:152
uint copyk
Definition: qgdict.h:154
QGDItList * iterators
Definition: qgdict.h:155
virtual void deleteItem(Item)
uint count() const
Definition: qinternallist.h:56
unsigned uint
Definition: qglobal.h:351
uint QGDict::count ( ) const
inlinevirtual
int QGDict::hashKeyAscii ( const char *  key)
protected

Definition at line 123 of file qgdict.cpp.

124 {
125 #if defined(CHECK_NULL)
126  if ( key == 0 )
127  {
128  qWarning( "QGDict::hashAsciiKey: Invalid null key" );
129  return 0;
130  }
131 #endif
132  register const char *k = key;
133  register uint h=0;
134  uint g;
135  if ( cases ) { // case sensitive
136  while ( *k ) {
137  h = (h<<4) + *k++;
138  if ( (g = h & 0xf0000000) )
139  h ^= g >> 24;
140  h &= ~g;
141  }
142  } else { // case insensitive
143  while ( *k ) {
144  h = (h<<4) + tolower(*k);
145  if ( (g = h & 0xf0000000) )
146  h ^= g >> 24;
147  h &= ~g;
148  k++;
149  }
150  }
151  int index = h;
152  if ( index < 0 ) // adjust index to table size
153  index = -index;
154  return index;
155 }
static constexpr double g
Definition: Units.h:144
void qWarning(const char *msg,...)
Definition: qglobal.cpp:409
def key(type, name=None)
Definition: graph.py:13
uint cases
Definition: qgdict.h:153
unsigned uint
Definition: qglobal.h:351
int QGDict::hashKeyString ( const QString key)
protected

Definition at line 86 of file qgdict.cpp.

87 {
88 #if defined(CHECK_NULL)
89  if ( key.isNull() )
90  qWarning( "QGDict::hashStringKey: Invalid null key" );
91 #endif
92  int i;
93  register uint h=0;
94  uint g;
95  int len = key.length();
96  const QChar *p = key.unicode();
97  if ( cases ) { // case sensitive
98  for ( i=0; i<len; i++ ) {
99  h = (h<<4) + p[i].cell();
100  if ( (g = h & 0xf0000000) )
101  h ^= g >> 24;
102  h &= ~g;
103  }
104  } else { // case insensitive
105  for ( i=0; i<len; i++ ) {
106  h = (h<<4) + p[i].lower().cell();
107  if ( (g = h & 0xf0000000) )
108  h ^= g >> 24;
109  h &= ~g;
110  }
111  }
112  int index = h;
113  if ( index < 0 ) // adjust index to table size
114  index = -index;
115  return index;
116 }
const QChar * unicode() const
Definition: qstring.h:508
static constexpr double g
Definition: Units.h:144
void qWarning(const char *msg,...)
Definition: qglobal.cpp:409
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
uchar & cell()
Definition: qstring.h:167
uint length() const
Definition: qstring.h:679
p
Definition: test.py:223
uint cases
Definition: qgdict.h:153
bool isNull() const
Definition: qstring.h:379
unsigned uint
Definition: qglobal.h:351
void QGDict::init ( uint  len,
KeyType  kt,
bool  caseSensitive,
bool  copyKeys 
)
private

Definition at line 228 of file qgdict.cpp.

229 {
230  vec = new QBaseBucket *[vlen = len]; // allocate hash table
231  CHECK_PTR( vec );
232  memset( (char*)vec, 0, vlen*sizeof(QBaseBucket*) );
233  numItems = 0;
234  iterators = 0;
235  // The caseSensitive and copyKey options don't make sense for
236  // all dict types.
237  switch ( (keytype = (uint)kt) ) {
238  case StringKey:
239  cases = caseSensitive;
240  copyk = FALSE;
241  break;
242  case AsciiKey:
243  cases = caseSensitive;
244  copyk = copyKeys;
245  break;
246  default:
247  cases = FALSE;
248  copyk = FALSE;
249  break;
250  }
251 }
QBaseBucket ** vec
Definition: qgdict.h:149
const bool FALSE
Definition: qglobal.h:370
uint vlen
Definition: qgdict.h:150
uint numItems
Definition: qgdict.h:151
uint cases
Definition: qgdict.h:153
uint keytype
Definition: qgdict.h:152
uint copyk
Definition: qgdict.h:154
#define CHECK_PTR(p)
Definition: qglobal.h:601
QGDItList * iterators
Definition: qgdict.h:155
unsigned uint
Definition: qglobal.h:351
QCollection::Item QGDict::look_ascii ( const char *  key,
QCollection::Item  d,
int  op 
)

Definition at line 422 of file qgdict.cpp.

423 {
424  QAsciiBucket *n;
425  int index = hashKeyAscii(key) % vlen;
426  if ( op == op_find ) { // find
427  if ( cases ) {
428  for ( n=(QAsciiBucket*)vec[index]; n;
429  n=(QAsciiBucket*)n->getNext() ) {
430  if ( qstrcmp(n->getKey(),key) == 0 )
431  return n->getData(); // item found
432  }
433  } else {
434  for ( n=(QAsciiBucket*)vec[index]; n;
435  n=(QAsciiBucket*)n->getNext() ) {
436  if ( qstricmp(n->getKey(),key) == 0 )
437  return n->getData(); // item found
438  }
439  }
440  return 0; // not found
441  }
442  if ( op == op_replace ) { // replace
443  if ( vec[index] != 0 ) // maybe something there
444  remove_ascii( key );
445  }
446  // op_insert or op_replace
447  n = new QAsciiBucket(copyk ? qstrdup(key) : key,newItem(d),vec[index]);
448  CHECK_PTR( n );
449 #if defined(CHECK_NULL)
450  if ( n->getData() == 0 )
451  qWarning( "QAsciiDict: Cannot insert null item" );
452 #endif
453  vec[index] = n;
454  numItems++;
455  return n->getData();
456 }
virtual Item newItem(Item)
QBaseBucket ** vec
Definition: qgdict.h:149
QCollection::Item getData()
Definition: qgdict.h:53
void qWarning(const char *msg,...)
Definition: qglobal.cpp:409
uint vlen
Definition: qgdict.h:150
static const int op_replace
Definition: qgdict.cpp:63
QBaseBucket * getNext()
Definition: qgdict.h:55
uint numItems
Definition: qgdict.h:151
int qstricmp(const char *str1, const char *str2)
Definition: qcstring.cpp:567
int hashKeyAscii(const char *)
Definition: qgdict.cpp:123
def key(type, name=None)
Definition: graph.py:13
std::void_t< T > n
const char * getKey() const
Definition: qgdict.h:78
bool remove_ascii(const char *key, QCollection::Item item=0)
Definition: qgdict.cpp:747
uint cases
Definition: qgdict.h:153
uint copyk
Definition: qgdict.h:154
#define CHECK_PTR(p)
Definition: qglobal.h:601
char * qstrdup(const char *str)
Definition: qcstring.cpp:548
Q_EXPORT int qstrcmp(const char *str1, const char *str2)
Definition: qcstring.h:95
static const int op_find
Definition: qgdict.cpp:61
QCollection::Item QGDict::look_int ( long  key,
QCollection::Item  d,
int  op 
)

Definition at line 461 of file qgdict.cpp.

462 {
463  QIntBucket *n;
464  int index = (int)((ulong)key % vlen); // simple hash
465  if ( op == op_find ) { // find
466  for ( n=(QIntBucket*)vec[index]; n;
467  n=(QIntBucket*)n->getNext() ) {
468  if ( n->getKey() == key )
469  return n->getData(); // item found
470  }
471  return 0; // not found
472  }
473  if ( op == op_replace ) { // replace
474  if ( vec[index] != 0 ) // maybe something there
475  remove_int( key );
476  }
477  // op_insert or op_replace
478  n = new QIntBucket(key,newItem(d),vec[index]);
479  CHECK_PTR( n );
480 #if defined(CHECK_NULL)
481  if ( n->getData() == 0 )
482  qWarning( "QIntDict: Cannot insert null item" );
483 #endif
484  vec[index] = n;
485  numItems++;
486  return n->getData();
487 }
virtual Item newItem(Item)
QBaseBucket ** vec
Definition: qgdict.h:149
QCollection::Item getData()
Definition: qgdict.h:53
void qWarning(const char *msg,...)
Definition: qglobal.cpp:409
uint vlen
Definition: qgdict.h:150
static const int op_replace
Definition: qgdict.cpp:63
QBaseBucket * getNext()
Definition: qgdict.h:55
uint numItems
Definition: qgdict.h:151
def key(type, name=None)
Definition: graph.py:13
std::void_t< T > n
unsigned long ulong
Definition: qglobal.h:352
bool remove_int(long key, QCollection::Item item=0)
Definition: qgdict.cpp:762
#define CHECK_PTR(p)
Definition: qglobal.h:601
intptr_t getKey() const
Definition: qgdict.h:88
static const int op_find
Definition: qgdict.cpp:61
QCollection::Item QGDict::look_ptr ( void *  key,
QCollection::Item  d,
int  op 
)

Definition at line 492 of file qgdict.cpp.

493 {
494  QPtrBucket *n;
495  int index = (int)((uintptr_t)key % vlen); // simple hash
496  if ( op == op_find ) { // find
497  for ( n=(QPtrBucket*)vec[index]; n;
498  n=(QPtrBucket*)n->getNext() ) {
499  if ( n->getKey() == key )
500  return n->getData(); // item found
501  }
502  return 0; // not found
503  }
504  if ( op == op_replace ) { // replace
505  if ( vec[index] != 0 ) // maybe something there
506  remove_ptr( key );
507  }
508  // op_insert or op_replace
509  n = new QPtrBucket(key,newItem(d),vec[index]);
510  CHECK_PTR( n );
511 #if defined(CHECK_NULL)
512  if ( n->getData() == 0 )
513  qWarning( "QPtrDict: Cannot insert null item" );
514 #endif
515  vec[index] = n;
516  numItems++;
517  return n->getData();
518 }
virtual Item newItem(Item)
QBaseBucket ** vec
Definition: qgdict.h:149
QCollection::Item getData()
Definition: qgdict.h:53
void qWarning(const char *msg,...)
Definition: qglobal.cpp:409
uint vlen
Definition: qgdict.h:150
static const int op_replace
Definition: qgdict.cpp:63
QBaseBucket * getNext()
Definition: qgdict.h:55
uint numItems
Definition: qgdict.h:151
def key(type, name=None)
Definition: graph.py:13
std::void_t< T > n
bool remove_ptr(void *key, QCollection::Item item=0)
Definition: qgdict.cpp:775
#define CHECK_PTR(p)
Definition: qglobal.h:601
void * getKey() const
Definition: qgdict.h:98
static const int op_find
Definition: qgdict.cpp:61
QCollection::Item QGDict::look_string ( const QString key,
QCollection::Item  d,
int  op 
)

Definition at line 382 of file qgdict.cpp.

383 {
384  QStringBucket *n;
385  int index = hashKeyString(key) % vlen;
386  if ( op == op_find ) { // find
387  if ( cases ) {
388  for ( n=(QStringBucket*)vec[index]; n;
389  n=(QStringBucket*)n->getNext() ) {
390  if ( key == n->getKey() )
391  return n->getData(); // item found
392  }
393  } else {
394  QString k = key.lower();
395  for ( n=(QStringBucket*)vec[index]; n;
396  n=(QStringBucket*)n->getNext() ) {
397  if ( k == n->getKey().lower() )
398  return n->getData(); // item found
399  }
400  }
401  return 0; // not found
402  }
403  if ( op == op_replace ) { // replace
404  if ( vec[index] != 0 ) // maybe something there
405  remove_string( key );
406  }
407  // op_insert or op_replace
408  n = new QStringBucket(key,newItem(d),vec[index]);
409  CHECK_PTR( n );
410 #if defined(CHECK_NULL)
411  if ( n->getData() == 0 )
412  qWarning( "QDict: Cannot insert null item" );
413 #endif
414  vec[index] = n;
415  numItems++;
416  return n->getData();
417 }
int hashKeyString(const QString &)
Definition: qgdict.cpp:86
virtual Item newItem(Item)
QString lower() const
Definition: qstring.cpp:13375
QBaseBucket ** vec
Definition: qgdict.h:149
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
QCollection::Item getData()
Definition: qgdict.h:53
void qWarning(const char *msg,...)
Definition: qglobal.cpp:409
const QString & getKey() const
Definition: qgdict.h:68
uint vlen
Definition: qgdict.h:150
static const int op_replace
Definition: qgdict.cpp:63
QBaseBucket * getNext()
Definition: qgdict.h:55
uint numItems
Definition: qgdict.h:151
bool remove_string(const QString &key, QCollection::Item item=0)
Definition: qgdict.cpp:732
std::void_t< T > n
uint cases
Definition: qgdict.h:153
#define CHECK_PTR(p)
Definition: qglobal.h:601
static const int op_find
Definition: qgdict.cpp:61
QGDict & QGDict::operator= ( const QGDict dict)
protected

Definition at line 309 of file qgdict.cpp.

310 {
311  clear();
312  QGDictIterator it( dict );
313  while ( it.get() ) { // copy from other dict
314  switch ( keytype ) {
315  case StringKey:
316  look_string( it.getKeyString(), it.get(), op_insert );
317  break;
318  case AsciiKey:
319  look_ascii( it.getKeyAscii(), it.get(), op_insert );
320  break;
321  case IntKey:
322  look_int( it.getKeyInt(), it.get(), op_insert );
323  break;
324  case PtrKey:
325  look_ptr( it.getKeyPtr(), it.get(), op_insert );
326  break;
327  }
328  ++it;
329  }
330  return *this;
331 }
QCollection::Item look_int(long key, QCollection::Item, int)
Definition: qgdict.cpp:461
QCollection::Item look_ascii(const char *key, QCollection::Item, int)
Definition: qgdict.cpp:422
QCollection::Item look_ptr(void *key, QCollection::Item, int)
Definition: qgdict.cpp:492
void clear()
Definition: qgdict.cpp:857
An internal class for implementing QDictIterator and QIntDictIterator.
Definition: qgdict.h:167
uint keytype
Definition: qgdict.h:152
static const int op_insert
Definition: qgdict.cpp:62
QCollection::Item look_string(const QString &key, QCollection::Item, int)
Definition: qgdict.cpp:382
QDataStream & QGDict::read ( QDataStream s)

Definition at line 997 of file qgdict.cpp.

998 {
999  uint num;
1000  s >> num; // read number of items
1001  clear(); // clear dict
1002  while ( num-- ) { // read all items
1003  Item d;
1004  switch ( keytype ) {
1005  case StringKey:
1006  {
1007  QString k;
1008  s >> k;
1009  read( s, d );
1010  look_string( k, d, op_insert );
1011  }
1012  break;
1013  case AsciiKey:
1014  {
1015  char *k;
1016  s >> k;
1017  read( s, d );
1018  look_ascii( k, d, op_insert );
1019  if ( copyk )
1020  delete [] k;
1021  }
1022  break;
1023  case IntKey:
1024  {
1025  Q_UINT32 k;
1026  s >> k;
1027  read( s, d );
1028  look_int( k, d, op_insert );
1029  }
1030  break;
1031  case PtrKey:
1032  {
1033  Q_UINT32 k;
1034  s >> k;
1035  read( s, d );
1036  // ### cannot insert 0 - this renders the thing
1037  // useless since all pointers are written as 0,
1038  // but hey, serializing pointers? can it be done
1039  // at all, ever?
1040  if ( k )
1041  look_ptr( (void *)(uintptr_t)k, d, op_insert );
1042  }
1043  break;
1044  }
1045  }
1046  return s;
1047 }
QDataStream & read(QDataStream &)
Definition: qgdict.cpp:997
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
QCollection::Item look_int(long key, QCollection::Item, int)
Definition: qgdict.cpp:461
QCollection::Item look_ascii(const char *key, QCollection::Item, int)
Definition: qgdict.cpp:422
QCollection::Item look_ptr(void *key, QCollection::Item, int)
Definition: qgdict.cpp:492
void clear()
Definition: qgdict.cpp:857
unsigned int Q_UINT32
Definition: qglobal.h:420
uint keytype
Definition: qgdict.h:152
static const int op_insert
Definition: qgdict.cpp:62
uint copyk
Definition: qgdict.h:154
unsigned uint
Definition: qglobal.h:351
static QCString * s
Definition: config.cpp:1042
QCollection::Item look_string(const QString &key, QCollection::Item, int)
Definition: qgdict.cpp:382
void * Item
Definition: qcollection.h:60
QDataStream & QGDict::read ( QDataStream s,
QCollection::Item item 
)
protectedvirtual

Reads a collection/dictionary item from the stream s and returns a reference to the stream.

The default implementation sets item to 0.

See also
write()

Definition at line 194 of file qgdict.cpp.

195 {
196  item = 0;
197  return s;
198 }
static QCString * s
Definition: config.cpp:1042
bool QGDict::remove_ascii ( const char *  key,
QCollection::Item  item = 0 
)
protected

Definition at line 747 of file qgdict.cpp.

748 {
749  QAsciiBucket *n = unlink_ascii( key, item );
750  if ( n ) {
751  if ( copyk )
752  delete [] (char *)n->getKey();
753  deleteItem( n->getData() );
754  delete n;
755  }
756  return n != 0;
757 }
QCollection::Item getData()
Definition: qgdict.h:53
def key(type, name=None)
Definition: graph.py:13
std::void_t< T > n
const char * getKey() const
Definition: qgdict.h:78
QAsciiBucket * unlink_ascii(const char *, QCollection::Item item=0)
Definition: qgdict.cpp:663
uint copyk
Definition: qgdict.h:154
virtual void deleteItem(Item)
bool QGDict::remove_int ( long  key,
QCollection::Item  item = 0 
)
protected

Definition at line 762 of file qgdict.cpp.

763 {
764  QIntBucket *n = unlink_int( key, item );
765  if ( n ) {
766  deleteItem( n->getData() );
767  delete n;
768  }
769  return n != 0;
770 }
QCollection::Item getData()
Definition: qgdict.h:53
def key(type, name=None)
Definition: graph.py:13
std::void_t< T > n
virtual void deleteItem(Item)
QIntBucket * unlink_int(long, QCollection::Item item=0)
Definition: qgdict.cpp:684
bool QGDict::remove_ptr ( void *  key,
QCollection::Item  item = 0 
)
protected

Definition at line 775 of file qgdict.cpp.

776 {
777  QPtrBucket *n = unlink_ptr( key, item );
778  if ( n ) {
779  deleteItem( n->getData() );
780  delete n;
781  }
782  return n != 0;
783 }
QCollection::Item getData()
Definition: qgdict.h:53
QPtrBucket * unlink_ptr(void *, QCollection::Item item=0)
Definition: qgdict.cpp:704
def key(type, name=None)
Definition: graph.py:13
std::void_t< T > n
virtual void deleteItem(Item)
bool QGDict::remove_string ( const QString key,
QCollection::Item  item = 0 
)
protected

Definition at line 732 of file qgdict.cpp.

733 {
734  QStringBucket *n = unlink_string( key, item );
735  if ( n ) {
736  deleteItem( n->getData() );
737  delete n;
738  return TRUE;
739  } else {
740  return FALSE;
741  }
742 }
const bool FALSE
Definition: qglobal.h:370
QCollection::Item getData()
Definition: qgdict.h:53
std::void_t< T > n
virtual void deleteItem(Item)
QStringBucket * unlink_string(const QString &, QCollection::Item item=0)
Definition: qgdict.cpp:627
const bool TRUE
Definition: qglobal.h:371
void QGDict::resize ( uint  newsize)
protected

Definition at line 527 of file qgdict.cpp.

528 {
529  // Save old information
530  QBaseBucket **old_vec = vec;
531  uint old_vlen = vlen;
532  bool old_copyk = copyk;
533 
534  vec = new QBaseBucket *[vlen = newsize];
535  CHECK_PTR( vec );
536  memset( (char*)vec, 0, vlen*sizeof(QBaseBucket*) );
537  numItems = 0;
538  copyk = FALSE;
539 
540  // Reinsert every item from vec, deleting vec as we go
541  for ( uint index = 0; index < old_vlen; index++ ) {
542  switch ( keytype ) {
543  case StringKey:
544  {
545  QStringBucket *n=(QStringBucket *)old_vec[index];
546  while ( n ) {
547  look_string( n->getKey(), n->getData(), op_insert );
549  delete n;
550  n = t;
551  }
552  }
553  break;
554  case AsciiKey:
555  {
556  QAsciiBucket *n=(QAsciiBucket *)old_vec[index];
557  while ( n ) {
558  look_ascii( n->getKey(), n->getData(), op_insert );
560  delete n;
561  n = t;
562  }
563  }
564  break;
565  case IntKey:
566  {
567  QIntBucket *n=(QIntBucket *)old_vec[index];
568  while ( n ) {
569  look_int( n->getKey(), n->getData(), op_insert );
570  QIntBucket *t=(QIntBucket *)n->getNext();
571  delete n;
572  n = t;
573  }
574  }
575  break;
576  case PtrKey:
577  {
578  QPtrBucket *n=(QPtrBucket *)old_vec[index];
579  while ( n ) {
580  look_ptr( n->getKey(), n->getData(), op_insert );
581  QPtrBucket *t=(QPtrBucket *)n->getNext();
582  delete n;
583  n = t;
584  }
585  }
586  break;
587  }
588  }
589  delete [] old_vec;
590 
591  // Restore state
592  copyk = old_copyk;
593 
594  // Invalidate all iterators, since order is lost
595  if ( iterators && iterators->count() ) {
597  while ( i ) {
598  i->toFirst();
599  i = iterators->next();
600  }
601  }
602 }
type * first()
Definition: qinternallist.h:87
QBaseBucket ** vec
Definition: qgdict.h:149
const bool FALSE
Definition: qglobal.h:370
QCollection::Item getData()
Definition: qgdict.h:53
const QString & getKey() const
Definition: qgdict.h:68
uint vlen
Definition: qgdict.h:150
QCollection::Item look_int(long key, QCollection::Item, int)
Definition: qgdict.cpp:461
QCollection::Item look_ascii(const char *key, QCollection::Item, int)
Definition: qgdict.cpp:422
QCollection::Item look_ptr(void *key, QCollection::Item, int)
Definition: qgdict.cpp:492
QBaseBucket * getNext()
Definition: qgdict.h:55
uint numItems
Definition: qgdict.h:151
std::void_t< T > n
const char * getKey() const
Definition: qgdict.h:78
An internal class for implementing QDictIterator and QIntDictIterator.
Definition: qgdict.h:167
type * next()
Definition: qinternallist.h:89
uint keytype
Definition: qgdict.h:152
QCollection::Item toFirst()
Definition: qgdict.cpp:1161
static const int op_insert
Definition: qgdict.cpp:62
uint copyk
Definition: qgdict.h:154
#define CHECK_PTR(p)
Definition: qglobal.h:601
void * getKey() const
Definition: qgdict.h:98
QGDItList * iterators
Definition: qgdict.h:155
uint count() const
Definition: qinternallist.h:56
intptr_t getKey() const
Definition: qgdict.h:88
unsigned uint
Definition: qglobal.h:351
QCollection::Item look_string(const QString &key, QCollection::Item, int)
Definition: qgdict.cpp:382
uint QGDict::size ( ) const
inline

Definition at line 108 of file qgdict.h.

108 { return vlen; }
uint vlen
Definition: qgdict.h:150
void QGDict::statistics ( ) const
protected

Definition at line 930 of file qgdict.cpp.

931 {
932 #if defined(DEBUG)
933  QString line;
934  line.fill( '-', 60 );
935  double real, ideal;
936  qDebug( "%s",line.ascii() );
937  qDebug( "DICTIONARY STATISTICS:" );
938  if ( count() == 0 ) {
939  qDebug( "Empty!" );
940  qDebug( "%s", line.ascii() );
941  return;
942  }
943  real = 0.0;
944  ideal = (float)count()/(2.0*size())*(count()+2.0*size()-1);
945  uint i = 0;
946  while ( i<size() ) {
947  QBaseBucket *n = vec[i];
948  int b = 0;
949  while ( n ) { // count number of buckets
950  b++;
951  n = n->getNext();
952  }
953  real = real + (double)b * ((double)b+1.0)/2.0;
954  char buf[80], *pbuf;
955  if ( b > 78 )
956  b = 78;
957  pbuf = buf;
958  while ( b-- )
959  *pbuf++ = '*';
960  *pbuf = '\0';
961  qDebug( "%s", buf );
962  i++;
963  }
964  qDebug( "Array size = %d", size() );
965  qDebug( "# items = %d", count() );
966  qDebug( "Real dist = %g", real );
967  qDebug( "Rand dist = %g", ideal );
968  qDebug( "Real/Rand = %g", real/ideal );
969  qDebug( "%s",line.ascii() );
970 #endif // DEBUG
971 }
uint count() const
Definition: qgdict.h:107
void qDebug(const char *msg,...)
Definition: qglobal.cpp:376
while(1)
Definition: code.cpp:12603
QBaseBucket ** vec
Definition: qgdict.h:149
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
void fill(QChar c, int len=-1)
Definition: qstring.cpp:12865
QBaseBucket * getNext()
Definition: qgdict.h:55
const char * ascii() const
Definition: qstring.cpp:14494
#define Array
Definition: scanner.cpp:11549
std::void_t< T > n
void line(double t, double *p, double &x, double &y, double &z)
static bool * b
Definition: config.cpp:1043
uint size() const
Definition: qgdict.h:108
if(!yymsg) yymsg
unsigned uint
Definition: qglobal.h:351
static QCString * s
Definition: config.cpp:1042
QCollection::Item QGDict::take_ascii ( const char *  key)
protected

Definition at line 804 of file qgdict.cpp.

805 {
807  Item d;
808  if ( n ) {
809  if ( copyk )
810  delete [] (char *)n->getKey();
811  d = n->getData();
812  delete n;
813  } else {
814  d = 0;
815  }
816  return d;
817 }
QCollection::Item getData()
Definition: qgdict.h:53
def key(type, name=None)
Definition: graph.py:13
std::void_t< T > n
const char * getKey() const
Definition: qgdict.h:78
QAsciiBucket * unlink_ascii(const char *, QCollection::Item item=0)
Definition: qgdict.cpp:663
uint copyk
Definition: qgdict.h:154
void * Item
Definition: qcollection.h:60
QCollection::Item QGDict::take_int ( long  key)
protected

Definition at line 822 of file qgdict.cpp.

823 {
824  QIntBucket *n = unlink_int( key );
825  Item d;
826  if ( n ) {
827  d = n->getData();
828  delete n;
829  } else {
830  d = 0;
831  }
832  return d;
833 }
QCollection::Item getData()
Definition: qgdict.h:53
def key(type, name=None)
Definition: graph.py:13
std::void_t< T > n
QIntBucket * unlink_int(long, QCollection::Item item=0)
Definition: qgdict.cpp:684
void * Item
Definition: qcollection.h:60
QCollection::Item QGDict::take_ptr ( void *  key)
protected

Definition at line 838 of file qgdict.cpp.

839 {
840  QPtrBucket *n = unlink_ptr( key );
841  Item d;
842  if ( n ) {
843  d = n->getData();
844  delete n;
845  } else {
846  d = 0;
847  }
848  return d;
849 }
QCollection::Item getData()
Definition: qgdict.h:53
QPtrBucket * unlink_ptr(void *, QCollection::Item item=0)
Definition: qgdict.cpp:704
def key(type, name=None)
Definition: graph.py:13
std::void_t< T > n
void * Item
Definition: qcollection.h:60
QCollection::Item QGDict::take_string ( const QString key)
protected

Definition at line 788 of file qgdict.cpp.

789 {
790  QStringBucket *n = unlink_string( key );
791  Item d;
792  if ( n ) {
793  d = n->getData();
794  delete n;
795  } else {
796  d = 0;
797  }
798  return d;
799 }
QCollection::Item getData()
Definition: qgdict.h:53
std::void_t< T > n
QStringBucket * unlink_string(const QString &, QCollection::Item item=0)
Definition: qgdict.cpp:627
void * Item
Definition: qcollection.h:60
QAsciiBucket * QGDict::unlink_ascii ( const char *  key,
QCollection::Item  item = 0 
)
private

Definition at line 663 of file qgdict.cpp.

664 {
665  if ( numItems == 0 ) // nothing in dictionary
666  return 0;
667  QAsciiBucket *n;
668  QAsciiBucket *prev = 0;
669  int index = hashKeyAscii(key) % vlen;
670  for ( n=(QAsciiBucket *)vec[index]; n; n=(QAsciiBucket *)n->getNext() ) {
671  bool found = (cases ? qstrcmp(n->getKey(),key)
672  : qstricmp(n->getKey(),key)) == 0;
673  if ( found && d )
674  found = (n->getData() == d);
675  if ( found ) {
676  unlink_common(index,n,prev);
677  return n;
678  }
679  prev = n;
680  }
681  return 0;
682 }
QBaseBucket ** vec
Definition: qgdict.h:149
QCollection::Item getData()
Definition: qgdict.h:53
uint vlen
Definition: qgdict.h:150
QBaseBucket * getNext()
Definition: qgdict.h:55
uint numItems
Definition: qgdict.h:151
int qstricmp(const char *str1, const char *str2)
Definition: qcstring.cpp:567
int hashKeyAscii(const char *)
Definition: qgdict.cpp:123
def key(type, name=None)
Definition: graph.py:13
std::void_t< T > n
const char * getKey() const
Definition: qgdict.h:78
void unlink_common(int, QBaseBucket *, QBaseBucket *)
Definition: qgdict.cpp:610
uint cases
Definition: qgdict.h:153
Q_EXPORT int qstrcmp(const char *str1, const char *str2)
Definition: qcstring.h:95
void QGDict::unlink_common ( int  index,
QBaseBucket node,
QBaseBucket prev 
)
private

Definition at line 610 of file qgdict.cpp.

611 {
612  if ( iterators && iterators->count() ) { // update iterators
614  while ( i ) { // invalidate all iterators
615  if ( i->curNode == node ) // referring to pending node
616  i->operator++();
617  i = iterators->next();
618  }
619  }
620  if ( prev ) // unlink node
621  prev->setNext( node->getNext() );
622  else
623  vec[index] = node->getNext();
624  numItems--;
625 }
type * first()
Definition: qinternallist.h:87
QBaseBucket ** vec
Definition: qgdict.h:149
QBaseBucket * curNode
Definition: qgdict.h:192
QBaseBucket * getNext()
Definition: qgdict.h:55
uint numItems
Definition: qgdict.h:151
An internal class for implementing QDictIterator and QIntDictIterator.
Definition: qgdict.h:167
type * next()
Definition: qinternallist.h:89
QGDItList * iterators
Definition: qgdict.h:155
void setNext(QBaseBucket *n)
Definition: qgdict.h:56
uint count() const
Definition: qinternallist.h:56
QIntBucket * QGDict::unlink_int ( long  key,
QCollection::Item  item = 0 
)
private

Definition at line 684 of file qgdict.cpp.

685 {
686  if ( numItems == 0 ) // nothing in dictionary
687  return 0;
688  QIntBucket *n;
689  QIntBucket *prev = 0;
690  int index = (int)((ulong)key % vlen);
691  for ( n=(QIntBucket *)vec[index]; n; n=(QIntBucket *)n->getNext() ) {
692  bool found = (n->getKey() == key);
693  if ( found && d )
694  found = (n->getData() == d);
695  if ( found ) {
696  unlink_common(index,n,prev);
697  return n;
698  }
699  prev = n;
700  }
701  return 0;
702 }
QBaseBucket ** vec
Definition: qgdict.h:149
QCollection::Item getData()
Definition: qgdict.h:53
uint vlen
Definition: qgdict.h:150
QBaseBucket * getNext()
Definition: qgdict.h:55
uint numItems
Definition: qgdict.h:151
def key(type, name=None)
Definition: graph.py:13
std::void_t< T > n
unsigned long ulong
Definition: qglobal.h:352
void unlink_common(int, QBaseBucket *, QBaseBucket *)
Definition: qgdict.cpp:610
intptr_t getKey() const
Definition: qgdict.h:88
QPtrBucket * QGDict::unlink_ptr ( void *  key,
QCollection::Item  item = 0 
)
private

Definition at line 704 of file qgdict.cpp.

705 {
706  if ( numItems == 0 ) // nothing in dictionary
707  return 0;
708  QPtrBucket *n;
709  QPtrBucket *prev = 0;
710  int index = (int)((uintptr_t)key % vlen);
711  for ( n=(QPtrBucket *)vec[index]; n; n=(QPtrBucket *)n->getNext() ) {
712  bool found = (n->getKey() == key);
713  if ( found && d )
714  found = (n->getData() == d);
715  if ( found ) {
716  unlink_common(index,n,prev);
717  return n;
718  }
719  prev = n;
720  }
721  return 0;
722 }
QBaseBucket ** vec
Definition: qgdict.h:149
QCollection::Item getData()
Definition: qgdict.h:53
uint vlen
Definition: qgdict.h:150
QBaseBucket * getNext()
Definition: qgdict.h:55
uint numItems
Definition: qgdict.h:151
def key(type, name=None)
Definition: graph.py:13
std::void_t< T > n
void unlink_common(int, QBaseBucket *, QBaseBucket *)
Definition: qgdict.cpp:610
void * getKey() const
Definition: qgdict.h:98
QStringBucket * QGDict::unlink_string ( const QString key,
QCollection::Item  item = 0 
)
private

Definition at line 627 of file qgdict.cpp.

628 {
629  if ( numItems == 0 ) // nothing in dictionary
630  return 0;
631  QStringBucket *n;
632  QStringBucket *prev = 0;
633  int index = hashKeyString(key) % vlen;
634  if ( cases ) {
635  for ( n=(QStringBucket*)vec[index]; n;
636  n=(QStringBucket*)n->getNext() ) {
637  bool found = (key == n->getKey());
638  if ( found && d )
639  found = (n->getData() == d);
640  if ( found ) {
641  unlink_common(index,n,prev);
642  return n;
643  }
644  prev = n;
645  }
646  } else {
647  QString k = key.lower();
648  for ( n=(QStringBucket*)vec[index]; n;
649  n=(QStringBucket*)n->getNext() ) {
650  bool found = (k == n->getKey().lower());
651  if ( found && d )
652  found = (n->getData() == d);
653  if ( found ) {
654  unlink_common(index,n,prev);
655  return n;
656  }
657  prev = n;
658  }
659  }
660  return 0;
661 }
int hashKeyString(const QString &)
Definition: qgdict.cpp:86
QString lower() const
Definition: qstring.cpp:13375
QBaseBucket ** vec
Definition: qgdict.h:149
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
QCollection::Item getData()
Definition: qgdict.h:53
const QString & getKey() const
Definition: qgdict.h:68
uint vlen
Definition: qgdict.h:150
QBaseBucket * getNext()
Definition: qgdict.h:55
uint numItems
Definition: qgdict.h:151
std::void_t< T > n
void unlink_common(int, QBaseBucket *, QBaseBucket *)
Definition: qgdict.cpp:610
uint cases
Definition: qgdict.h:153
QDataStream & QGDict::write ( QDataStream s) const

Definition at line 1054 of file qgdict.cpp.

1055 {
1056  s << count(); // write number of items
1057  uint i = 0;
1058  while ( i<size() ) {
1059  QBaseBucket *n = vec[i];
1060  while ( n ) { // write all buckets
1061  switch ( keytype ) {
1062  case StringKey:
1063  s << ((QStringBucket*)n)->getKey();
1064  break;
1065  case AsciiKey:
1066  s << ((QAsciiBucket*)n)->getKey();
1067  break;
1068  case IntKey:
1069  s << (Q_UINT32)((QIntBucket*)n)->getKey();
1070  break;
1071  case PtrKey:
1072  s << (Q_UINT32)0; // ### cannot serialize a pointer
1073  break;
1074  }
1075  write( s, n->getData() ); // write data
1076  n = n->getNext();
1077  }
1078  i++;
1079  }
1080  return s;
1081 }
uint count() const
Definition: qgdict.h:107
QBaseBucket ** vec
Definition: qgdict.h:149
std::void_t< T > n
unsigned int Q_UINT32
Definition: qglobal.h:420
uint keytype
Definition: qgdict.h:152
uint size() const
Definition: qgdict.h:108
QDataStream & write(QDataStream &) const
Definition: qgdict.cpp:1054
unsigned uint
Definition: qglobal.h:351
QDataStream & QGDict::write ( QDataStream s,
QCollection::Item   
) const
protectedvirtual

Writes a collection/dictionary item to the stream s and returns a reference to the stream.

See also
read()

Definition at line 207 of file qgdict.cpp.

208 {
209  return s;
210 }
static QCString * s
Definition: config.cpp:1042

Friends And Related Function Documentation

friend class QGDictIterator
friend

Definition at line 163 of file qgdict.h.

Member Data Documentation

uint QGDict::cases
private

Definition at line 153 of file qgdict.h.

uint QGDict::copyk
private

Definition at line 154 of file qgdict.h.

QGDItList* QGDict::iterators
private

Definition at line 155 of file qgdict.h.

uint QGDict::keytype
private

Definition at line 152 of file qgdict.h.

uint QGDict::numItems
private

Definition at line 151 of file qgdict.h.

QBaseBucket** QGDict::vec
private

Definition at line 149 of file qgdict.h.

uint QGDict::vlen
private

Definition at line 150 of file qgdict.h.


The documentation for this class was generated from the following files: