summaryrefslogtreecommitdiff
path: root/sql/sql_hset.h
diff options
context:
space:
mode:
authorSergei Golubchik <sergii@pisem.net>2013-10-18 12:36:03 -0700
committerSergei Golubchik <sergii@pisem.net>2013-10-18 12:36:03 -0700
commit7fba8e5164038d6f18c93f2c34fb12ece0766c53 (patch)
tree327bc54930a4d4848458c7aacd04ad7dbe12981c /sql/sql_hset.h
parent3098b6cf5b8630956ccd854d41480eba81eeb77d (diff)
downloadmariadb-git-7fba8e5164038d6f18c93f2c34fb12ece0766c53.tar.gz
find() method for Hash_set<>.
Move key function from template parameter to the constructor
Diffstat (limited to 'sql/sql_hset.h')
-rw-r--r--sql/sql_hset.h20
1 files changed, 13 insertions, 7 deletions
diff --git a/sql/sql_hset.h b/sql/sql_hset.h
index f3a1467737f..dc3bd487ce5 100644
--- a/sql/sql_hset.h
+++ b/sql/sql_hset.h
@@ -23,19 +23,19 @@
A type-safe wrapper around mysys HASH.
*/
-template <typename T, my_hash_get_key K>
+template <typename T>
class Hash_set
{
public:
- typedef T Value_type;
enum { START_SIZE= 8 };
/**
Constructs an empty hash. Does not allocate memory, it is done upon
the first insert. Thus does not cause or return errors.
*/
- Hash_set()
+ Hash_set(uchar *(*K)(const T *, size_t *, my_bool))
{
my_hash_clear(&m_hash);
+ m_hash.get_key= (my_hash_get_key)K;
}
/**
Destroy the hash by freeing the buckets table. Does
@@ -56,13 +56,19 @@ public:
*/
bool insert(T *value)
{
- my_hash_init_opt(&m_hash, &my_charset_bin, START_SIZE, 0, 0, K, 0, MYF(0));
+ my_hash_init_opt(&m_hash, &my_charset_bin, START_SIZE, 0, 0,
+ m_hash.get_key, 0, MYF(0));
size_t key_len;
- const uchar *key= K(reinterpret_cast<uchar*>(value), &key_len, FALSE);
- if (my_hash_search(&m_hash, key, key_len) == NULL)
- return my_hash_insert(&m_hash, reinterpret_cast<uchar *>(value));
+ uchar *v= reinterpret_cast<uchar *>(value);
+ const uchar *key= m_hash.get_key(v, &key_len, FALSE);
+ if (find(key, key_len) == NULL)
+ return my_hash_insert(&m_hash, v);
return FALSE;
}
+ T *find(const void *key, size_t klen) const
+ {
+ return (T*)my_hash_search(&m_hash, reinterpret_cast<const uchar *>(key), klen);
+ }
/** Is this hash set empty? */
bool is_empty() const { return m_hash.records == 0; }
/** Returns the number of unique elements. */