diff options
author | Klaus Schmidinger <vdr@tvdr.de> | 2005-05-28 13:17:20 +0200 |
---|---|---|
committer | Klaus Schmidinger <vdr@tvdr.de> | 2005-05-28 13:17:20 +0200 |
commit | 7701acd968c91de94c1d0ae184a0f746c4ae5844 (patch) | |
tree | c66f7457c6dfd66eca823855a2f560d053d6d827 /tools.c | |
parent | b4cbb84489020d0fa3e45fbff60cf1ce43ea6a1b (diff) | |
download | vdr-7701acd968c91de94c1d0ae184a0f746c4ae5844.tar.gz vdr-7701acd968c91de94c1d0ae184a0f746c4ae5844.tar.bz2 |
Now using hash tables to speed up cSchedule::GetEvent()
Diffstat (limited to 'tools.c')
-rw-r--r-- | tools.c | 54 |
1 files changed, 53 insertions, 1 deletions
@@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: tools.c 1.93 2005/05/26 11:40:14 kls Exp $ + * $Id: tools.c 1.94 2005/05/28 11:46:44 kls Exp $ */ #include "tools.h" @@ -1060,3 +1060,55 @@ void cListBase::Sort(void) } } +// --- cHashBase ------------------------------------------------------------- + +cHashBase::cHashBase(int Size) +{ + size = Size; + hashTable = (cList<cHashObject>**)calloc(size, sizeof(cList<cHashObject>*)); +} + +cHashBase::~cHashBase(void) +{ + for (int i = 0; i < size; i++) + delete hashTable[i]; + free(hashTable); +} + +void cHashBase::Add(cListObject *Object, int Id) +{ + int hash = hashfn(Id); + if (!hashTable[hash]) + hashTable[hash] = new cList<cHashObject>; + hashTable[hash]->Add(new cHashObject(Object, Id)); +} + +void cHashBase::Del(cListObject *Object, int Id) +{ + cList<cHashObject> *list = hashTable[hashfn(Id)]; + if (list) { + for (cHashObject *hob = list->First(); hob; hob = list->Next(hob)) { + if (hob->object == Object) { + list->Del(hob); + break; + } + } + } +} + +cListObject *cHashBase::Get(int Id) const +{ + cList<cHashObject> *list = hashTable[hashfn(Id)]; + if (list) { + for (cHashObject *hob = list->First(); hob; hob = list->Next(hob)) { + if (hob->id == Id) + return hob->object; + } + } + return NULL; +} + +cList<cHashObject> *cHashBase::GetList(int Id) const +{ + return hashTable[hashfn(Id)]; +} |