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

#include <sortdict.h>

Inheritance diagram for SIntDict< T >:
LetterToIndexMap< T >

Classes

class  Iterator
 
class  IteratorDict
 

Public Member Functions

 SIntDict (int size=17)
 
virtual ~SIntDict ()
 
void append (int key, const T *d)
 
void prepend (int key, const T *d)
 
bool remove (int key)
 
void sort ()
 
void inSort (int key, const T *d)
 
void setAutoDelete (bool val)
 
T * find (int key)
 
T * operator[] (int key) const
 
T * at (uint i)
 
virtual int compareValues (const T *item1, const T *item2) const
 
void clear ()
 
int count ()
 

Private Attributes

SIntList< T > * m_list
 
QIntDict< T > * m_dict
 
int m_sizeIndex
 

Friends

class Iterator
 
class IteratorDict
 

Detailed Description

template<class T>
class SIntDict< T >

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

Definition at line 74 of file sortdict.h.

Constructor & Destructor Documentation

template<class T>
SIntDict< T >::SIntDict ( int  size = 17)
inline

Create an ordered dictionary.

Parameters
sizeThe size of the dictionary. Should be a prime number for best distribution of elements.

Definition at line 457 of file sortdict.h.

457  : m_sizeIndex(0)
458  {
459  m_list = new SIntList<T>(this);
460 #if AUTORESIZE
463 #else
464  m_dict = new QIntDict<T>(size);
465 #endif
466  }
SIntList< T > * m_list
Definition: sortdict.h:448
int m_sizeIndex
Definition: sortdict.h:450
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
const uint SDict_primes[]
Definition: sortdict.h:29
unsigned uint
Definition: qglobal.h:351
QIntDict< T > * m_dict
Definition: sortdict.h:449
template<class T>
virtual SIntDict< T >::~SIntDict ( )
inlinevirtual

Destroys the dictionary

Definition at line 469 of file sortdict.h.

470  {
471  delete m_list;
472  delete m_dict;
473  }
SIntList< T > * m_list
Definition: sortdict.h:448
QIntDict< T > * m_dict
Definition: sortdict.h:449

Member Function Documentation

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

Appends a compound 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 481 of file sortdict.h.

482  {
483  m_list->append(d);
484  m_dict->insert(key,d);
485 #if AUTORESIZE
487  {
489  }
490 #endif
491  }
SIntList< T > * m_list
Definition: sortdict.h:448
int m_sizeIndex
Definition: sortdict.h:450
void insert(long k, const type *d)
Definition: qintdict.h:57
def key(type, name=None)
Definition: graph.py:13
const uint SDict_primes[]
Definition: sortdict.h:29
uint size() const
Definition: qintdict.h:55
void resize(uint n)
Definition: qintdict.h:68
QIntDict< T > * m_dict
Definition: sortdict.h:449
template<class T>
T* SIntDict< T >::at ( uint  i)
inline

Returns the item at position i in the sorted dictionary

Definition at line 567 of file sortdict.h.

568  {
569  return m_list->at(i);
570  }
SIntList< T > * m_list
Definition: sortdict.h:448
template<class T>
void SIntDict< T >::clear ( )
inline

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

See also
setAutoDelete

Definition at line 585 of file sortdict.h.

586  {
587  m_list->clear();
588  m_dict->clear();
589  }
SIntList< T > * m_list
Definition: sortdict.h:448
void clear()
Definition: qintdict.h:67
QIntDict< T > * m_dict
Definition: sortdict.h:449
template<class T>
virtual int SIntDict< 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 UsedIndexLetters, MemberGroupSDict, LetterToIndexMap< T >, and LetterToIndexMap< SearchIndexList >.

Definition at line 576 of file sortdict.h.

577  {
578  return item1!=item2;
579  }
template<class T>
int SIntDict< T >::count ( )
inline

Returns the number of items stored in the dictionary

Definition at line 593 of file sortdict.h.

