PTLib  Version 2.18.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
dict.h
Go to the documentation of this file.
1 /*
2  * dict.h
3  *
4  * Dictionary (hash table) Container classes.
5  *
6  * Portable Tools Library
7  *
8  * Copyright (c) 1993-1998 Equivalence Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Portable Windows Library.
21  *
22  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23  *
24  * Portions are Copyright (C) 1993 Free Software Foundation, Inc.
25  * All Rights Reserved.
26  *
27  * Contributor(s): ______________________________________.
28  */
29 
30 
31 #ifndef PTLIB_DICT_H
32 #define PTLIB_DICT_H
33 
34 #ifdef P_USE_PRAGMA
35 #pragma interface
36 #endif
37 
38 #include <ptlib/array.h>
39 
41 // PDictionary classes
42 
46 template <typename T>
47 class PKey : public PObject
48 {
49  PCLASSINFO(PKey, PObject);
50  public:
51  typedef T value_type;
52  typedef PKey<T> my_type;
53 
59  value_type newKey = 0
60  ) : m_key(newKey) { }
61 
65  { this->m_key = newKey; return *this; }
67 
70  virtual PObject * Clone() const { return new PKey(this->m_key); }
72 
73  /* Get the relative rank of the ordinal index. This is a simpel comparison
74  of the objects PINDEX values.
75 
76  @return
77  comparison of the two objects, <code>EqualTo</code> for same,
78  <code>LessThan</code> for \p obj logically less than the
79  object and <code>GreaterThan</code> for \p obj logically
80  greater than the object.
81  */
82  virtual Comparison Compare(const PObject & obj) const
83  {
84  return Compare2(this->m_key, dynamic_cast<const my_type &>(obj).m_key);
85  }
86 
93  virtual PINDEX HashFunction() const
94  {
95 #if PINDEX_SIGNED
96  return std::abs((PINDEX)this->m_key)%23;
97 #else
98  return ((PINDEX)this->m_key)%23;
99 #endif
100  }
101 
108  virtual void PrintOn(ostream & strm) const { strm << this->m_key; }
110 
115  PINLINE operator value_type() const { return this->m_key; }
116 
119  PINLINE value_type operator++() { return ++this->m_key; }
120 
123  PINLINE value_type operator++(int) { return this->m_key++; }
124 
127  PINLINE value_type operator--() { return --this->m_key; }
128 
131  PINLINE value_type operator--(int) { return this->m_key--; }
132 
135  PINLINE PKey & operator+=(value_type add) { this->m_key += add; return *this; }
136 
139  PINLINE PKey & operator-=(value_type minus) { this->m_key -= minus; return *this; }
141 
142  private:
143  value_type m_key;
144 };
145 
147 
148 
150 
151 // Member variables
153 {
158  PINDEX m_bucket;
159 
161 };
162 
165 {
167  : m_head(NULL)
168  , m_tail(NULL)
169 #if PTRACING
170  , m_size(0)
171 #endif
172  { }
175 #if PTRACING
176  PINDEX m_size;
177 #endif
178 };
180 __inline std::ostream & operator<<(std::ostream & strm, const PHashTableList & hash) { return strm << (void *)hash.m_head; }
181 
182 class PHashTable;
183 
184 
185 class PHashTableInfo : public PBaseArray<PHashTableList>
186 {
188  PCLASSINFO(PCharArray, ParentClass);
189  public:
190  PHashTableInfo(PINDEX initialSize = 0)
191  : ParentClass(initialSize), deleteKeys(true) { }
192  PHashTableInfo(PHashTableList const * buffer, PINDEX length, PBoolean dynamic = true)
193  : ParentClass(buffer, length, dynamic), deleteKeys(true) { }
194  virtual PObject * Clone() const { return PNEW PHashTableInfo(*this, GetSize()); }
195  virtual ~PHashTableInfo() { Destruct(); }
196  virtual void DestroyContents();
197 
198  void AppendElement(PObject * key, PObject * data PTRACE_PARAM(, PHashTable * owner));
199  PObject * RemoveElement(const PObject & key);
200  PHashTableElement * GetElementAt(PINDEX index);
201  PHashTableElement * GetElementAt(const PObject & key);
202  PINDEX GetElementsIndex(const PObject*obj,PBoolean byVal,PBoolean keys) const;
205 
207  PTRACE_THROTTLE(m_throttlePoorHashFunction, 1);
208 
209  friend class PHashTable;
210  friend class PAbstractSet;
211 };
212 
213 
224 class PHashTable : public PCollection
225 {
226  PCONTAINERINFO(PHashTable, PCollection);
227 
228  public:
231  PHashTable();
234 
246  virtual Comparison Compare(
247  const PObject & obj
248  ) const;
250 
251 
261  virtual PBoolean SetSize(
262  PINDEX newSize
263  );
265 
266 
278  const PObject & key
279  ) const;
280 
297  virtual const PObject & AbstractGetKeyAt(
298  PINDEX index
299  ) const;
300 
317  virtual PObject & AbstractGetDataAt(
318  PINDEX index
319  ) const;
321 
323 };
324 
325 
327 
330 class PAbstractSet : public PHashTable
331 {
332  PCONTAINERINFO(PAbstractSet, PHashTable);
333  public:
343 
354  virtual PINDEX Append(
355  PObject * obj
356  );
357 
370  virtual PINDEX Insert(
371  const PObject & before,
372  PObject * obj
373  );
374 
387  virtual PINDEX InsertAt(
388  PINDEX index,
389  PObject * obj
390  );
391 
402  virtual PBoolean Remove(
403  const PObject * obj
404  );
405 
417  virtual PObject * RemoveAt(
418  PINDEX index
419  );
420 
431  virtual PObject * GetAt(
432  PINDEX index
433  ) const;
434 
447  virtual PBoolean SetAt(
448  PINDEX index,
449  PObject * val
450  );
451 
463  virtual PINDEX GetObjectsIndex(
464  const PObject * obj
465  ) const;
466 
475  virtual PINDEX GetValuesIndex(
476  const PObject & obj
477  ) const;
478 
482  bool Union(
483  const PAbstractSet & set
484  );
485 
489  static bool Intersection(
490  const PAbstractSet & set1,
491  const PAbstractSet & set2,
492  PAbstractSet * intersection = NULL
493  );
495 };
496 
497 
508 template <class T> class PSet : public PAbstractSet
509 {
510  PCLASSINFO(PSet, PAbstractSet);
511 
512  public:
522  inline PSet(PBoolean initialDeleteObjects = false)
523  : PAbstractSet() { this->AllowDeleteObjects(initialDeleteObjects); }
525 
531  virtual PObject * Clone() const
532  { return PNEW PSet(0, this); }
534 
546  void Include(
547  const T * obj // New object to include in the set.
548  ) { this->Append((PObject *)obj); }
549 
558  const T & obj // New object to include in the set.
559  ) { this->Append(obj.Clone()); return *this; }
560 
568  void Exclude(
569  const T * obj // New object to exclude in the set.
570  ) { this->Remove(obj); }
571 
580  const T & obj // New object to exclude in the set.
581  ) { this->erase(this->find(obj)); return *this; }
582 
592  const T & key
593  ) const { return this->AbstractContains(key); }
594 
604  const T & key
605  ) const { return this->AbstractContains(key); }
606 
620  virtual const T & GetKeyAt(
621  PINDEX index
622  ) const
623  { return dynamic_cast<const T &>(this->AbstractGetKeyAt(index)); }
625 
628  class iterator;
629  class const_iterator;
630  class iterator_base : public std::iterator<std::forward_iterator_tag, T> {
631  protected:
633  : table(NULL)
634  , element(NULL)
635  { }
637  : table(t)
638  , element(t->GetElementAt((PINDEX)0))
639  { }
640  iterator_base(PHashTableInfo * t, const T & k)
641  : table(t)
642  , element(t->GetElementAt(k))
643  { }
644 
647 
648  void Next() { this->element = PAssertNULL(this->table)->NextElement(this->element); }
649  void Prev() { this->element = PAssertNULL(this->table)->PrevElement(this->element); }
650 
651  T * Ptr() const { return dynamic_cast<T *>(PAssertNULL(this->element)->m_key); }
652 
653  public:
654  bool operator==(const iterator_base & it) const { return this->element == it.element; }
655  bool operator!=(const iterator_base & it) const { return this->element != it.element; }
656  };
657 
658  class iterator : public iterator_base {
659  protected:
661  iterator(PHashTableInfo * t, const T & k) : iterator_base(t, k) { }
662 
663  public:
664  iterator() { }
665 
666  iterator operator++() { this->Next(); return *this; }
667  iterator operator--() { this->Prev(); return *this; }
668  iterator operator++(int) { iterator it = *this; this->Next(); return it; }
669  iterator operator--(int) { iterator it = *this; this->Prev(); return it; }
670 
671  T * operator->() const { return this->Ptr(); }
672  T & operator* () const { return *this->Ptr(); }
673 
674  friend class PSet<T>;
675  };
676 
677  iterator begin() { return iterator(this->hashTable); }
678  iterator end() { return iterator(); }
679  iterator find(const T & k) { return iterator(this->hashTable, k); }
680 
681 
682  class const_iterator : public iterator_base {
683  protected:
685  const_iterator(PHashTableInfo * t, const T & k) : iterator_base(t, k) { }
686 
687  public:
689 
690  const_iterator operator++() { this->Next(); return *this; }
691  const_iterator operator--() { this->Prev(); return *this; }
692  const_iterator operator++(int) { const_iterator it = *this; this->Next(); return it; }
693  const_iterator operator--(int) { const_iterator it = *this; this->Prev(); return it; }
694 
695  const T * operator->() const { return this->Ptr(); }
696  const T & operator* () const { return *this->Ptr(); }
697 
698  friend class PSet<T>;
699  };
700 
701  const_iterator begin() const { return const_iterator(this->hashTable); }
702  const_iterator end() const { return const_iterator(); }
703  const_iterator find(const T & k) const { return const_iterator(this->hashTable, k); }
704 
705  void erase(const iterator & it) { this->Remove(&*it); }
706  void erase(const const_iterator & it) { this->Remove(&*it); }
708 
709  protected:
710  PSet(int dummy, const PSet * c)
711  : PAbstractSet(dummy, c)
713 };
714 
715 
727 #define PSET(cls, T) typedef PSet<T> cls
728 
729 
741 #define PDECLARE_SET(cls, T, initDelObj) \
742  class cls : public PSet<T> { \
743  typedef PSet<T> BaseClass; PCLASSINFO(cls, BaseClass) \
744  protected: \
745  cls(int dummy, const cls * c) \
746  : BaseClass(dummy, c) { } \
747  public: \
748  cls(PBoolean initialDeleteObjects = initDelObj) \
749  : BaseClass(initialDeleteObjects) { } \
750  virtual PObject * Clone() const \
751  { return PNEW cls(0, this); } \
752 
753 
755 PDECLARE_SET(POrdinalSet, POrdinalKey, true)
756 };
757 
759 
763 {
764  PCLASSINFO(PAbstractDictionary, PHashTable);
765  public:
775 
784  virtual void PrintOn(
785  ostream &strm
786  ) const;
788 
799  virtual PINDEX Insert(
800  const PObject & key,
801  PObject * obj
802  );
803 
810  virtual PINDEX InsertAt(
811  PINDEX index,
812  PObject * obj
813  );
814 
824  virtual PObject * RemoveAt(
825  PINDEX index
826  );
827 
836  virtual PBoolean SetAt(
837  PINDEX index,
838  PObject * val
839  );
840 
847  virtual PObject * GetAt(
848  PINDEX index
849  ) const;
850 
862  virtual PINDEX GetObjectsIndex(
863  const PObject * obj
864  ) const;
865 
874  virtual PINDEX GetValuesIndex(
875  const PObject & obj
876  ) const;
878 
879 
891  PINDEX index,
892  PObject * obj
893  );
894 
906  virtual PObject * AbstractSetAt(
907  const PObject & key,
908  PObject * obj
909  );
910 
920  virtual PObject & GetRefAt(
921  const PObject & key
922  ) const;
923 
930  virtual PObject * AbstractGetAt(
931  const PObject & key
932  ) const;
933 
936  virtual void AbstractGetKeys(
937  PArrayObjects & keys
938  ) const;
940 
941  protected:
942  PINLINE PAbstractDictionary(int dummy, const PAbstractDictionary * c);
943 
944  private:
950  virtual PINDEX Append(
951  PObject * obj
952  );
953 
964  virtual PBoolean Remove(
965  const PObject * obj
966  );
967 
968 };
969 
970 
978 template <class K, class D> class PDictionary : public PAbstractDictionary
979 {
980  PCLASSINFO(PDictionary, PAbstractDictionary);
981 
982  public:
983  typedef K key_type;
984  typedef D data_type;
986 
996  : PAbstractDictionary() { }
998 
1005  virtual PObject * Clone() const
1006  { return PNEW PDictionary(0, this); }
1008 
1021  const D & operator[](
1022  const K & key
1023  ) const { return dynamic_cast<const D &>(this->GetRefAt(key)); }
1025  const K & key
1026  ) { return dynamic_cast<D &>(this->GetRefAt(key)); }
1027 
1037  const K & key
1038  ) const { return this->AbstractContains(key); }
1039 
1049  virtual D * RemoveAt(
1050  const K & key
1051  ) { return dynamic_cast<D *>(this->AbstractSetAt(key, NULL)); }
1052 
1064  virtual PBoolean SetAt(
1065  const K & key, // Key for position in dictionary to add object.
1066  D * obj // New object to put into the dictionary.
1067  ) { return this->AbstractSetAt(key, obj) != NULL; }
1068 
1075  virtual D * GetAt(
1076  const K & key // Key for position in dictionary to get object.
1077  ) const { return dynamic_cast<D *>(this->AbstractGetAt(key)); }
1078 
1092  const K & GetKeyAt(
1093  PINDEX index
1094  ) const
1095  { return dynamic_cast<const K &>(this->AbstractGetKeyAt(index)); }
1096 
1111  PINDEX index
1112  ) const
1113  { return dynamic_cast<D &>(this->AbstractGetDataAt(index)); }
1114 
1118  {
1119  PArray<K> keys;
1120  this->AbstractGetKeys(keys);
1121  return keys;
1122  }
1124 
1127  class iterator;
1128  class const_iterator;
1130  protected:
1131  K * m_internal_first; // Must be first two members
1133 
1136 
1138  : m_internal_first(NULL)
1139  , m_internal_second(NULL)
1140  , m_table(NULL)
1141  , m_element(NULL)
1142  {
1143  }
1144 
1145  iterator_base(const dict_type * dict)
1146  : m_table(dict->hashTable)
1147  {
1148  this->SetElement(this->m_table->GetElementAt((PINDEX)0));
1149  }
1150 
1151  iterator_base(const dict_type * dict, const K & key)
1152  : m_table(dict->hashTable)
1153  {
1154  this->SetElement(this->m_table->GetElementAt(key));
1155  }
1156 
1158  {
1159  this->m_element = element;
1160  if (element != NULL) {
1161  this->m_internal_first = dynamic_cast<K *>(element->m_key);
1162  this->m_internal_second = dynamic_cast<D *>(element->m_data);
1163  }
1164  else {
1165  this->m_internal_first = NULL;
1166  this->m_internal_second = NULL;
1167  }
1168  }
1169 
1170  P_PUSH_MSVC_WARNINGS(6011)
1171  void Next() { this->SetElement(PAssertNULL(this->m_table)->NextElement(this->m_element)); }
1172  void Prev() { this->SetElement(PAssertNULL(this->m_table)->PrevElement(this->m_element)); }
1174 
1175  public:
1176  bool operator==(const iterator_base & it) const { return this->m_element == it.m_element; }
1177  bool operator!=(const iterator_base & it) const { return this->m_element != it.m_element; }
1178  };
1179 
1180  template<class CK, class CD>
1182  public:
1183  CK & first;
1184  CD & second;
1185 
1186  private:
1187  iterator_pair() : first(reinterpret_cast<CK&>(0)), second(reinterpret_cast<CD&>(0)) { }
1188  };
1189 
1190  class iterator : public iterator_base, public std::iterator<std::forward_iterator_tag, iterator_pair<K,D> > {
1191  protected:
1192  iterator(dict_type * dict) : iterator_base(dict) { }
1193  iterator(dict_type * dict, const K & key) : iterator_base(dict, key) { }
1194 
1195  public:
1196  iterator() { }
1197 
1198  iterator operator++() { this->Next(); return *this; }
1199  iterator operator--() { this->Prev(); return *this; }
1200  iterator operator++(int) { iterator it = *this; this->Next(); return it; }
1201  iterator operator--(int) { iterator it = *this; this->Prev(); return it; }
1202 
1204  const pair * operator->() const { return reinterpret_cast<const pair *>(this); }
1205  const pair & operator* () const { return *reinterpret_cast<const pair *>(this); }
1206 
1207  friend class PDictionary<K, D>;
1208  };
1209 
1210  iterator begin() { return iterator(this); }
1211  iterator end() { return iterator(); }
1212  iterator find(const K & key) { return iterator(this, key); }
1213 
1214 
1215  class const_iterator : public iterator_base, public std::iterator<std::forward_iterator_tag, iterator_pair<const K,const D> > {
1216  protected:
1217  const_iterator(const dict_type * dict) : iterator_base(dict) { }
1218  const_iterator(const dict_type * dict, const K & key) : iterator_base(dict, key) { }
1219 
1220  public:
1223 
1224  const_iterator operator++() { this->Next(); return *this; }
1225  const_iterator operator--() { this->Prev(); return *this; }
1226  const_iterator operator++(int) { const_iterator it = *this; this->Next(); return it; }
1227  const_iterator operator--(int) { const_iterator it = *this; this->Prev(); return it; }
1228 
1230  const pair * operator->() const { return reinterpret_cast<const pair *>(this); }
1231  const pair & operator* () const { return *reinterpret_cast<const pair *>(this); }
1232 
1233  friend class PDictionary<K, D>;
1234  };
1235 
1236  const_iterator begin() const { return const_iterator(this); }
1237  const_iterator end() const { return const_iterator(); }
1238  const_iterator find(const K & k) const { return const_iterator(this, k); }
1239 
1240  void erase(const iterator & it) { this->AbstractSetAt(*it.m_element->m_key, NULL); }
1241  void erase(const const_iterator & it) { this->AbstractSetAt(*it.m_element->m_key, NULL); }
1243 
1244  protected:
1245  PDictionary(int dummy, const PDictionary * c)
1246  : PAbstractDictionary(dummy, c) { }
1247 };
1248 
1249 
1262 #define PDICTIONARY(cls, K, D) typedef PDictionary<K, D> cls
1263 
1264 
1277 #define PDECLARE_DICTIONARY(cls, K, D) \
1278  PDICTIONARY(cls##_PTemplate, K, D); \
1279  PDECLARE_CLASS(cls, cls##_PTemplate) \
1280  protected: \
1281  cls(int dummy, const cls * c) \
1282  : cls##_PTemplate(dummy, c) { } \
1283  public: \
1284  cls() \
1285  : cls##_PTemplate() { } \
1286  virtual PObject * Clone() const \
1287  { return PNEW cls(0, this); } \
1288 
1289 
1297 template <class K> class POrdinalDictionary : public PDictionary<K, POrdinalKey>
1298 {
1300  PCLASSINFO(POrdinalDictionary, ParentClass);
1301 
1302  public:
1312  : ParentClass() { }
1314 
1321  virtual PObject * Clone() const
1322  { return PNEW POrdinalDictionary(0, this); }
1324 
1337  PINDEX operator[](
1338  const K & key // Key to look for in the dictionary.
1339  ) const
1340  { return dynamic_cast<POrdinalKey &>(this->GetRefAt(key)); }
1341 
1356  PINDEX index,
1357  PINDEX ordinal
1358  ) { return this->AbstractSetAt(this->AbstractGetKeyAt(index), PNEW POrdinalKey(ordinal)) != NULL; }
1359 
1371  virtual PBoolean SetAt(
1372  const K & key,
1373  PINDEX ordinal
1374  ) { return this->AbstractSetAt(key, PNEW POrdinalKey(ordinal)) != NULL; }
1375 
1389  const K & GetKeyAt(
1390  PINDEX index
1391  ) const
1392  { return dynamic_cast<const K &>(this->AbstractGetKeyAt(index)); }
1393 
1410  PINDEX GetDataAt(
1411  PINDEX index
1412  ) const
1413  { return dynamic_cast<POrdinalKey &>(this->AbstractGetDataAt(index)); }
1415 
1416  protected:
1418  : ParentClass(dummy, c) { }
1419 };
1420 
1421 
1434 #define PORDINAL_DICTIONARY(cls, K) typedef POrdinalDictionary<K> cls
1435 
1436 
1451 #define PDECLARE_ORDINAL_DICTIONARY(cls, K) \
1452  PORDINAL_DICTIONARY(cls##_PTemplate, K); \
1453  PDECLARE_CLASS(cls, POrdinalDictionary<K>) \
1454  protected: \
1455  cls(int dummy, const cls * c) \
1456  : cls##_PTemplate(dummy, c) { } \
1457  public: \
1458  cls() \
1459  : cls##_PTemplate() { } \
1460  virtual PObject * Clone() const \
1461  { return PNEW cls(0, this); } \
1462 
1463 
1464 #endif // PTLIB_DICT_H
1465 
1466 // End Of File ///////////////////////////////////////////////////////////////
PINLINE PBoolean AbstractContains(const PObject &key) const
Determine if the value of the object is contained in the hash table.
PINLINE value_type operator--(int)
Operator to post-decrement the ordinal.
Definition: dict.h:131
virtual const T & GetKeyAt(PINDEX index) const
Get the key in the set at the ordinal index position.
Definition: dict.h:620
PDictionary< K, D > dict_type
Definition: dict.h:985
const_iterator()
Definition: dict.h:688
iterator(PHashTableInfo *t, const T &k)
Definition: dict.h:661
PObject * RemoveElement(const PObject &key)
void Next()
Definition: dict.h:648
virtual PINDEX GetObjectsIndex(const PObject *obj) const
Search the collection for the specific instance of the object.
PKey< PINDEX > POrdinalKey
Definition: dict.h:146
void Include(const T *obj)
Include the specified object into the set.
Definition: dict.h:546
iterator_pair< K, D > pair
Definition: dict.h:1203
PHashTable()
Create a new, empty, hash table.
virtual PBoolean SetAt(PINDEX index, PObject *val)
Set the object at the specified index to the new value.
T * operator->() const
Definition: dict.h:671
iterator operator++()
Definition: dict.h:666
T * Ptr() const
Definition: dict.h:651
bool Union(const PAbstractSet &set)
Calculate union of sets.
iterator end()
Definition: dict.h:678
const D & operator[](const K &key) const
Get the object contained in the dictionary at the key position.
Definition: dict.h:1021
iterator_base(PHashTableInfo *t, const T &k)
Definition: dict.h:640
iterator end()
Definition: dict.h:1211
const K & GetKeyAt(PINDEX index) const
Get the key in the dictionary at the ordinal index position.
Definition: dict.h:1389
virtual void PrintOn(ostream &strm) const
Output the contents of the object to the stream.
virtual P_DEPRECATED PBoolean SetDataAt(PINDEX index, PObject *obj)
Set the data at the specified ordinal index position in the dictionary.
iterator find(const T &k)
Definition: dict.h:679
An array of objects.
Definition: array.h:714
void Destruct()
Internal function called from container destructors.
CD & second
Definition: dict.h:1184
virtual PINDEX InsertAt(PINDEX index, PObject *obj)
Add a new object to the collection.
virtual PBoolean SetAt(const K &key, PINDEX ordinal)
Add a new object to the collection.
Definition: dict.h:1371
PINLINE value_type operator++(int)
Operator to post-increment the ordinal.
Definition: dict.h:123
iterator operator--()
Definition: dict.h:1199
Array of characters.
Definition: array.h:552
PINDEX GetElementsIndex(const PObject *obj, PBoolean byVal, PBoolean keys) const
PSet(int dummy, const PSet *c)
Definition: dict.h:710
iterator begin()
Definition: dict.h:677
D * m_internal_second
Definition: dict.h:1132
const_iterator(PHashTableInfo *t, const T &k)
Definition: dict.h:685
T value_type
Definition: dict.h:51
PINLINE PKey & operator+=(value_type add)
Operator to add the ordinal.
Definition: dict.h:135
iterator operator++()
Definition: dict.h:1198
virtual PBoolean SetAt(PINDEX index, PObject *val)
Add a new object to the collection.
iterator(PHashTableInfo *t)
Definition: dict.h:660
This template class maps the PAbstractArray to a specific element type.
Definition: array.h:276
PHashTableElement * m_next
Definition: dict.h:156
PINLINE void AllowDeleteObjects(PBoolean yes=true)
Allow or disallow the deletion of the objects contained in the collection.
virtual PINDEX GetValuesIndex(const PObject &obj) const
Search the collection for the specified value of the object.
#define PTRACE_PARAM(...)
Definition: object.h:935
POrdinalDictionary()
Create a new, empty, dictionary.
Definition: dict.h:1311
Definition: dict.h:1181
virtual PObject * Clone() const
Make a complete duplicate of the dictionary.
Definition: dict.h:1321
PHashTableInfo * m_table
Definition: dict.h:1134
const_iterator operator--()
Definition: dict.h:1225
PHashTableElement * m_tail
Definition: dict.h:174
This template class maps the PAbstractDictionary to a specific key and data types.
Definition: dict.h:978
iterator operator--(int)
Definition: dict.h:1201
const_iterator operator++()
Definition: dict.h:690
#define PINLINE
Definition: object.h:194
void Prev()
Definition: dict.h:1172
iterator operator--()
Definition: dict.h:667
K key_type
Definition: dict.h:983
PKey< T > my_type
Definition: dict.h:52
const T * operator->() const
Definition: dict.h:695
Comparison
Result of the comparison operation performed by the Compare() function.
Definition: object.h:2251
PINLINE value_type operator--()
Operator to pre-decrement the ordinal.
Definition: dict.h:127
const_iterator operator++(int)
Definition: dict.h:692
virtual PINDEX GetObjectsIndex(const PObject *obj) const
Search the collection for the specific instance of the object.
const_iterator operator++(int)
Definition: dict.h:1226
iterator(dict_type *dict)
Definition: dict.h:1192
virtual PINDEX Append(PObject *obj)
Add a new object to the collection.
PINLINE PAbstractDictionary()
Create a new, empty, dictionary.
A set of ordinal integers.
Definition: dict.h:762
const_iterator(const dict_type *dict, const K &key)
Definition: dict.h:1218
virtual PObject * AbstractSetAt(const PObject &key, PObject *obj)
Add a new object to the collection.
iterator operator--(int)
Definition: dict.h:669
const_iterator()
Definition: dict.h:1221
PHashTableElement * m_head
Definition: dict.h:173
const_iterator operator--(int)
Definition: dict.h:693
#define P_POP_MSVC_WARNINGS()
Definition: object.h:154
void Next()
Definition: dict.h:1171
iterator_base(PHashTableInfo *t)
Definition: dict.h:636
iterator operator++(int)
Definition: dict.h:668
const_iterator begin() const
Definition: dict.h:701
virtual PObject * GetAt(PINDEX index) const
This function is the same as PHashTable::AbstractGetKeyAt().
const pair * operator->() const
Definition: dict.h:1230
void erase(const const_iterator &it)
Definition: dict.h:1241
virtual PObject * Clone() const
Clone the object.
Definition: dict.h:194
PINDEX operator[](const K &key) const
Get the object contained in the dictionary at the key position.
Definition: dict.h:1337
virtual void AbstractGetKeys(PArrayObjects &keys) const
Get an array containing all the keys for the dictionary.
virtual PINDEX GetValuesIndex(const PObject &obj) const
Search the collection for the specified value of the object.
K * m_internal_first
Definition: dict.h:1131
virtual Comparison Compare(const PObject &obj) const
Get the relative rank of the two hash tables.
Definition: dict.h:152
void SetElement(PHashTableElement *element)
Definition: dict.h:1157
T & operator*() const
Definition: dict.h:672
Definition: dict.h:630
iterator_base(const dict_type *dict, const K &key)
Definition: dict.h:1151
bool operator!=(const iterator_base &it) const
Definition: dict.h:655
bool deleteKeys
Definition: dict.h:206
PBoolean Contains(const T &key) const
Determine if the value of the object is contained in the set.
Definition: dict.h:591
const_iterator begin() const
Definition: dict.h:1236
virtual void PrintOn(ostream &strm) const
Output the ordinal index to the specified stream.
Definition: dict.h:108
virtual PBoolean SetSize(PINDEX newSize)
This function is meaningless for hash table.
Definition: dict.h:185
virtual PINDEX HashFunction() const
This function calculates a hash table index value for the implementation of PSet and PDictionary clas...
Definition: dict.h:93
PDECLARE_POOL_ALLOCATOR(PHashTableElement)
POrdinalDictionary(int dummy, const POrdinalDictionary *c)
Definition: dict.h:1417
PBoolean operator[](const T &key) const
Determine if the value of the object is contained in the set.
Definition: dict.h:603
PHashTableList()
Definition: dict.h:166
virtual PObject * Clone() const
Make a complete duplicate of the set.
Definition: dict.h:531
PDictionary(int dummy, const PDictionary *c)
Definition: dict.h:1245
PINLINE PKey & operator=(value_type newKey)
Operator to assign the ordinal.
Definition: dict.h:64
iterator_base()
Definition: dict.h:632
PHashTableInfo(PINDEX initialSize=0)
Definition: dict.h:190
Abstract set of PObjects.
Definition: dict.h:330
virtual Comparison Compare(const PObject &obj) const
Compare the two objects and return their relative rank.
Definition: dict.h:82
virtual PObject * AbstractGetAt(const PObject &key) const
Get the object at the specified key position.
iterator find(const K &key)
Definition: dict.h:1212
iterator()
Definition: dict.h:1196
const_iterator find(const T &k) const
Definition: dict.h:703
void Prev()
Definition: dict.h:649
This class is used when an ordinal index value is the key for PSet and PDictionary classes...
Definition: dict.h:47
PINDEX m_bucket
Definition: dict.h:158
Definition: dict.h:1190
const_iterator operator--(int)
Definition: dict.h:1227
D & GetDataAt(PINDEX index) const
Get the data in the dictionary at the ordinal index position.
Definition: dict.h:1110
#define PAssertNULL(ptr)
This macro is used to assert that a pointer must be non-null.
Definition: object.h:428
bool operator!=(const iterator_base &it) const
Definition: dict.h:1177
void erase(const iterator &it)
Definition: dict.h:1240
virtual PINDEX GetSize() const
Get the current size of the container.
PBoolean Contains(const K &key) const
Determine if the value of the object is contained in the hash table.
Definition: dict.h:1036
bool PBoolean
Definition: object.h:174
const pair & operator*() const
Definition: dict.h:1205
iterator operator++(int)
Definition: dict.h:1200
PHashTableElement * PrevElement(PHashTableElement *element) const
const_iterator end() const
Definition: dict.h:702
This template class maps the PAbstractSet to a specific object type.
Definition: dict.h:508
bool operator==(const iterator_base &it) const
Definition: dict.h:654
virtual ~PHashTableInfo()
Definition: dict.h:195
#define PDECLARE_SET(cls, T, initDelObj)
Begin declaration of a set class.
Definition: dict.h:741
void erase(const const_iterator &it)
Definition: dict.h:706
PHashTableElement * m_element
Definition: dict.h:1135
#define P_PUSH_MSVC_WARNINGS(warnings)
Definition: object.h:153
const pair & operator*() const
Definition: dict.h:1231
virtual D * GetAt(const K &key) const
Get the object at the specified key position.
Definition: dict.h:1075
virtual PINDEX Insert(const PObject &before, PObject *obj)
Add a new object to the collection.
void AppendElement(PObject *key, PObject *data PTRACE_PARAM(, PHashTable *owner))
The hash table class is the basis for implementing the PSet and PDictionary classes.
Definition: dict.h:224
bool deleteObjects
Definition: contain.h:67
PObject * m_key
Definition: dict.h:154
const_iterator end() const
Definition: dict.h:1237
iterator_base(const dict_type *dict)
Definition: dict.h:1145
PSet & operator+=(const T &obj)
Include the specified objects value into the set.
Definition: dict.h:557
iterator_pair< const K, const D > pair
Definition: dict.h:1229
virtual PINDEX Insert(const PObject &key, PObject *obj)
Insert a new object into the dictionary.
virtual PObject * RemoveAt(PINDEX index)
Remove an object at the specified index.
static bool Intersection(const PAbstractSet &set1, const PAbstractSet &set2, PAbstractSet *intersection=NULL)
Calculate intersection of sets.
virtual PINDEX InsertAt(PINDEX index, PObject *obj)
Insert a new object at the specified index.
PHashTableInfo(PHashTableList const *buffer, PINDEX length, PBoolean dynamic=true)
Definition: dict.h:192
iterator()
Definition: dict.h:664
virtual PObject * GetAt(PINDEX index) const
Get the object at the specified index position.
PHashTableElement * GetElementAt(PINDEX index)
const_iterator operator--()
Definition: dict.h:691
iterator(dict_type *dict, const K &key)
Definition: dict.h:1193
void Exclude(const T *obj)
Remove the object from the set.
Definition: dict.h:568
PSet & operator-=(const T &obj)
Remove the objects value from the set.
Definition: dict.h:579
static Comparison Compare2(T v1, T v2)
Compare two types, returning Comparison type.
Definition: object.h:2258
Definition: dict.h:1215
PINLINE PKey(value_type newKey=0)
Create a new key for ordinal index values.
Definition: dict.h:58
PSet(PBoolean initialDeleteObjects=false)
Create a new, empty, dictionary.
Definition: dict.h:522
PTRACE_THROTTLE(m_throttlePoorHashFunction, 1)
virtual void DestroyContents()
Destroy the container contents.
const_iterator find(const K &k) const
Definition: dict.h:1238
virtual PObject & GetRefAt(const PObject &key) const
Get the object at the specified key position.
Definition: dict.h:164
Definition: dict.h:658
virtual const PObject & AbstractGetKeyAt(PINDEX index) const
Get the key in the hash table at the ordinal index position.
PINLINE PKey & operator-=(value_type minus)
Operator to subtract from the ordinal.
Definition: dict.h:139
D & operator[](const K &key)
Definition: dict.h:1024
PHashTableElement * NextElement(PHashTableElement *element) const
virtual PBoolean SetAt(const K &key, D *obj)
Add a new object to the collection.
Definition: dict.h:1064
iterator_base()
Definition: dict.h:1137
const T & operator*() const
Definition: dict.h:696
const K & GetKeyAt(PINDEX index) const
Get the key in the dictionary at the ordinal index position.
Definition: dict.h:1092
const_iterator(const dict_type *dict)
Definition: dict.h:1217
#define P_DEPRECATED
Definition: object.h:141
virtual PObject * RemoveAt(PINDEX index)
Remove an object at the specified index.
virtual PBoolean SetDataAt(PINDEX index, PINDEX ordinal)
Set the data at the specified ordinal index position in the dictionary.
Definition: dict.h:1355
virtual PObject * Clone() const
Create a duplicate of the PKey.
Definition: dict.h:71
const_iterator(iterator it)
Definition: dict.h:1222
CK & first
Definition: dict.h:1183
void erase(const iterator &it)
Definition: dict.h:705
PINLINE value_type operator++()
Operator to pre-increment the ordinal.
Definition: dict.h:119
virtual D * RemoveAt(const K &key)
Remove an object at the specified key.
Definition: dict.h:1049
PHashTableInfo * table
Definition: dict.h:645
virtual PBoolean Remove(const PObject *obj)
Remove the object from the collection.
Definition: dict.h:682
PINLINE PAbstractSet()
Create a new, empty, set.
PINDEX GetDataAt(PINDEX index) const
Get the data in the dictionary at the ordinal index position.
Definition: dict.h:1410
PContainerReference * reference
Definition: contain.h:288
virtual PObject & AbstractGetDataAt(PINDEX index) const
Get the data in the hash table at the ordinal index position.
iterator begin()
Definition: dict.h:1210
const_iterator operator++()
Definition: dict.h:1224
This template class maps the PAbstractDictionary to a specific key type and a POrdinalKey data type...
Definition: dict.h:1297
PHashTableElement * element
Definition: dict.h:646
Ultimate parent class for all objects in the class library.
Definition: object.h:2204
A collection is a container that collects together descendents of the PObject class.
Definition: contain.h:392
virtual PObject * Clone() const
Make a complete duplicate of the dictionary.
Definition: dict.h:1005
D data_type
Definition: dict.h:984
PDictionary()
Create a new, empty, dictionary.
Definition: dict.h:995
const_iterator(PHashTableInfo *t)
Definition: dict.h:684
#define PTRACING
Definition: object.h:482
PObject * m_data
Definition: dict.h:155
PArray< K > GetKeys() const
Get an array containing all the keys for the dictionary.
Definition: dict.h:1117
PHashTableInfo * hashTable
Definition: dict.h:322
#define PNEW
Macro for overriding system default new operator.
Definition: object.h:1896
Definition: dict.h:1129
PHashTableElement * m_prev
Definition: dict.h:157
const pair * operator->() const
Definition: dict.h:1204