KVIrc  4.9.2
DeveloperAPIs
KviPointerHashTable.h
Go to the documentation of this file.
1 #ifndef _KVI_POINTERHASHTABLE_H_
2 #define _KVI_POINTERHASHTABLE_H_
3 //============================================================================
4 //
5 // File : KviPointerHashTable.h
6 // Creation date : Sat Jan 12 2008 04:53 by Szymon Stefanek
7 //
8 // This file is part of the KVIrc IRC client distribution
9 // Copyright (C) 2008 Szymon Stefanek (pragma at kvirc dot net)
10 //
11 // This program is FREE software. You can redistribute it and/or
12 // modify it under the terms of the GNU General Public License
13 // as published by the Free Software Foundation; either version 2
14 // of the License, or (at your option) any later version.
15 //
16 // This program is distributed in the HOPE that it will be USEFUL,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 // See the GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program. If not, write to the Free Software Foundation,
23 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 //
25 //============================================================================
26 
33 #include "kvi_settings.h"
34 #include "KviPointerList.h"
35 #include "KviCString.h"
36 #include "KviQString.h"
37 #include "KviMemory.h"
38 #include "kvi_debug.h"
39 
40 #include <ctype.h>
41 
45 
49 inline unsigned int kvi_hash_hash(const char * szKey, bool bCaseSensitive)
50 {
51  unsigned int uResult = 0;
52  if(bCaseSensitive)
53  {
54  while(*szKey)
55  {
56  uResult += (unsigned char)(*(szKey));
57  szKey++;
58  }
59  }
60  else
61  {
62  while(*szKey)
63  {
64  uResult += (unsigned char)tolower(*(szKey));
65  szKey++;
66  }
67  }
68  return uResult;
69 }
70 
74 inline bool kvi_hash_key_equal(const char * szKey1, const char * szKey2, bool bCaseSensitive)
75 {
76  if(bCaseSensitive)
77  {
78  while(*szKey1 && *szKey2)
79  {
80  if(*szKey1 != *szKey2)
81  return false;
82  szKey1++;
83  szKey2++;
84  }
85  }
86  else
87  {
88  while(*szKey1 && *szKey2)
89  {
90  if(tolower(*szKey1) != tolower(*szKey2))
91  return false;
92  szKey1++;
93  szKey2++;
94  }
95  }
96  //check if one of the strings is a substring of the other (like "perl" and "perlcore")
97  if(*szKey1 || *szKey2)
98  return false;
99  return true;
100 }
101 
105 inline void kvi_hash_key_copy(const char * const & szFrom, const char *& szTo, bool bDeepCopy)
106 {
107  if(bDeepCopy)
108  {
109 #if defined(COMPILE_ON_WINDOWS)
110  // strlen() returns size_t under windows, which is 32 bits long on a 32 bits
111  // system and 64 bits long on a 64 bits one. cast it to avoid a warning
112  int len = (int)kvi_strLen(szFrom);
113 #else
114  int len = kvi_strLen(szFrom);
115 #endif
116  char * dst = (char *)KviMemory::allocate(len + 1);
117  KviMemory::copy(dst, szFrom, len + 1);
118  szTo = dst;
119  }
120  else
121  {
122  szTo = szFrom; // we never modify it anyway
123  }
124 }
125 
129 inline void kvi_hash_key_destroy(const char *& szKey, bool bDeepCopy)
130 {
131  if(bDeepCopy)
132  KviMemory::free((char *)szKey);
133 }
134 
138 inline const char *& kvi_hash_key_default(const char **)
139 {
140  static const char * static_null = NULL;
141  return static_null;
142 }
143 
147 inline unsigned int kvi_hash_hash(const KviCString & szKey, bool bCaseSensitive)
148 {
149  unsigned int uResult = 0;
150  const char * p = szKey.ptr();
151  if(bCaseSensitive)
152  {
153  while(*p)
154  {
155  uResult += *((const unsigned char *)p);
156  p++;
157  }
158  }
159  else
160  {
161  while(*p)
162  {
163  uResult += tolower(*((const unsigned char *)p));
164  p++;
165  }
166  }
167  return uResult;
168 }
169 
173 inline bool kvi_hash_key_equal(const KviCString & szKey1, const KviCString & szKey2)
174 {
175  return kvi_hash_key_equal(szKey1.ptr(), szKey2.ptr());
176 }
177 
181 inline void kvi_hash_key_copy(const KviCString & szFrom, KviCString & szTo, bool)
182 {
183  szTo = szFrom;
184 }
185 
189 inline void kvi_hash_key_destroy(KviCString &, bool)
190 {
191 }
192 
197 {
198  return KviCString::emptyString();
199 }
200 
204 inline unsigned int kvi_hash_hash(const int & iKey, bool)
205 {
206  return (unsigned int)iKey;
207 }
208 
212 inline bool kvi_hash_key_equal(const int & iKey1, const int & iKey2, bool)
213 {
214  return iKey1 == iKey2;
215 }
216 
220 inline void kvi_hash_key_copy(const int & iKeyFrom, int & iKeyTo, bool)
221 {
222  iKeyTo = iKeyFrom;
223 }
224 
228 inline void kvi_hash_key_destroy(int &, bool)
229 {
230 }
231 
235 inline const int & kvi_hash_key_default(int *)
236 {
237  static int static_default = 0;
238  return static_default;
239 }
240 
244 inline unsigned int kvi_hash_hash(const unsigned short & iKey, bool)
245 {
246  return (unsigned int)iKey;
247 }
248 
252 inline bool kvi_hash_key_equal(const unsigned short & iKey1, const unsigned short & iKey2, bool)
253 {
254  return iKey1 == iKey2;
255 }
256 
260 inline void kvi_hash_key_copy(const unsigned short & iKeyFrom, unsigned short & iKeyTo, bool)
261 {
262  iKeyTo = iKeyFrom;
263 }
264 
268 inline void kvi_hash_key_destroy(unsigned short &, bool)
269 {
270 }
271 
275 inline const unsigned short & kvi_hash_key_default(unsigned short *)
276 {
277  static unsigned short static_default = 0;
278  return static_default;
279 }
280 
284 inline unsigned int kvi_hash_hash(void * pKey, bool)
285 {
286  unsigned char * pBytes = (unsigned char *)&(pKey);
287  unsigned char * pEnd = pBytes + sizeof(void *);
288  unsigned int uSum = 0;
289  while(pBytes < pEnd)
290  {
291  uSum += *pBytes;
292  pBytes++;
293  }
294  return uSum;
295 }
296 
300 inline bool kvi_hash_key_equal(void * pKey1, void * pKey2, bool)
301 {
302  return pKey1 == pKey2;
303 }
304 
308 inline void kvi_hash_key_copy(void * const & pKeyFrom, void *& pKeyTo, bool)
309 {
310  pKeyTo = pKeyFrom;
311 }
312 
316 inline void kvi_hash_key_destroy(void *, bool)
317 {
318 }
319 
323 inline void *& kvi_hash_key_default(void *)
324 {
325  static void * static_default = NULL;
326  return static_default;
327 }
328 
332 inline unsigned int kvi_hash_hash(const QString & szKey, bool bCaseSensitive)
333 {
334  unsigned int uResult = 0;
335  const QChar * p = szKey.constData();
336  if(!p)
337  return 0;
338  if(bCaseSensitive)
339  {
340  while(p->unicode())
341  {
342  uResult += p->unicode();
343  p++;
344  }
345  }
346  else
347  {
348  while(p->unicode())
349  {
350  uResult += p->toLower().unicode();
351  p++;
352  }
353  }
354  return uResult;
355 }
356 
360 inline bool kvi_hash_key_equal(const QString & szKey1, const QString & szKey2, bool bCaseSensitive)
361 {
362  if(bCaseSensitive)
363  return KviQString::equalCS(szKey1, szKey2);
364  return KviQString::equalCI(szKey1, szKey2);
365 }
366 
370 inline void kvi_hash_key_copy(const QString & szFrom, QString & szTo, bool)
371 {
372  szTo = szFrom;
373 }
374 
378 inline void kvi_hash_key_destroy(QString &, bool)
379 {
380 }
381 
385 inline const QString & kvi_hash_key_default(QString *)
386 {
387  return KviQString::Empty;
388 }
389 
390 template <typename Key, typename T>
392 template <typename Key, typename T>
394 
395 template <typename Key, typename T>
397 {
398  friend class KviPointerHashTable<Key, T>;
399 
400 protected:
401  T * pData;
402  Key hKey;
403 
404 public:
405  Key & key() { return hKey; };
406  T * data() { return pData; };
407 };
408 
448 template <class Key, class T>
450 {
451  friend class KviPointerHashTableIterator<Key, T>;
452 
453 protected:
456  unsigned int m_uSize;
457  unsigned int m_uCount;
460  unsigned int m_uIteratorIdx;
461 
462 public:
471  T * find(const Key & hKey)
472  {
475  return 0;
477  {
478  if(kvi_hash_key_equal(e->hKey, hKey, m_bCaseSensitive))
479  return (T *)e->pData;
480  }
481  return 0;
482  }
483 
493  T * operator[](const Key & hKey)
494  {
495  return find(hKey);
496  }
497 
502  unsigned int count() const
503  {
504  return m_uCount;
505  }
506 
511  bool isEmpty() const
512  {
513  return m_uCount == 0;
514  }
515 
526  void insert(const Key & hKey, T * pData)
527  {
528  if(!pData)
529  return;
530  unsigned int uEntry = kvi_hash_hash(hKey, m_bCaseSensitive) % m_uSize;
531  if(!m_pDataArray[uEntry])
533  for(KviPointerHashTableEntry<Key, T> * e = m_pDataArray[uEntry]->first(); e; e = m_pDataArray[uEntry]->next())
534  {
535  if(kvi_hash_key_equal(e->hKey, hKey, m_bCaseSensitive))
536  {
537  if(!m_bCaseSensitive)
538  {
539  // must change the key too
541  kvi_hash_key_copy(hKey, e->hKey, m_bDeepCopyKeys);
542  }
543  if(m_bAutoDelete)
544  delete e->pData;
545  e->pData = pData;
546  return;
547  }
548  }
551  n->pData = pData;
552  m_pDataArray[uEntry]->append(n);
553  m_uCount++;
554  }
555 
567  void replace(const Key & hKey, T * pData)
568  {
569  insert(hKey, pData);
570  }
571 
581  bool remove(const Key & hKey)
582  {
583  unsigned int uEntry = kvi_hash_hash(hKey, m_bCaseSensitive) % m_uSize;
584  if(!m_pDataArray[uEntry])
585  return false;
586  for(KviPointerHashTableEntry<Key, T> * e = m_pDataArray[uEntry]->first(); e; e = m_pDataArray[uEntry]->next())
587  {
588  if(kvi_hash_key_equal(e->hKey, hKey, m_bCaseSensitive))
589  {
591  if(m_bAutoDelete)
592  delete((T *)(e->pData));
593  m_pDataArray[uEntry]->removeRef(e);
594  if(m_pDataArray[uEntry]->isEmpty())
595  {
596  delete m_pDataArray[uEntry];
597  m_pDataArray[uEntry] = 0;
598  }
599  m_uCount--;
600  return true;
601  }
602  }
603  return false;
604  }
605 
615  bool removeRef(const T * pRef)
616  {
617  for(unsigned int i = 0; i < m_uSize; i++)
618  {
619  if(m_pDataArray[i])
620  {
622  {
623  if(e->pData == pRef)
624  {
626  if(m_bAutoDelete)
627  delete((T *)(e->pData));
629  if(m_pDataArray[i]->isEmpty())
630  {
631  delete m_pDataArray[i];
632  m_pDataArray[i] = 0;
633  }
634  m_uCount--;
635  return true;
636  }
637  }
638  }
639  }
640  return false;
641  }
642 
650  void clear()
651  {
652  for(unsigned int i = 0; i < m_uSize; i++)
653  {
654  if(!m_pDataArray[i])
655  continue;
656 
657  while(KviPointerHashTableEntry<Key, T> * e = m_pDataArray[i]->takeFirst())
658  {
660 
661  if(m_bAutoDelete)
662  delete((T *)(e->pData));
663 
664  delete e;
665 
666  if(!m_pDataArray[i])
667  break; // emptied in the meantime
668  }
669 
670  if(m_pDataArray[i])
671  {
672  delete m_pDataArray[i];
673  m_pDataArray[i] = 0;
674  }
675  }
676  m_uCount = 0;
677  }
678 
688  {
690  {
692  {
694  {
695  if(e->pData == pRef)
696  return e;
697  }
698  }
699  }
700  return 0;
701  }
702 
711  {
712  if(m_uIteratorIdx >= m_uSize)
713  return 0;
716  return 0;
717  }
718 
724  {
725  m_uIteratorIdx = 0;
727  {
728  m_uIteratorIdx++;
729  }
730  if(m_uIteratorIdx == m_uSize)
731  return 0;
732  return m_pDataArray[m_uIteratorIdx]->first();
733  }
734 
743  {
744  if(m_uIteratorIdx >= m_uSize)
745  return 0;
746 
747  if(m_uIteratorIdx < m_uSize)
748  {
750  if(t)
751  return t;
752  }
753 
754  m_uIteratorIdx++;
755 
757  {
758  m_uIteratorIdx++;
759  }
760 
761  if(m_uIteratorIdx == m_uSize)
762  return 0;
763 
764  return m_pDataArray[m_uIteratorIdx]->first();
765  }
766 
774  T * current()
775  {
776  if(m_uIteratorIdx >= m_uSize)
777  return 0;
779  {
781  if(!e)
782  return 0;
783  return e->data();
784  }
785  return 0;
786  }
787 
795  const Key & currentKey()
796  {
797  if(m_uIteratorIdx >= m_uSize)
798  return kvi_hash_key_default(((Key *)NULL));
800  {
802  if(!e)
803  return kvi_hash_key_default(((Key *)NULL));
804  return e->key();
805  }
806  return kvi_hash_key_default(((Key *)NULL));
807  }
808 
814  T * first()
815  {
816  m_uIteratorIdx = 0;
818  {
819  m_uIteratorIdx++;
820  }
821  if(m_uIteratorIdx == m_uSize)
822  return 0;
824  if(!e)
825  return 0;
826  return e->data();
827  }
828 
836  T * next()
837  {
838  if(m_uIteratorIdx >= m_uSize)
839  return 0;
840 
841  if(m_uIteratorIdx < m_uSize)
842  {
844  if(t)
845  {
846  return t->data();
847  }
848  }
849 
850  m_uIteratorIdx++;
851 
853  {
854  m_uIteratorIdx++;
855  }
856 
857  if(m_uIteratorIdx == m_uSize)
858  return 0;
859 
861  if(!e)
862  return 0;
863  return e->data();
864  }
865 
877  {
878  clear();
880  insert(e->key(), e->data());
881  }
882 
891  {
893  insert(e->key(), e->data());
894  }
895 
903  void setAutoDelete(bool bAutoDelete)
904  {
905  m_bAutoDelete = bAutoDelete;
906  }
907 
917  KviPointerHashTable(unsigned int uSize = 32, bool bCaseSensitive = true, bool bDeepCopyKeys = true)
918  {
919  m_uCount = 0;
920  m_bCaseSensitive = bCaseSensitive;
921  m_bAutoDelete = true;
922  m_bDeepCopyKeys = bDeepCopyKeys;
923  m_uSize = uSize > 0 ? uSize : 32;
925  for(unsigned int i = 0; i < m_uSize; i++)
926  m_pDataArray[i] = NULL;
927  }
928 
937  {
938  m_uCount = 0;
939  m_bAutoDelete = false;
942  m_uSize = t.m_uSize;
944  for(unsigned int i = 0; i < m_uSize; i++)
945  m_pDataArray[i] = NULL;
946  copyFrom(t);
947  }
948 
955  {
956  clear();
957  delete[] m_pDataArray;
958  }
959 };
960 
965 template <typename Key, typename T>
967 {
968 protected:
970  unsigned int m_uEntryIndex;
972 
973 public:
982  {
985  if(src.m_pIterator)
987  else
988  m_pIterator = NULL;
989  }
990 
997  bool moveFirst()
998  {
999  if(m_pIterator)
1000  {
1001  delete m_pIterator;
1002  m_pIterator = NULL;
1003  }
1004 
1005  m_uEntryIndex = 0;
1006  while((m_uEntryIndex < m_pHashTable->m_uSize) && (!(m_pHashTable->m_pDataArray[m_uEntryIndex])))
1007  {
1008  m_uEntryIndex++;
1009  }
1010 
1011  if(m_uEntryIndex == m_pHashTable->m_uSize)
1012  return false;
1013 
1015  bool bRet = m_pIterator->moveFirst();
1016  if(!bRet)
1017  {
1018  delete m_pIterator;
1019  m_pIterator = NULL;
1020  }
1021  return bRet;
1022  }
1023 
1030  bool moveLast()
1031  {
1032  if(m_pIterator)
1033  {
1034  delete m_pIterator;
1035  m_pIterator = NULL;
1036  }
1037 
1038  m_uEntryIndex = m_pHashTable->m_uSize;
1039  while(m_uEntryIndex > 0)
1040  {
1041  m_uEntryIndex--;
1042  if(m_pHashTable->m_pDataArray[m_uEntryIndex])
1043  {
1045  bool bRet = m_pIterator->moveLast();
1046  if(!bRet)
1047  {
1048  delete m_pIterator;
1049  m_pIterator = NULL;
1050  }
1051  return bRet;
1052  }
1053  }
1054  return false;
1055  }
1056 
1064  bool moveNext()
1065  {
1066  if(!m_pIterator)
1067  return false;
1068  if(m_pIterator->moveNext())
1069  return true;
1070  if(m_pIterator)
1071  {
1072  delete m_pIterator;
1073  m_pIterator = NULL;
1074  }
1075  m_uEntryIndex++;
1076  while((m_uEntryIndex < m_pHashTable->m_uSize) && (!(m_pHashTable->m_pDataArray[m_uEntryIndex])))
1077  {
1078  m_uEntryIndex++;
1079  }
1080  if(m_uEntryIndex == m_pHashTable->m_uSize)
1081  return false;
1083  bool bRet = m_pIterator->moveFirst();
1084  if(!bRet)
1085  {
1086  delete m_pIterator;
1087  m_pIterator = NULL;
1088  }
1089  return bRet;
1090  }
1091 
1100  bool operator++()
1101  {
1102  return moveNext();
1103  }
1104 
1113  bool movePrev()
1114  {
1115  if(!m_pIterator)
1116  return false;
1117  if(m_pIterator->movePrev())
1118  return true;
1119  if(m_pIterator)
1120  {
1121  delete m_pIterator;
1122  m_pIterator = NULL;
1123  }
1124  if(m_uEntryIndex >= m_pHashTable->m_uSize)
1125  return false;
1126  while(m_uEntryIndex > 0)
1127  {
1128  m_uEntryIndex--;
1129  if(m_pHashTable->m_pDataArray[m_uEntryIndex])
1130  {
1132  bool bRet = m_pIterator->moveLast();
1133  if(!bRet)
1134  {
1135  delete m_pIterator;
1136  m_pIterator = NULL;
1137  }
1138  return bRet;
1139  }
1140  }
1141  return false;
1142  }
1143 
1153  bool operator--()
1154  {
1155  return movePrev();
1156  }
1157 
1165  T * current() const
1166  {
1167  return m_pIterator ? m_pIterator->current()->data() : NULL;
1168  }
1169 
1177  T * operator*() const
1178  {
1179  return m_pIterator ? m_pIterator->current()->data() : NULL;
1180  }
1181 
1188  const Key & currentKey() const
1189  {
1190  if(m_pIterator)
1191  return m_pIterator->current()->key();
1192  return kvi_hash_key_default(((Key *)NULL));
1193  }
1194 
1201  T * toFirst()
1202  {
1203  if(!moveFirst())
1204  return NULL;
1205  return current();
1206  }
1207 
1208 public:
1215  {
1216  m_pHashTable = &hTable;
1217  m_uEntryIndex = 0;
1218  m_pIterator = NULL;
1219  moveFirst();
1220  }
1221 
1226  {
1227  if(m_pIterator)
1228  delete m_pIterator;
1229  }
1230 };
1231 
1232 #endif //_KVI_POINTERHASHTABLE_H_
void clear()
Removes all the items from the hash table.
Definition: KviPointerHashTable.h:650
void kvi_hash_key_destroy(const char *&szKey, bool bDeepCopy)
Hash key destruction function for the char * data type.
Definition: KviPointerHashTable.h:129
T * pData
Definition: KviPointerHashTable.h:401
Definition: KviCString.h:105
T * operator*() const
Returs the value pointed by the iterator.
Definition: KviPointerHashTable.h:1177
T * operator[](const Key &hKey)
Returns the item associated to the key hKey.
Definition: KviPointerHashTable.h:493
This file contains the definition of the debug macros;.
T * toFirst()
Moves the iterator to the first element of the hash table.
Definition: KviPointerHashTable.h:1201
KviPointerHashTableEntry< Key, T > * currentEntry()
Returns the entry pointed by the hash table iterator.
Definition: KviPointerHashTable.h:710
char * NULL
Definition: KviIrcNumericCodes.h:391
void append(const T *d)
Appends an item at the end of the list.
Definition: KviPointerList.h:900
T * first()
Places the hash table iterator at the first entry.
Definition: KviPointerHashTable.h:814
bool removeRef(const T *pRef)
Removes the first occurrence of the item pointer pRef.
Definition: KviPointerHashTable.h:615
Key & key()
Definition: KviPointerHashTable.h:405
T * data()
Definition: KviPointerHashTable.h:406
T * find(const Key &hKey)
Returns the item associated to the key.
Definition: KviPointerHashTable.h:471
bool movePrev()
Moves the iterator to the previous element of the list.
Definition: KviPointerList.h:270
#define n
Definition: detector.cpp:78
unsigned int m_uSize
Definition: KviPointerHashTable.h:456
bool moveLast()
Moves the iterator to the last element of the list.
Definition: KviPointerList.h:225
void replace(const Key &hKey, T *pData)
Inserts the item pData at the position specified by the key hKey.
Definition: KviPointerHashTable.h:567
KviPointerHashTable(KviPointerHashTable< Key, T > &t)
First creates an empty hash table and then inserts a copy of all the item pointers present in t...
Definition: KviPointerHashTable.h:936
A fast pointer hash table iterator implementation.
Definition: KviPointerHashTable.h:393
T * first()
Returns the first item in the list.
Definition: KviPointerList.h:637
void insert(KviPointerHashTable< Key, T > &t)
Inserts a complete shallow copy of the data contained in t.
Definition: KviPointerHashTable.h:890
#define e
Definition: detector.cpp:69
T * next()
Returns the next item in the list.
Definition: KviPointerList.h:786
#define kvi_strLen(str)
Definition: KviCString.h:70
bool moveFirst()
Moves the iterator to the first element of the list.
Definition: KviPointerList.h:213
#define i
Definition: detector.cpp:73
bool moveNext()
Moves the iterator to the next element of the hash table.
Definition: KviPointerHashTable.h:1064
bool movePrev()
Moves the iterator to the previous element of the hash table.
Definition: KviPointerHashTable.h:1113
~KviPointerHashTableIterator()
Destroys the iterator.
Definition: KviPointerHashTable.h:1225
T * current()
Returns the current iteration item.
Definition: KviPointerList.h:746
bool kvi_hash_key_equal(const char *szKey1, const char *szKey2, bool bCaseSensitive)
Hash key compare function for the char * data type.
Definition: KviPointerHashTable.h:74
unsigned int count() const
Returns the number of items in this hash table.
Definition: KviPointerHashTable.h:502
bool isEmpty() const
Returns true if the hash table is empty.
Definition: KviPointerHashTable.h:511
KviPointerList< KviPointerHashTableEntry< Key, T > > ** m_pDataArray
Definition: KviPointerHashTable.h:454
const QString Empty
A global empty string (note that this is ALSO NULL under Qt 3.x)
Definition: KviQString.cpp:49
bool removeRef(const T *d)
Removes the item pointed by d (if found in the list)
Definition: KviPointerList.h:1139
KviPointerHashTableEntry< Key, T > * firstEntry()
Places the hash table iterator at the first entry and returns it.
Definition: KviPointerHashTable.h:723
const Key & currentKey() const
Returs the key pointed by the iterator.
Definition: KviPointerHashTable.h:1188
KviPointerListIterator< KviPointerHashTableEntry< Key, T > > * m_pIterator
Definition: KviPointerHashTable.h:971
void copyFrom(KviPointerHashTable< Key, T > &t)
Removes all items in the hash table and then makes a complete shallow copy of the data contained in t...
Definition: KviPointerHashTable.h:876
const Key & currentKey()
Returns the key pointed by the hash table iterator.
Definition: KviPointerHashTable.h:795
unsigned int m_uCount
Definition: KviPointerHashTable.h:457
KviPointerHashTable(unsigned int uSize=32, bool bCaseSensitive=true, bool bDeepCopyKeys=true)
Creates an empty hash table.
Definition: KviPointerHashTable.h:917
unsigned int m_uIteratorIdx
Definition: KviPointerHashTable.h:460
T * next()
Places the hash table iterator at the next entry and returns the associated data value pointer...
Definition: KviPointerHashTable.h:836
bool moveNext()
Moves the iterator to the next element of the list.
Definition: KviPointerList.h:238
void kvi_hash_key_copy(const char *const &szFrom, const char *&szTo, bool bDeepCopy)
Hash key copy function for the char * data type.
Definition: KviPointerHashTable.h:105
void insert(const Key &hKey, T *pData)
Inserts the item pData at the position specified by the key hKey.
Definition: KviPointerHashTable.h:526
QHashIterator< int, QFile * > t(getDict)
T * current()
Returs the value pointed by the iterator.
Definition: KviPointerList.h:301
bool moveLast()
Moves the iterator to the last element of the hash table.
Definition: KviPointerHashTable.h:1030
C++ Template based double linked pointer list class.
KviPointerHashTableEntry< Key, T > * nextEntry()
Places the hash table iterator at the next entry and returns it.
Definition: KviPointerHashTable.h:742
void * allocate(int size)
COMPILE_MEMORY_PROFILE.
Definition: KviMemory.h:113
A template double linked list of pointers.
Definition: KviPointerList.h:55
This file contains an internal implementation of the malloc/free functions.
bool m_bCaseSensitive
Definition: KviPointerHashTable.h:458
KviPointerHashTableEntry< Key, T > * findRef(const T *pRef)
Searches for the item pointer pRef.
Definition: KviPointerHashTable.h:687
bool operator--()
Moves the iterator to the previous element of the hash table.
Definition: KviPointerHashTable.h:1153
void setAutoDelete(bool bAutoDelete)
Enables or disabled the autodeletion feature.
Definition: KviPointerHashTable.h:903
Key hKey
Definition: KviPointerHashTable.h:402
const KviPointerHashTable< Key, T > * m_pHashTable
Definition: KviPointerHashTable.h:969
T * current()
Returns the data value pointer pointed by the hash table iterator.
Definition: KviPointerHashTable.h:774
void operator=(const KviPointerHashTableIterator< Key, T > &src)
Creates an iterator copy.
Definition: KviPointerHashTable.h:981
bool equalCI(const QString &sz1, const QString &sz2)
Compares two strings with case insensitive.
Definition: KviQString.cpp:285
unsigned int kvi_hash_hash(const char *szKey, bool bCaseSensitive)
Hash function for the char * data type.
Definition: KviPointerHashTable.h:49
bool m_bAutoDelete
Definition: KviPointerHashTable.h:455
bool m_bDeepCopyKeys
Definition: KviPointerHashTable.h:459
A fast pointer hash table implementation.
Definition: KviPointerHashTable.h:391
T * current() const
Returs the value pointed by the iterator.
Definition: KviPointerHashTable.h:1165
Definition: KviPointerHashTable.h:396
const char *& kvi_hash_key_default(const char **)
Default (empty) hash key for the char * data type.
Definition: KviPointerHashTable.h:138
This file contains compile time settings.
char * ptr() const
Definition: KviCString.h:172
void copy(void *dst_ptr, const void *src_ptr, int len)
Moves len bytes from src_ptr to dst_ptr.
Definition: KviMemory.h:166
void free(void *ptr)
COMPILE_MEMORY_CHECKS.
Definition: KviMemory.h:125
bool equalCS(const QString &sz1, const QString &sz2)
Compares two strings with case sensitive.
Definition: KviQString.cpp:257
bool moveFirst()
Moves the iterator to the first element of the hash table.
Definition: KviPointerHashTable.h:997
#define p
Definition: detector.cpp:80
KviPointerHashTableIterator(const KviPointerHashTable< Key, T > &hTable)
Creates an iterator pointing to the first item in the hash table, if any.
Definition: KviPointerHashTable.h:1214
A fast KviPointerList iterator.
Definition: KviPointerList.h:57
Helper functions for the QString class.
static KviCString & emptyString()
Definition: KviCString.cpp:3159
unsigned int m_uEntryIndex
Definition: KviPointerHashTable.h:970
~KviPointerHashTable()
Destroys the hash table and all the items contained within.
Definition: KviPointerHashTable.h:954
bool operator++()
Moves the iterator to the next element of the hash table.
Definition: KviPointerHashTable.h:1100