594  {
595  return m_list->count();
596  }
SIntList< T > * m_list
Definition: sortdict.h:448
template<class T>
T* SIntDict< T >::find ( int  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 555 of file sortdict.h.

556  {
557  return m_dict->find(key);
558  }
def key(type, name=None)
Definition: graph.py:13
QIntDict< T > * m_dict
Definition: sortdict.h:449
type * find(long k) const
Definition: qintdict.h:63
template<class T>
void SIntDict< T >::inSort ( int  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 532 of file sortdict.h.

533  {
534  m_list->inSort(d);
535  m_dict->insert(key,d);
536 #if AUTORESIZE
538  {
540  }
541 #endif
542  }
SIntList< T > * m_list
Definition: sortdict.h:448
int m_sizeIndex
Definition: sortdict.h:450
void insert(long k, const type *d)
Definition: qintdict.h:57
def key(type, name=None)
Definition: graph.py:13
const uint SDict_primes[]
Definition: sortdict.h:29
uint size() const
Definition: qintdict.h:55
void resize(uint n)
Definition: qintdict.h:68
QIntDict< T > * m_dict
Definition: sortdict.h:449
template<class T>
T* SIntDict< T >::operator[] ( int  key) const
inline

Equavalent to find().

Definition at line 561 of file sortdict.h.

562  {
563  return m_dict->find(key);
564  }
def key(type, name=None)
Definition: graph.py:13
QIntDict< T > * m_dict
Definition: sortdict.h:449
type * find(long k) const
Definition: qintdict.h:63
template<class T>
void SIntDict< T >::prepend ( int  key,
const T *  d 
)
inline

Prepend a compound 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 499 of file sortdict.h.

500  {
501  m_list->prepend(d);
502  m_dict->insert(key,d);
503 #if AUTORESIZE
505  {
507  }
508 #endif
509  }
SIntList< T > * m_list
Definition: sortdict.h:448
int m_sizeIndex
Definition: sortdict.h:450
void insert(long k, const type *d)
Definition: qintdict.h:57
def key(type, name=None)
Definition: graph.py:13
const uint SDict_primes[]
Definition: sortdict.h:29
uint size() const
Definition: qintdict.h:55
void resize(uint n)
Definition: qintdict.h:68
QIntDict< T > * m_dict
Definition: sortdict.h:449
template<class T>
bool SIntDict< T >::remove ( int  key)
inline

Remove an item from the dictionary

Definition at line 512 of file sortdict.h.

513  {
514  T *item = m_dict->take(key);
515  return item ? m_list->remove(item) : FALSE;
516  }
SIntList< T > * m_list
Definition: sortdict.h:448
const bool FALSE
Definition: qglobal.h:370
type * take(long k)
Definition: qintdict.h:62
def key(type, name=None)
Definition: graph.py:13
QIntDict< T > * m_dict
Definition: sortdict.h:449
template<class T>
void SIntDict< T >::setAutoDelete ( bool  val)
inline

Indicates whether or not the dictionary owns its elements

Definition at line 545 of file sortdict.h.

546  {
547  m_list->setAutoDelete(val);
548  }
SIntList< T > * m_list
Definition: sortdict.h:448
template<class T>
void SIntDict< 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 522 of file sortdict.h.

523  {
524  m_list->sort();
525  }
SIntList< T > * m_list
Definition: sortdict.h:448

Friends And Related Function Documentation

template<class T>
friend class Iterator
friend

Definition at line 598 of file sortdict.h.

template<class T>
friend class IteratorDict
friend

Definition at line 662 of file sortdict.h.

Member Data Documentation

template<class T>
QIntDict<T>* SIntDict< T >::m_dict
private

Definition at line 449 of file sortdict.h.

template<class T>
SIntList<T>* SIntDict< T >::m_list
private

Definition at line 448 of file sortdict.h.

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

Definition at line 450 of file sortdict.h.


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