1 #include "dynamic_ids.h"
3 int cmp_string(
const void *id1,
const void *id2)
5 return strcmp((
char *) id1, (
char *) id2);
8 int cmp_ulong(
const void *id1,
const void *id2)
10 return ((*(ulong *) id1) - (* (ulong *)id2));
13 Dynamic_ids::Dynamic_ids(
size_t param_size):
size(param_size)
15 my_init_dynamic_array(&dynamic_ids,
size, 16, 16);
18 Dynamic_ids::~Dynamic_ids()
20 delete_dynamic(&dynamic_ids);
23 bool Server_ids::do_unpack_dynamic_ids(
char *param_dynamic_ids)
25 char *token= NULL, *last= NULL;
28 DBUG_ENTER(
"Server_ids::unpack_dynamic_ids");
30 token= strtok_r((
char *)const_cast<const char*>(param_dynamic_ids),
36 num_items= atoi(token);
37 for (uint
i=0;
i < num_items;
i++)
39 token= strtok_r(NULL,
" ", &last);
44 ulong val= atol(token);
45 insert_dynamic(&dynamic_ids, (uchar *) &val);
51 bool Server_ids::do_pack_dynamic_ids(
String *buffer)
53 DBUG_ENTER(
"Server_ids::pack_dynamic_ids");
55 if (buffer->set_int(dynamic_ids.elements, FALSE, &my_charset_bin))
59 i < dynamic_ids.elements;
i++)
62 get_dynamic(&dynamic_ids, (uchar*) &s_id,
i);
63 if (buffer->append(
" ") ||
64 buffer->append_ulonglong(s_id))
71 bool Server_ids::do_search_id(
const void *
id)
73 return (bsearch((ulong *)
id, dynamic_ids.buffer,
74 dynamic_ids.elements,
size,
75 (int (*) (
const void*,
const void*))
80 bool Database_ids::do_unpack_dynamic_ids(
char *param_dynamic_ids)
82 char *token= NULL, *last= NULL;
85 DBUG_ENTER(
"Server_ids::unpack_dynamic_ids");
87 token= strtok_r((
char *)const_cast<const char*>(param_dynamic_ids),
93 num_items= atoi(token);
94 for (uint
i=0;
i < num_items;
i++)
96 token= strtok_r(NULL,
" ", &last);
101 size_t size= strlen(token);
102 if (token[size - 1] ==
'\n')
109 token[size -1]=
'\0';
111 insert_dynamic(&dynamic_ids, (uchar *) token);
117 bool Database_ids::do_pack_dynamic_ids(
String *buffer)
121 DBUG_ENTER(
"Server_ids::pack_dynamic_ids");
123 if (buffer->set_int(dynamic_ids.elements, FALSE, &my_charset_bin))
127 i < dynamic_ids.elements;
i++)
129 get_dynamic(&dynamic_ids, (uchar*) token,
i);
130 if (buffer->append(
" ") ||
131 buffer->append(token))
138 bool Database_ids::do_search_id(
const void *
id)
140 return (bsearch((
const char *)
id, dynamic_ids.buffer,
141 dynamic_ids.elements,
size,
142 (int (*) (
const void*,
const void*))
143 cmp_string) != NULL);