Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
7fba8e51
Commit
7fba8e51
authored
Oct 18, 2013
by
Sergei Golubchik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
find() method for Hash_set<>.
Move key function from template parameter to the constructor
parent
3098b6cf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
11 deletions
+16
-11
sql/sql_base.cc
sql/sql_base.cc
+3
-4
sql/sql_hset.h
sql/sql_hset.h
+13
-7
No files found.
sql/sql_base.cc
View file @
7fba8e51
...
@@ -4542,10 +4542,9 @@ open_and_process_table(THD *thd, LEX *lex, TABLE_LIST *tables,
...
@@ -4542,10 +4542,9 @@ open_and_process_table(THD *thd, LEX *lex, TABLE_LIST *tables,
DBUG_RETURN
(
error
);
DBUG_RETURN
(
error
);
}
}
extern
"C"
uchar
*
schema_set_get_key
(
const
uchar
*
record
,
size_t
*
length
,
extern
"C"
uchar
*
schema_set_get_key
(
const
TABLE_LIST
*
table
,
size_t
*
length
,
my_bool
not_used
__attribute__
((
unused
)))
my_bool
not_used
__attribute__
((
unused
)))
{
{
TABLE_LIST
*
table
=
(
TABLE_LIST
*
)
record
;
*
length
=
table
->
db_length
;
*
length
=
table
->
db_length
;
return
(
uchar
*
)
table
->
db
;
return
(
uchar
*
)
table
->
db
;
}
}
...
@@ -4586,7 +4585,7 @@ lock_table_names(THD *thd,
...
@@ -4586,7 +4585,7 @@ lock_table_names(THD *thd,
MDL_request_list
mdl_requests
;
MDL_request_list
mdl_requests
;
TABLE_LIST
*
table
;
TABLE_LIST
*
table
;
MDL_request
global_request
;
MDL_request
global_request
;
Hash_set
<
TABLE_LIST
,
schema_set_get_key
>
schema_set
;
Hash_set
<
TABLE_LIST
>
schema_set
(
schema_set_get_key
)
;
ulong
org_lock_wait_timeout
=
lock_wait_timeout
;
ulong
org_lock_wait_timeout
=
lock_wait_timeout
;
/* Check if we are using CREATE TABLE ... IF NOT EXISTS */
/* Check if we are using CREATE TABLE ... IF NOT EXISTS */
bool
create_table
;
bool
create_table
;
...
@@ -4625,7 +4624,7 @@ lock_table_names(THD *thd,
...
@@ -4625,7 +4624,7 @@ lock_table_names(THD *thd,
Scoped locks: Take intention exclusive locks on all involved
Scoped locks: Take intention exclusive locks on all involved
schemas.
schemas.
*/
*/
Hash_set
<
TABLE_LIST
,
schema_set_get_key
>::
Iterator
it
(
schema_set
);
Hash_set
<
TABLE_LIST
>::
Iterator
it
(
schema_set
);
while
((
table
=
it
++
))
while
((
table
=
it
++
))
{
{
MDL_request
*
schema_request
=
new
(
thd
->
mem_root
)
MDL_request
;
MDL_request
*
schema_request
=
new
(
thd
->
mem_root
)
MDL_request
;
...
...
sql/sql_hset.h
View file @
7fba8e51
...
@@ -23,19 +23,19 @@
...
@@ -23,19 +23,19 @@
A type-safe wrapper around mysys HASH.
A type-safe wrapper around mysys HASH.
*/
*/
template
<
typename
T
,
my_hash_get_key
K
>
template
<
typename
T
>
class
Hash_set
class
Hash_set
{
{
public:
public:
typedef
T
Value_type
;
enum
{
START_SIZE
=
8
};
enum
{
START_SIZE
=
8
};
/**
/**
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
()
Hash_set
(
uchar
*
(
*
K
)(
const
T
*
,
size_t
*
,
my_bool
)
)
{
{
my_hash_clear
(
&
m_hash
);
my_hash_clear
(
&
m_hash
);
m_hash
.
get_key
=
(
my_hash_get_key
)
K
;
}
}
/**
/**
Destroy the hash by freeing the buckets table. Does
Destroy the hash by freeing the buckets table. Does
...
@@ -56,13 +56,19 @@ class Hash_set
...
@@ -56,13 +56,19 @@ class Hash_set
*/
*/
bool
insert
(
T
*
value
)
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
;
size_t
key_len
;
const
uchar
*
key
=
K
(
reinterpret_cast
<
uchar
*>
(
value
),
&
key_len
,
FALSE
);
uchar
*
v
=
reinterpret_cast
<
uchar
*>
(
value
);
if
(
my_hash_search
(
&
m_hash
,
key
,
key_len
)
==
NULL
)
const
uchar
*
key
=
m_hash
.
get_key
(
v
,
&
key_len
,
FALSE
);
return
my_hash_insert
(
&
m_hash
,
reinterpret_cast
<
uchar
*>
(
value
));
if
(
find
(
key
,
key_len
)
==
NULL
)
return
my_hash_insert
(
&
m_hash
,
v
);
return
FALSE
;
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? */
/** Is this hash set empty? */
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. */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment