Classes | Public Member Functions | Private Attributes | Friends | List of all members
SDict< T > Class Template Reference

#include <sortdict.h>

Classes

class  Iterator
 
class  IteratorDict
 

Public Member Functions

 SDict (int size=17, bool caseSensitive=TRUE)
 
virtual ~SDict ()
 
void append (const char *key, const T *d)
 
void prepend (const char *key, const T *d)
 
bool remove (const char *key)
 
T * take (const char *key)
 
void sort ()
 
void inSort (const char *key, const T *d)
 
void insertAt (int i, const char *key, const T *d)
 
void setAutoDelete (bool val)
 
T * find (const char *key)
 
T * find (const QCString &key)
 
T * find (const QString &key)
 
int findAt (const QCString &key)
 
T * operator[] (const char *key) const
 
T * at (uint i)
 
virtual int compareValues (const T *item1, const T *item2) const
 
void clear ()
 
int count () const
 

Private Attributes

SList< T > * m_list
 
QDict< T > * m_dict
 
int m_sizeIndex
 

Friends

class Iterator
 
class IteratorDict
 

Detailed Description

template<class T>
class SDict< T >

Ordered dictionary of elements of type T. Internally uses a QList<T> and a QDict<T>.

Definition at line 73 of file sortdict.h.

Constructor & Destructor Documentation

template<class T>
SDict< T >::SDict ( int  size = 17,
bool  caseSensitive = TRUE 
)
inline

Create an ordered dictionary.

Parameters
sizeThe size of the dictionary. Should be a prime number for best distribution of elements.
caseSensitiveindicated whether the keys should be sorted in a case sensitive way.

Definition at line 111 of file sortdict.h.

111  : m_sizeIndex(0)
112  {
113  m_list = new SList<T>(this);
114 #if AUTORESIZE
116  m_dict = new QDict<T>(SDict_primes[m_sizeIndex],caseSensitive);
117 #else
118  m_dict = new QDict<T>(size,caseSensitive);
119 #endif
120  }
SList< T > * m_list
Definition: sortdict.h:100
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
QDict< T > * m_dict
Definition: sortdict.h:101
const uint SDict_primes[]
Definition: sortdict.h:29
Definition: sortdict.h:80
unsigned uint
Definition: qglobal.h:351
int m_sizeIndex
Definition: sortdict.h:102
template<class T>
virtual SDict< T >::~SDict ( )
inlinevirtual

Destroys the dictionary

Definition at line 123 of file sortdict.h.

124  {
125  delete m_list;
126  delete m_dict;
127  }
SList< T > * m_list
Definition: sortdict.h:100
QDict< T > * m_dict
Definition: sortdict.h:101

Member Function Documentation

template<class T>
void SDict< T >::append ( const char *  key,
const T *  d 
)
inline

Appends an element to the dictionary. The element is owned by the dictionary.

Parameters
keyThe unique key to use to quicky find the item later on.
dThe compound to add.
See also
find()

Definition at line 135 of file sortdict.h.

136  {
137  m_list->append(d);
138  m_dict->insert(key,d);
139 #if AUTORESIZE
140  if (m_dict->size()>SDict_primes[m_sizeIndex])
141  {
142  m_dict->resize(SDict_primes[++m_sizeIndex]);
143  }
144 #endif
145  }
SList< T > * m_list
Definition: sortdict.h:100
def key(type, name=None)
Definition: graph.py:13
QDict< T > * m_dict
Definition: sortdict.h:101
const uint SDict_primes[]
Definition: sortdict.h:29
int m_sizeIndex
Definition: sortdict.h:102
template<class T>
T* SDict< T >::at ( uint  i)
inline

Returns the item at position i in the sorted dictionary

Definition at line 258 of file sortdict.h.

259  {
260  return m_list->at(i);
261  }
SList< T > * m_list
Definition: sortdict.h:100
template<class T>
void SDict< T >::clear ( )
inline

Clears the dictionary. Will delete items if setAutoDelete() was set to TRUE.

See also
setAutoDelete

Definition at line 276 of file sortdict.h.

277  {
278  m_list->clear();
279  m_dict->clear();
280  }
SList< T > * m_list
Definition: sortdict.h:100
QDict< T > * m_dict
Definition: sortdict.h:101
template<class T>
virtual int SDict< T >::compareValues ( const T *  item1,
const T *  item2 
) const
inlinevirtual

Function that is used to compare two items when sorting. Overload this to properly sort items.

See also
inSort()

Reimplemented in NamespaceSDict, DirSDict, GroupSDict, SearchIndexList, FilePairDict, MemberSDict, MemberNameInfoSDict, PageSDict, ClassSDict, IndexFieldSDict, MemberNameSDict, SortedRefItems, and ExampleSDict.

Definition at line 267 of file sortdict.h.

268  {
269  return item1!=item2;
270  }
template<class T>
int SDict< T >::count ( ) const
inline

Returns the number of items stored in the dictionary

Definition at line 284 of file sortdict.h.

285  {
286  return m_list->count();
287  }
SList< T > * m_list
Definition: sortdict.h:100
template<class T>
T* SDict< T >::find ( const char *  key)
inline

Looks up a compound given its key.

Parameters
keyThe key to identify this element.
Returns
The requested compound or zero if it cannot be found.
See also
append()

Definition at line 232 of file sortdict.h.

233  {
234  return m_dict->find(key);
235  }
def key(type, name=None)
Definition: graph.py:13
QDict< T > * m_dict
Definition: sortdict.h:101
template<class T>
T* SDict< T >::find ( const QCString key)
inline

Definition at line 236 of file sortdict.h.

237  {
238  return m_dict->find(key);
239  }
QDict< T > * m_dict
Definition: sortdict.h:101
template<class T>
T* SDict< T >::find ( const QString key)
inline

Definition at line 240 of file sortdict.h.

241  {
242  return m_dict->find(key);
243  }
QDict< T > * m_dict
Definition: sortdict.h:101
template<class T>
int SDict< T >::findAt ( const QCString key)
inline

Definition at line 244 of file sortdict.h.

245  {
246  T *item = find(key);
247  if (item==0) return -1;
248  return m_list->find(item);
249  }
SList< T > * m_list
Definition: sortdict.h:100
T * find(const char *key)
Definition: sortdict.h:232
template<class T>
void SDict< T >::insertAt ( int  i,
const char *  key,
const T *  d 
)
inline

Definition at line 209 of file sortdict.h.

210  {
211  m_list->insert(i,d);
212  m_dict->insert(key,d);
213 #if AUTORESIZE
214  if (m_dict->size()>SDict_primes[m_sizeIndex])
215  {
216  m_dict->resize(SDict_primes[++m_sizeIndex]);
217  }
218 #endif
219  }
SList< T > * m_list
Definition: sortdict.h:100
def key(type, name=None)
Definition: graph.py:13
QDict< T > * m_dict
Definition: sortdict.h:101
const uint SDict_primes[]
Definition: sortdict.h:29
int m_sizeIndex
Definition: sortdict.h:102
template<class T>
void SDict< T >::inSort ( const char *  key,
const T *  d 
)
inline

Inserts a compound into the dictionary in a sorted way.

Parameters
keyThe unique key to use to quicky find the item later on.
dThe compound to add.
See also
find()

Definition at line 197 of file sortdict.h.

198  {
199  m_list->inSort(d);
200  m_dict->insert(key,d);
201 #if AUTORESIZE
202  if (m_dict->size()>SDict_primes[m_sizeIndex])
203  {
204  m_dict->resize(SDict_primes[++m_sizeIndex]);
205  }
206 #endif
207  }
SList< T > * m_list
Definition: sortdict.h:100
def key(type, name=None)
Definition: graph.py:13
QDict< T > * m_dict
Definition: sortdict.h:101
const uint SDict_primes[]
Definition: sortdict.h:29
int m_sizeIndex
Definition: sortdict.h:102
template<class T>
T* SDict< T >::operator[] ( const char *  key) const
inline

Equavalent to find().

Definition at line 252 of file sortdict.h.

253  {
254  return m_dict->find(key);
255  }
def key(type, name=None)
Definition: graph.py:13
QDict< T > * m_dict
Definition: sortdict.h:101
template<class T>
void SDict< T >::prepend ( const char *  key,
const T *  d 
)
inline

Prepends an element to the dictionary. The element is owned by the dictionary.

Parameters
keyThe unique key to use to quicky find the item later on.
dThe compound to add.
See also
find()

Definition at line 153 of file sortdict.h.

154  {
155  m_list->prepend(d);
156  m_dict->insert(key,d);
157 #if AUTORESIZE
158  if (m_dict->size()>SDict_primes[m_sizeIndex])
159  {
160  m_dict->resize(SDict_primes[++m_sizeIndex]);
161  }
162 #endif
163  }
SList< T > * m_list
Definition: sortdict.h:100
def key(type, name=None)
Definition: graph.py:13
QDict< T > * m_dict
Definition: sortdict.h:101
const uint SDict_primes[]
Definition: sortdict.h:29
int m_sizeIndex
Definition: sortdict.h:102
template<class T>
bool SDict< T >::remove ( const char *  key)
inline

Remove an item from the dictionary

Definition at line 166 of file sortdict.h.

167  {
168  T *item = m_dict->take(key);
169  return item ? m_list->remove(item) : FALSE;
170  }
SList< T > * m_list
Definition: sortdict.h:100
const bool FALSE
Definition: qglobal.h:370
def key(type, name=None)
Definition: graph.py:13
QDict< T > * m_dict
Definition: sortdict.h:101
template<class T>
void SDict< T >::setAutoDelete ( bool  val)
inline

Indicates whether or not the dictionary owns its elements

Definition at line 222 of file sortdict.h.

223  {
224  m_list->setAutoDelete(val);
225  }
SList< T > * m_list
Definition: sortdict.h:100
template<class T>
void SDict< T >::sort ( )
inline

Sorts the members of the dictionary. First appending a number of members and then sorting them is faster (O(NlogN) than using inSort() for each member (O(N^2)).

Definition at line 188 of file sortdict.h.

189  {
190  m_list->sort();
191  }
SList< T > * m_list
Definition: sortdict.h:100
template<class T>
T* SDict< T >::take ( const char *  key)
inline

Take an item out of the dictionary without deleting it

Definition at line 173 of file sortdict.h.

174  {
175  T *item = m_dict->take(key);
176  if (item)
177  {
178  int i = m_list->find(item);
179  m_list->take(i);
180  }
181  return item;
182  }
SList< T > * m_list
Definition: sortdict.h:100
def key(type, name=None)
Definition: graph.py:13
QDict< T > * m_dict
Definition: sortdict.h:101

Friends And Related Function Documentation

template<class T>
friend class Iterator
friend

Definition at line 289 of file sortdict.h.

template<class T>
friend class IteratorDict
friend

Definition at line 353 of file sortdict.h.

Member Data Documentation

template<class T>
QDict<T>* SDict< T >::m_dict
private

Definition at line 101 of file sortdict.h.

template<class T>
SList<T>* SDict< T >::m_list
private

Definition at line 100 of file sortdict.h.

template<class T>
int SDict< T >::m_sizeIndex
private

Definition at line 102 of file sortdict.h.


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