3
MediaTomb - http://www.mediatomb.cc/
5
dbb_hash.h - this file is part of MediaTomb.
7
Copyright (C) 2005 Gena Batyan <bgeradz@mediatomb.cc>,
8
Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>
10
Copyright (C) 2006-2007 Gena Batyan <bgeradz@mediatomb.cc>,
11
Sergey 'Jin' Bostandzhyan <jin@mediatomb.cc>,
12
Leonhard Wimmer <leo@mediatomb.cc>
14
MediaTomb is free software; you can redistribute it and/or modify
15
it under the terms of the GNU General Public License version 2
16
as published by the Free Software Foundation.
18
MediaTomb is distributed in the hope that it will be useful,
19
but WITHOUT ANY WARRANTY; without even the implied warranty of
20
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
GNU General Public License for more details.
23
You should have received a copy of the GNU General Public License
24
version 2 along with MediaTomb; if not, write to the Free Software
25
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
27
$Id: dbb_hash.h 1343 2007-06-04 14:06:56Z lww $
32
#ifndef __HASH_DBB_HASH_H__
33
#define __HASH_DBB_HASH_H__
35
#include "direct_hash_base.h"
37
template <typename KT, typename VT> struct dbb_hash_slot
43
/// \brief Direct hash with base type keys and base type values.
44
template <typename KT, typename VT>
45
class DBBHash : public DHashBase<KT, struct dbb_hash_slot<KT, VT> >
50
DBBHash(int capacity, KT emptyKey) : DHashBase<KT, struct dbb_hash_slot<KT, VT> >(capacity)
52
this->emptyKey = emptyKey;
57
virtual int hashCode(KT key)
59
return this->baseTypeHashCode((unsigned int)key);
61
virtual bool match(KT key, struct dbb_hash_slot<KT, VT> *slot)
63
return (key == slot->key);
65
virtual bool isEmptySlot(struct dbb_hash_slot<KT, VT> *slot)
67
return (slot->key == emptyKey);
76
for (int i = 0; i < this->capacity; i++)
77
this->data[i].key = emptyKey;
82
/* need to use deleted key
83
inline bool remove(KT key)
85
struct dbb_hash_slot<KT, VT> *slot;
86
if (! search(key, &slot))
94
inline void put(KT key, VT value)
96
struct dbb_hash_slot<KT, VT> *slot;
97
bool found = search(key, &slot);
105
inline void put(KT key, hash_slot_t destSlot, VT value)
107
struct dbb_hash_slot<KT, VT> *slot = (struct dbb_hash_slot<KT, VT> *)destSlot;
108
if (slot->key == emptyKey)
116
inline bool get(KT key, VT *value)
118
struct dbb_hash_slot<KT, VT> *slot;
119
bool found = search(key, &slot);
121
*value = slot->value;
124
bool get(KT key, hash_slot_t *destSlot, VT *value)
126
struct dbb_hash_slot<KT, VT> **slot = (struct dbb_hash_slot<KT, VT> **)destSlot;
127
bool found = search(key, slot);
129
*value = (*slot)->value;
132
inline bool exists(KT key)
134
struct dbb_hash_slot<KT, VT> *slot;
135
return search(key, &slot);
137
inline bool exists(KT key, hash_slot_t *destSlot)
139
return search(key, (struct dbb_hash_slot<KT, VT> **)destSlot);
143
#endif // __HASH_DBB_HASH_H__