1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

remove my_hash_const_element(), use Hash_set in C++ code

This commit is contained in:
Sergei Golubchik
2017-03-10 19:41:35 +01:00
parent 63798a6ea8
commit 76a262cdf8
4 changed files with 36 additions and 52 deletions

View File

@@ -32,10 +32,12 @@ public:
Constructs an empty hash. Does not allocate memory, it is done upon
the first insert. Thus does not cause or return errors.
*/
Hash_set(uchar *(*K)(const T *, size_t *, my_bool))
Hash_set(uchar *(*K)(const T *, size_t *, my_bool),
CHARSET_INFO *cs= &my_charset_bin)
{
my_hash_clear(&m_hash);
m_hash.get_key= (my_hash_get_key)K;
m_hash.charset= cs;
}
/**
Destroy the hash by freeing the buckets table. Does
@@ -56,7 +58,7 @@ public:
*/
bool insert(T *value)
{
my_hash_init_opt(&m_hash, &my_charset_bin, START_SIZE, 0, 0,
my_hash_init_opt(&m_hash, m_hash.charset, START_SIZE, 0, 0,
m_hash.get_key, 0, MYF(0));
size_t key_len;
uchar *v= reinterpret_cast<uchar *>(value);
@@ -65,6 +67,10 @@ public:
return my_hash_insert(&m_hash, v);
return FALSE;
}
bool remove(T *value)
{
return my_hash_delete(&m_hash, reinterpret_cast<uchar*>(value));
}
T *find(const void *key, size_t klen) const
{
return (T*)my_hash_search(&m_hash, reinterpret_cast<const uchar *>(key), klen);
@@ -73,6 +79,10 @@ public:
bool is_empty() const { return m_hash.records == 0; }
/** Returns the number of unique elements. */
size_t size() const { return static_cast<size_t>(m_hash.records); }
const T* at(size_t i) const
{
return reinterpret_cast<T*>(my_hash_element(const_cast<HASH*>(&m_hash), i));
}
/** An iterator over hash elements. Is not insert-stable. */
class Iterator
{