Commit 76a262cd authored by Sergei Golubchik's avatar Sergei Golubchik

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

parent 63798a6e
...@@ -74,7 +74,6 @@ my_bool my_hash_init2(HASH *hash, uint growth_size, CHARSET_INFO *charset, ...@@ -74,7 +74,6 @@ my_bool my_hash_init2(HASH *hash, uint growth_size, CHARSET_INFO *charset,
void my_hash_free(HASH *tree); void my_hash_free(HASH *tree);
void my_hash_reset(HASH *hash); void my_hash_reset(HASH *hash);
uchar *my_hash_element(HASH *hash, ulong idx); uchar *my_hash_element(HASH *hash, ulong idx);
const uchar *my_hash_const_element(const HASH *hash, ulong idx);
uchar *my_hash_search(const HASH *info, const uchar *key, size_t length); uchar *my_hash_search(const HASH *info, const uchar *key, size_t length);
uchar *my_hash_search_using_hash_value(const HASH *info, uchar *my_hash_search_using_hash_value(const HASH *info,
my_hash_value_type hash_value, my_hash_value_type hash_value,
......
...@@ -756,14 +756,6 @@ uchar *my_hash_element(HASH *hash, ulong idx) ...@@ -756,14 +756,6 @@ uchar *my_hash_element(HASH *hash, ulong idx)
} }
const uchar *my_hash_const_element(const HASH *hash, ulong idx)
{
if (idx < hash->records)
return dynamic_element(&hash->array,idx,const HASH_LINK*)->data;
return 0;
}
/* /*
Replace old row with new row. This should only be used when key Replace old row with new row. This should only be used when key
isn't changed isn't changed
......
...@@ -32,10 +32,12 @@ class Hash_set ...@@ -32,10 +32,12 @@ class Hash_set
Constructs an empty hash. Does not allocate memory, it is done upon Constructs an empty hash. Does not allocate memory, it is done upon
the first insert. Thus does not cause or return errors. 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); my_hash_clear(&m_hash);
m_hash.get_key= (my_hash_get_key)K; m_hash.get_key= (my_hash_get_key)K;
m_hash.charset= cs;
} }
/** /**
Destroy the hash by freeing the buckets table. Does Destroy the hash by freeing the buckets table. Does
...@@ -56,7 +58,7 @@ class Hash_set ...@@ -56,7 +58,7 @@ class Hash_set
*/ */
bool insert(T *value) 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)); m_hash.get_key, 0, MYF(0));
size_t key_len; size_t key_len;
uchar *v= reinterpret_cast<uchar *>(value); uchar *v= reinterpret_cast<uchar *>(value);
...@@ -65,6 +67,10 @@ class Hash_set ...@@ -65,6 +67,10 @@ class Hash_set
return my_hash_insert(&m_hash, v); return my_hash_insert(&m_hash, v);
return FALSE; 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 T *find(const void *key, size_t klen) const
{ {
return (T*)my_hash_search(&m_hash, reinterpret_cast<const uchar *>(key), klen); return (T*)my_hash_search(&m_hash, reinterpret_cast<const uchar *>(key), klen);
...@@ -73,6 +79,10 @@ class Hash_set ...@@ -73,6 +79,10 @@ class Hash_set
bool is_empty() const { return m_hash.records == 0; } bool is_empty() const { return m_hash.records == 0; }
/** Returns the number of unique elements. */ /** Returns the number of unique elements. */
size_t size() const { return static_cast<size_t>(m_hash.records); } 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. */ /** An iterator over hash elements. Is not insert-stable. */
class Iterator class Iterator
{ {
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment