2 # ifndef TPL_DYNLHASH_H
3 # define TPL_DYNLHASH_H
5 # include <tpl_lhash.H>
35 template <
typename Key,
typename Record,
class Cmp = Aleph::equal_to<Key>>
44 DLBucket(
const Key & key,
const Record & _record)
48 DLBucket(
const Key & key, Record && _record)
51 DLBucket(Key && key,
const Record & _record)
54 DLBucket(Key && key, Record && _record)
56 record(std::move(_record)) { }
59 static DLBucket * record_to_bucket(Record * rec)
61 DLBucket * ret_val = 0;
62 size_t offset = (size_t) &ret_val->record;
63 return (DLBucket*) (((size_t) rec) - offset);
75 : table(_table), key(_key)
77 Record * record = table.search(key);
78 bucket = record not_eq NULL ? record_to_bucket(record) : NULL;
81 operator const Record & ()
const
82 throw(std::exception, std::invalid_argument)
85 throw std::invalid_argument(
"access to unexisting entry");
87 return bucket->record;
90 DLProxy& operator = (
const Record& record)
91 throw(std::exception, std::bad_alloc)
95 bucket->record = record;
99 bucket =
new DLBucket (key, record);
100 table.LhashTable<Key>::insert(bucket);
104 DLProxy& operator = (
const DLProxy& proxy)
105 throw(std::exception, std::bad_alloc, std::invalid_argument)
107 if (proxy.bucket == NULL)
108 throw std::invalid_argument(
"access to unexisting entry");
112 bucket->record = proxy.bucket->record;
116 bucket =
new DLBucket (key, proxy.bucket->record);
117 table.LhashTable<Key>::insert(bucket);
136 throw (std::exception, std::bad_alloc) :
LhashTable<Key>(hash_fct, len)
147 DLBucket * Bucket = (DLBucket*) it.get_curr();
148 insert(Bucket->get_key(), Bucket->record);
184 Record * __insert(DLBucket * bucket)
187 return &bucket->record;
195 Record *
insert(
const Key & key,
const Record & record)
196 throw (std::exception, std::bad_alloc)
198 return __insert(
new DLBucket (key, record));
201 Record *
insert(
const Key & key, Record && record = Record())
202 throw (std::exception, std::bad_alloc)
204 return __insert(
new DLBucket (key, std::move(record)));
207 Record *
insert(Key && key,
const Record & record)
208 throw (std::exception, std::bad_alloc)
210 return __insert(
new DLBucket (std::move(key), record));
213 Record *
insert(Key && key, Record && record)
214 throw (std::exception, std::bad_alloc)
216 return __insert(
new DLBucket (std::move(key), std::move(record)));
225 return bucket != NULL ? &bucket->record : NULL;
230 void remove(Record * record)
232 DLBucket* bucket = record_to_bucket(record);
237 DLProxy operator [] (
const Key& key)
const
238 throw(std::exception, std::invalid_argument)
240 return DLProxy ( const_cast<DynLhashTable&>(*
this), key);
243 DLProxy operator [] (
const Key& key)
244 throw(std::exception, std::bad_alloc, std::invalid_argument)
246 return DLProxy (*
this, key);
252 # endif // TPL_DYNLHASH_H
Record * search(const Key &key)
Definition: tpl_dynLhash.H:222
Bucket * insert(Bucket *bucket)
Definition: tpl_lhash.H:160
void empty()
Vacía la tabla hash; libera memoria de todas las cubetas.
Definition: tpl_lhash.H:123
DynLhashTable(Hash_Fct hash_fct, const size_t &len=DefaultPrime)
Definition: tpl_dynLhash.H:135
Record * insert(const Key &key, const Record &record)
Definition: tpl_dynLhash.H:195
Definition: tpl_lhash.H:531
Definition: tpl_dynLhash.H:36
Definition: tpl_lhash.H:472
Bucket * remove(Bucket *bucket)
Definition: tpl_lhash.H:209
DynLhashTable< Key, Record >::Hash_Fct Hash_Fct
El tipo de función hash.
Definition: tpl_dynLhash.H:125