Merge lp:~ivolucien/drizzle/trunk-bug-621861 into lp:~drizzle-trunk/drizzle/development
- trunk-bug-621861
- Merge into development
Proposed by
Mark Atwood
Status: | Merged |
---|---|
Approved by: | Mark Atwood |
Approved revision: | 2462 |
Merged at revision: | 2479 |
Proposed branch: | lp:~ivolucien/drizzle/trunk-bug-621861 |
Merge into: | lp:~drizzle-trunk/drizzle/development |
Diff against target: |
1499 lines (+657/-424) (has conflicts) 9 files modified
.bzrignore (+386/-0) drizzled/item/sum.cc (+7/-8) drizzled/item/sum.h (+2/-2) drizzled/tree.cc (+157/-334) drizzled/tree.h (+74/-53) drizzled/unique.cc (+8/-8) drizzled/unique.h (+4/-4) plugin/myisam/mi_write.cc (+12/-13) plugin/myisam/myisam_priv.h (+7/-2) Contents conflict in .bzrignore |
To merge this branch: | bzr merge lp:~ivolucien/drizzle/trunk-bug-621861 |
Related bugs: | |
Related blueprints: |
Remove dead code
(Medium)
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Mark Atwood | Pending | ||
Review via email:
|
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message

Olaf van der Spek (olafvdspek) wrote : | # |
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added file '.bzrignore' | |||
2 | --- .bzrignore 1970-01-01 00:00:00 +0000 | |||
3 | +++ .bzrignore 2011-12-24 17:41:25 +0000 | |||
4 | @@ -0,0 +1,386 @@ | |||
5 | 1 | *.bb | ||
6 | 2 | *.bbg | ||
7 | 3 | *.da | ||
8 | 4 | *.dirstamp | ||
9 | 5 | *.gcda | ||
10 | 6 | *.gcno | ||
11 | 7 | *.gmo | ||
12 | 8 | *.gz | ||
13 | 9 | *.la | ||
14 | 10 | *.linted | ||
15 | 11 | *.lo | ||
16 | 12 | *.orig | ||
17 | 13 | *.rej | ||
18 | 14 | *.reject | ||
19 | 15 | *.rpm | ||
20 | 16 | *replication.pb.* | ||
21 | 17 | *stamp-h | ||
22 | 18 | ./ChangeLog | ||
23 | 19 | .DS_Store | ||
24 | 20 | .deps | ||
25 | 21 | .libs | ||
26 | 22 | .plugin.ini.stamp | ||
27 | 23 | .plugin.scan | ||
28 | 24 | ChangeLog | ||
29 | 25 | DEPENDENCIES | ||
30 | 26 | INSTALL | ||
31 | 27 | Makefile | ||
32 | 28 | Makefile.in | ||
33 | 29 | TAGS | ||
34 | 30 | aclocal.m4 | ||
35 | 31 | authentication.gcno | ||
36 | 32 | autom4te.cache/ | ||
37 | 33 | cached_item.gcno | ||
38 | 34 | calendar.gcno | ||
39 | 35 | check_stack_overrun.gcno | ||
40 | 36 | client/Makefile.in | ||
41 | 37 | client/drizzle | ||
42 | 38 | client/drizzleadmin | ||
43 | 39 | client/drizzlebinlog | ||
44 | 40 | client/drizzlecheck | ||
45 | 41 | client/drizzledump | ||
46 | 42 | client/drizzleimport | ||
47 | 43 | client/drizzleslap | ||
48 | 44 | client/drizzletest | ||
49 | 45 | client/mysqlslap | ||
50 | 46 | comp_creator.gcno | ||
51 | 47 | compile | ||
52 | 48 | config.guess | ||
53 | 49 | config.h | ||
54 | 50 | config.h.gch | ||
55 | 51 | config.h.in | ||
56 | 52 | config.log | ||
57 | 53 | config.status | ||
58 | 54 | config.sub | ||
59 | 55 | config/bzr_revinfo | ||
60 | 56 | config/pandora-plugin.list | ||
61 | 57 | config/pandora_vc_revinfo | ||
62 | 58 | config/plugin-list.ac | ||
63 | 59 | config/plugin-list.am | ||
64 | 60 | config/plugin.ac | ||
65 | 61 | config/plugin.am | ||
66 | 62 | config/plugin.list | ||
67 | 63 | config/plugin.stamp | ||
68 | 64 | config/top.h | ||
69 | 65 | configure | ||
70 | 66 | configvar.gcno | ||
71 | 67 | current_session.gcno | ||
72 | 68 | dbug/Makefile.in | ||
73 | 69 | depcomp | ||
74 | 70 | docs | ||
75 | 71 | docs/doctrees | ||
76 | 72 | docs/html | ||
77 | 73 | docs/plugins/* | ||
78 | 74 | docs/plugins/list.rst | ||
79 | 75 | doxerr.log | ||
80 | 76 | drizzle-2010.01.1315.tar.gz | ||
81 | 77 | drizzle.pot | ||
82 | 78 | drizzled.gcno | ||
83 | 79 | drizzled/configmake.h | ||
84 | 80 | drizzled/drizzled | ||
85 | 81 | drizzled/drizzled_safe | ||
86 | 82 | drizzled/function_hash.h | ||
87 | 83 | drizzled/gen_lex_hash | ||
88 | 84 | drizzled/generated_probes.h | ||
89 | 85 | drizzled/lex_hash.h | ||
90 | 86 | drizzled/message/alter_table.pb.cc | ||
91 | 87 | drizzled/message/alter_table.pb.h | ||
92 | 88 | drizzled/message/binary_log.pb.cc | ||
93 | 89 | drizzled/message/binary_log.pb.h | ||
94 | 90 | drizzled/message/binlog_reader | ||
95 | 91 | drizzled/message/binlog_writer | ||
96 | 92 | drizzled/message/command_reader | ||
97 | 93 | drizzled/message/engine.pb.cc | ||
98 | 94 | drizzled/message/engine.pb.h | ||
99 | 95 | drizzled/message/event.pb.cc | ||
100 | 96 | drizzled/message/event.pb.h | ||
101 | 97 | drizzled/message/length | ||
102 | 98 | drizzled/message/replication.pb.cc | ||
103 | 99 | drizzled/message/replication.pb.h | ||
104 | 100 | drizzled/message/replication_event.pb.cc | ||
105 | 101 | drizzled/message/replication_event.pb.h | ||
106 | 102 | drizzled/message/replication_event_reader | ||
107 | 103 | drizzled/message/replication_event_writer | ||
108 | 104 | drizzled/message/resultset.pb.cc | ||
109 | 105 | drizzled/message/resultset.pb.h | ||
110 | 106 | drizzled/message/schema.pb.cc | ||
111 | 107 | drizzled/message/schema.pb.h | ||
112 | 108 | drizzled/message/schema_reader | ||
113 | 109 | drizzled/message/schema_writer | ||
114 | 110 | drizzled/message/table.pb.cc | ||
115 | 111 | drizzled/message/table.pb.h | ||
116 | 112 | drizzled/message/table_raw_reader | ||
117 | 113 | drizzled/message/table_reader | ||
118 | 114 | drizzled/message/table_writer | ||
119 | 115 | drizzled/message/transaction.pb.cc | ||
120 | 116 | drizzled/message/transaction.pb.h | ||
121 | 117 | drizzled/message/transaction_writer | ||
122 | 118 | drizzled/module/load_list.h | ||
123 | 119 | drizzled/plugin/version.h | ||
124 | 120 | drizzled/schema.pb.cc | ||
125 | 121 | drizzled/schema.pb.h | ||
126 | 122 | drizzled/sql_builtin.cc | ||
127 | 123 | drizzled/sql_yacc.cc | ||
128 | 124 | drizzled/sql_yacc.h | ||
129 | 125 | drizzled/sql_yacc.output | ||
130 | 126 | drizzled/sql_reserved_words.h | ||
131 | 127 | drizzled/symbol_hash.h | ||
132 | 128 | drizzled/version.h | ||
133 | 129 | dtcollation.gcno | ||
134 | 130 | errmsg.gcno | ||
135 | 131 | errmsg_print.gcno | ||
136 | 132 | error.gcno | ||
137 | 133 | examples/client | ||
138 | 134 | examples/pipe_query | ||
139 | 135 | examples/proxy | ||
140 | 136 | examples/server | ||
141 | 137 | examples/simple | ||
142 | 138 | examples/simple_multi | ||
143 | 139 | examples/sqlite_server | ||
144 | 140 | extra/Makefile.in | ||
145 | 141 | extra/comp_err | ||
146 | 142 | extra/innochecksum | ||
147 | 143 | extra/my_print_defaults | ||
148 | 144 | extra/mysql_waitpid | ||
149 | 145 | field.gcno | ||
150 | 146 | field_conv.gcno | ||
151 | 147 | field_iterator.gcno | ||
152 | 148 | filesort.gcno | ||
153 | 149 | gnulib/getopt.h | ||
154 | 150 | gnulib/time.h | ||
155 | 151 | gnulib/unistd.h | ||
156 | 152 | ha_trx_info.gcno | ||
157 | 153 | handler.gcno | ||
158 | 154 | handlerton.gcno | ||
159 | 155 | hybrid_type_traits.gcno | ||
160 | 156 | hybrid_type_traits_decimal.gcno | ||
161 | 157 | hybrid_type_traits_integer.gcno | ||
162 | 158 | include/Makefile.in | ||
163 | 159 | include/config.h | ||
164 | 160 | include/drizzle_version.h | ||
165 | 161 | include/mysqld_ername.h | ||
166 | 162 | include/mysqld_error.h | ||
167 | 163 | include/sql_state.h | ||
168 | 164 | include/stamp-h1 | ||
169 | 165 | install-sh | ||
170 | 166 | item.gcno | ||
171 | 167 | key.gcno | ||
172 | 168 | key_map.gcno | ||
173 | 169 | libdrizzle-2.0/libdrizzle/mysql_password_hash | ||
174 | 170 | libdrizzle-2.0/libdrizzle/drizzle_password_hash | ||
175 | 171 | libmysql/Makefile.in | ||
176 | 172 | libserialutil_la-db.gcno | ||
177 | 173 | libserialutil_la-unireg.gcno | ||
178 | 174 | libtool | ||
179 | 175 | lint-rules.am | ||
180 | 176 | lock.gcno | ||
181 | 177 | log.gcno | ||
182 | 178 | logging.gcno | ||
183 | 179 | ltmain.sh | ||
184 | 180 | m4/bzr_version.m4 | ||
185 | 181 | m4/libtool.m4 | ||
186 | 182 | m4/ltoptions.m4 | ||
187 | 183 | m4/ltsugar.m4 | ||
188 | 184 | m4/ltversion.m4 | ||
189 | 185 | m4/lt~obsolete.m4 | ||
190 | 186 | mf_iocache.gcno | ||
191 | 187 | missing | ||
192 | 188 | my_decimal.gcno | ||
193 | 189 | mysql-test/Makefile.in | ||
194 | 190 | mysys/Makefile.in | ||
195 | 191 | mysys/tests/Makefile.in | ||
196 | 192 | name_resolution_context_state.gcno | ||
197 | 193 | natural_join_column.gcno | ||
198 | 194 | opt_range.gcno | ||
199 | 195 | opt_sum.gcno | ||
200 | 196 | out | ||
201 | 197 | pandora-plugin.ac | ||
202 | 198 | pandora-plugin.am | ||
203 | 199 | parser.gcno | ||
204 | 200 | patch | ||
205 | 201 | plugin/Makefile.in | ||
206 | 202 | plugin/archive/Makefile.in | ||
207 | 203 | plugin/archive/archive_performance | ||
208 | 204 | plugin/archive/archive_reader | ||
209 | 205 | plugin/archive/archive_test | ||
210 | 206 | plugin/archive/concurrency_test | ||
211 | 207 | plugin/blackhole/Makefile.in | ||
212 | 208 | plugin/csv/Makefile.in | ||
213 | 209 | plugin/heap/Makefile.in | ||
214 | 210 | plugin/innobase/Makefile.in | ||
215 | 211 | plugin/innobase/include/pars0grm.hh | ||
216 | 212 | plugin/innobase/include/pars0grm.h | ||
217 | 213 | plugin/innobase/pars/pars0grm.c | ||
218 | 214 | plugin/innobase/pars/pars0grm.cc | ||
219 | 215 | plugin/innobase/pars/pars0grm.h | ||
220 | 216 | plugin/innobase/pars/pars0lex.c | ||
221 | 217 | plugin/memcached_functions/start_mc.sh | ||
222 | 218 | plugin/memcached_functions/tests/start_mc.sh | ||
223 | 219 | plugin/myisam/Makefile.in | ||
224 | 220 | plugin/myisam/myisamchk | ||
225 | 221 | plugin/myisam/myisamlog | ||
226 | 222 | plugin/myisam/myisampack | ||
227 | 223 | plugin/storage_engine_api_tester/cursor_states_to_dot | ||
228 | 224 | plugin/storage_engine_api_tester/engine_states_to_dot | ||
229 | 225 | plugin/transaction_log/utilities/drizzletrx | ||
230 | 226 | po/POTFILES | ||
231 | 227 | po/drizzle7.pot | ||
232 | 228 | po/remove-potcdate.sed | ||
233 | 229 | po/stamp-it | ||
234 | 230 | po/stamp-po | ||
235 | 231 | protocol.gcno | ||
236 | 232 | qcache.gcno | ||
237 | 233 | query_id.gcno | ||
238 | 234 | records.gcno | ||
239 | 235 | regex/Makefile.in | ||
240 | 236 | rename.gcno | ||
241 | 237 | replicator.gcno | ||
242 | 238 | scheduling.gcno | ||
243 | 239 | scripts/Makefile.in | ||
244 | 240 | server/drizzled_safe | ||
245 | 241 | server/gen_lex_hash | ||
246 | 242 | server/lex_hash.h | ||
247 | 243 | server/share/czech/ | ||
248 | 244 | server/share/danish/ | ||
249 | 245 | server/share/dutch/ | ||
250 | 246 | server/share/english/ | ||
251 | 247 | server/share/estonian/ | ||
252 | 248 | server/share/french/ | ||
253 | 249 | server/share/german/ | ||
254 | 250 | server/share/greek/ | ||
255 | 251 | server/share/hungarian/ | ||
256 | 252 | server/share/italian/ | ||
257 | 253 | server/share/japanese-sjis/ | ||
258 | 254 | server/share/japanese/ | ||
259 | 255 | server/share/korean/ | ||
260 | 256 | server/share/norwegian-ny/ | ||
261 | 257 | server/share/norwegian/ | ||
262 | 258 | server/share/polish/ | ||
263 | 259 | server/share/portuguese/ | ||
264 | 260 | server/share/romanian/ | ||
265 | 261 | server/share/russian/ | ||
266 | 262 | server/share/serbian/ | ||
267 | 263 | server/share/slovak/ | ||
268 | 264 | server/share/spanish/ | ||
269 | 265 | server/share/swedish/ | ||
270 | 266 | server/share/ukrainian/ | ||
271 | 267 | server/sql_yacc.cc | ||
272 | 268 | server/sql_yacc.h | ||
273 | 269 | server/sql_yacc.output | ||
274 | 270 | session.gcno | ||
275 | 271 | set_var.gcno | ||
276 | 272 | show.gcno | ||
277 | 273 | sj_tmp_table.gcno | ||
278 | 274 | sql-common/Makefile.in | ||
279 | 275 | sql/Makefile.in | ||
280 | 276 | sql/share/Makefile.in | ||
281 | 277 | sql_base.gcno | ||
282 | 278 | sql_client.gcno | ||
283 | 279 | sql_connect.gcno | ||
284 | 280 | sql_delete.gcno | ||
285 | 281 | sql_derived.gcno | ||
286 | 282 | sql_error.gcno | ||
287 | 283 | sql_handler.gcno | ||
288 | 284 | sql_insert.gcno | ||
289 | 285 | sql_lex.gcno | ||
290 | 286 | sql_list.gcno | ||
291 | 287 | sql_load.gcno | ||
292 | 288 | sql_locale.gcno | ||
293 | 289 | sql_parse.gcno | ||
294 | 290 | sql_plugin.gcno | ||
295 | 291 | sql_select.gcno | ||
296 | 292 | sql_state.gcno | ||
297 | 293 | sql_string.gcno | ||
298 | 294 | sql_table.gcno | ||
299 | 295 | sql_udf.gcno | ||
300 | 296 | sql_union.gcno | ||
301 | 297 | sql_update.gcno | ||
302 | 298 | sql_yacc.gcno | ||
303 | 299 | stacktrace.gcno | ||
304 | 300 | stamp-h1 | ||
305 | 301 | strfunc.gcno | ||
306 | 302 | strings/Makefile.in | ||
307 | 303 | strings/tests/Makefile.in | ||
308 | 304 | support-files/Makefile.in | ||
309 | 305 | support-files/drizzle-log-rotate | ||
310 | 306 | support-files/drizzle7.pc | ||
311 | 307 | support-files/drizzle.server | ||
312 | 308 | support-files/drizzle.spec | ||
313 | 309 | support-files/libdrizzle.pc | ||
314 | 310 | support-files/libdrizzle-1.0.pc | ||
315 | 311 | support-files/libdrizzle-2.0.pc | ||
316 | 312 | support-files/libdrizzleclient.pc | ||
317 | 313 | support-files/smf/Makefile.in | ||
318 | 314 | support-files/smf/drizzle | ||
319 | 315 | support-files/smf/drizzle.xml | ||
320 | 316 | support-files/smf/install.sh | ||
321 | 317 | table.gcno | ||
322 | 318 | table_map_iterator.gcno | ||
323 | 319 | temporal.gcno | ||
324 | 320 | temporal_format.gcno | ||
325 | 321 | tests/Makefile.in | ||
326 | 322 | tests/dtr | ||
327 | 323 | tests/dtr@ | ||
328 | 324 | tests/dbqp | ||
329 | 325 | tests/dbqp_data/uuid | ||
330 | 326 | tests/dbqp_work | ||
331 | 327 | tests/install_test_db | ||
332 | 328 | tests/mtr | ||
333 | 329 | tests/mtr@ | ||
334 | 330 | tests/resolve_stack_dump | ||
335 | 331 | tests/stripped_log | ||
336 | 332 | tests/test-run | ||
337 | 333 | tests/test-run@ | ||
338 | 334 | tests/total_warning_count | ||
339 | 335 | tests/var | ||
340 | 336 | tests/workdir | ||
341 | 337 | thr_malloc.gcno | ||
342 | 338 | time.gcno | ||
343 | 339 | tmp_table.gcno | ||
344 | 340 | tztime.gcno | ||
345 | 341 | uniques.gcno | ||
346 | 342 | unittests/atomics_test | ||
347 | 343 | unittests/calendar_test | ||
348 | 344 | unittests/unittests | ||
349 | 345 | unittests/uwagi.txt | ||
350 | 346 | virtual_column_info.gcno | ||
351 | 347 | xid.gcno | ||
352 | 348 | ylwrap | ||
353 | 349 | docs/html | ||
354 | 350 | docs/dirhtml | ||
355 | 351 | docs/singlehtml | ||
356 | 352 | docs/pickle | ||
357 | 353 | docs/json | ||
358 | 354 | docs/htmlhelp | ||
359 | 355 | docs/qthelp | ||
360 | 356 | docs/devhelp | ||
361 | 357 | docs/epub | ||
362 | 358 | docs/latex | ||
363 | 359 | docs/latexpdf | ||
364 | 360 | docs/text | ||
365 | 361 | docs/man | ||
366 | 362 | docs/changes | ||
367 | 363 | docs/linkcheck | ||
368 | 364 | docs/doctest | ||
369 | 365 | .pc | ||
370 | 366 | drizzled/message/catalog.pb.cc | ||
371 | 367 | drizzled/message/catalog.pb.h | ||
372 | 368 | drizzled/message/catalog_reader | ||
373 | 369 | drizzled/message/catalog_writer | ||
374 | 370 | drizzled/message/replication_options.pb.cc | ||
375 | 371 | drizzled/message/replication_options.pb.h | ||
376 | 372 | drizzled/message/access.pb.cc | ||
377 | 373 | drizzled/message/access.pb.h | ||
378 | 374 | drizzled/execute/parser.cc | ||
379 | 375 | drizzled/execute/parser.h | ||
380 | 376 | drizzled/execute/parser.output | ||
381 | 377 | drizzled/execute/scanner.cc | ||
382 | 378 | drizzled/execute/scanner.h | ||
383 | 379 | plugin/innobase/xtrabackup/drizzlebackup.innobase | ||
384 | 380 | libdrizzle-2.0/drizzle_password_hash | ||
385 | 381 | libdrizzle-2.0/mysql_password_hash | ||
386 | 382 | .autotools | ||
387 | 383 | .cproject | ||
388 | 384 | .metadata | ||
389 | 385 | .project | ||
390 | 386 | .settings | ||
391 | 0 | 387 | ||
392 | === renamed file '.bzrignore' => '.bzrignore.THIS' | |||
393 | === modified file 'drizzled/item/sum.cc' | |||
394 | --- drizzled/item/sum.cc 2011-10-19 09:25:53 +0000 | |||
395 | +++ drizzled/item/sum.cc 2011-12-24 17:41:25 +0000 | |||
396 | @@ -3048,7 +3048,7 @@ | |||
397 | 3048 | table= 0; | 3048 | table= 0; |
398 | 3049 | if (tree) | 3049 | if (tree) |
399 | 3050 | { | 3050 | { |
401 | 3051 | delete_tree(tree); | 3051 | tree->delete_tree(); |
402 | 3052 | tree= 0; | 3052 | tree= 0; |
403 | 3053 | } | 3053 | } |
404 | 3054 | 3054 | ||
405 | @@ -3083,7 +3083,7 @@ | |||
406 | 3083 | warning_for_row= false; | 3083 | warning_for_row= false; |
407 | 3084 | no_appended= true; | 3084 | no_appended= true; |
408 | 3085 | if (tree) | 3085 | if (tree) |
410 | 3086 | reset_tree(tree); | 3086 | tree->reset_tree(); |
411 | 3087 | if (distinct) | 3087 | if (distinct) |
412 | 3088 | unique_filter->reset(); | 3088 | unique_filter->reset(); |
413 | 3089 | /* No need to reset the table as we never call write_row */ | 3089 | /* No need to reset the table as we never call write_row */ |
414 | @@ -3121,10 +3121,10 @@ | |||
415 | 3121 | row_eligible= false; | 3121 | row_eligible= false; |
416 | 3122 | } | 3122 | } |
417 | 3123 | 3123 | ||
419 | 3124 | TREE_ELEMENT *el= 0; // Only for safety | 3124 | Tree_Element *el= 0; // Only for safety |
420 | 3125 | if (row_eligible && tree) | 3125 | if (row_eligible && tree) |
423 | 3126 | el= tree_insert(tree, table->record[0] + table->getShare()->null_bytes, 0, | 3126 | el= tree->tree_insert(table->record[0] + table->getShare()->null_bytes, 0, |
424 | 3127 | tree->custom_arg); | 3127 | tree->getCustomArg()); |
425 | 3128 | /* | 3128 | /* |
426 | 3129 | If the row is not a duplicate (el->count == 1) | 3129 | If the row is not a duplicate (el->count == 1) |
427 | 3130 | we can dump the row here in case of GROUP_CONCAT(DISTINCT...) | 3130 | we can dump the row here in case of GROUP_CONCAT(DISTINCT...) |
428 | @@ -3273,7 +3273,7 @@ | |||
429 | 3273 | syntax of this function). If there is no ORDER BY clause, we don't | 3273 | syntax of this function). If there is no ORDER BY clause, we don't |
430 | 3274 | create this tree. | 3274 | create this tree. |
431 | 3275 | */ | 3275 | */ |
433 | 3276 | init_tree(tree, (uint32_t) min(session->variables.max_heap_table_size, | 3276 | tree->init_tree((uint32_t) min(session->variables.max_heap_table_size, |
434 | 3277 | (uint64_t)(session->variables.sortbuff_size/16)), | 3277 | (uint64_t)(session->variables.sortbuff_size/16)), |
435 | 3278 | 0, | 3278 | 0, |
436 | 3279 | tree_key_length, | 3279 | tree_key_length, |
437 | @@ -3325,8 +3325,7 @@ | |||
438 | 3325 | return 0; | 3325 | return 0; |
439 | 3326 | if (no_appended && tree) | 3326 | if (no_appended && tree) |
440 | 3327 | /* Tree is used for sorting as in ORDER BY */ | 3327 | /* Tree is used for sorting as in ORDER BY */ |
443 | 3328 | tree_walk(tree, (tree_walk_action)&dump_leaf_key, (void*)this, | 3328 | tree->tree_walk((tree_walk_action)&dump_leaf_key, (void*)this, left_root_right); |
442 | 3329 | left_root_right); | ||
444 | 3330 | if (count_cut_values && !warning) | 3329 | if (count_cut_values && !warning) |
445 | 3331 | { | 3330 | { |
446 | 3332 | /* | 3331 | /* |
447 | 3333 | 3332 | ||
448 | === modified file 'drizzled/item/sum.h' | |||
449 | --- drizzled/item/sum.h 2011-04-20 22:18:30 +0000 | |||
450 | +++ drizzled/item/sum.h 2011-12-24 17:41:25 +0000 | |||
451 | @@ -950,8 +950,8 @@ | |||
452 | 950 | DRIZZLE_ERROR *warning; | 950 | DRIZZLE_ERROR *warning; |
453 | 951 | String result; | 951 | String result; |
454 | 952 | String *separator; | 952 | String *separator; |
457 | 953 | TREE tree_base; | 953 | Tree tree_base; |
458 | 954 | TREE *tree; | 954 | Tree *tree; |
459 | 955 | 955 | ||
460 | 956 | /** | 956 | /** |
461 | 957 | If DISTINCT is used with this GROUP_CONCAT, this member is used to filter | 957 | If DISTINCT is used with this GROUP_CONCAT, this member is used to filter |
462 | 958 | 958 | ||
463 | === modified file 'drizzled/tree.cc' | |||
464 | --- drizzled/tree.cc 2011-06-22 14:19:44 +0000 | |||
465 | +++ drizzled/tree.cc 2011-12-24 17:41:25 +0000 | |||
466 | @@ -15,7 +15,7 @@ | |||
467 | 15 | 15 | ||
468 | 16 | /* | 16 | /* |
469 | 17 | Code for handling red-black (balanced) binary trees. | 17 | Code for handling red-black (balanced) binary trees. |
471 | 18 | key in tree is allocated accrding to following: | 18 | key in tree is allocated according to following: |
472 | 19 | 19 | ||
473 | 20 | 1) If size < 0 then tree will not allocate keys and only a pointer to | 20 | 1) If size < 0 then tree will not allocate keys and only a pointer to |
474 | 21 | each key is saved in tree. | 21 | each key is saved in tree. |
475 | @@ -29,8 +29,8 @@ | |||
476 | 29 | 3) if key_size is given to init_tree then each node will continue the | 29 | 3) if key_size is given to init_tree then each node will continue the |
477 | 30 | key and calls to insert_key may increase length of key. | 30 | key and calls to insert_key may increase length of key. |
478 | 31 | if key_size > sizeof(pointer) and key_size is a multiple of 8 (double | 31 | if key_size > sizeof(pointer) and key_size is a multiple of 8 (double |
481 | 32 | allign) then key will be put on a 8 alligned adress. Else | 32 | align) then key will be put on a 8 aligned address. Else |
482 | 33 | the key will be on adress (element+1). This is transparent for user | 33 | the key will be on address (element+1). This is transparent for user |
483 | 34 | compare and search functions uses a pointer to given key-argument. | 34 | compare and search functions uses a pointer to given key-argument. |
484 | 35 | 35 | ||
485 | 36 | - If you use a free function for tree-elements and you are freeing | 36 | - If you use a free function for tree-elements and you are freeing |
486 | @@ -48,9 +48,9 @@ | |||
487 | 48 | /* | 48 | /* |
488 | 49 | NOTE: | 49 | NOTE: |
489 | 50 | tree->compare function should be ALWAYS called as | 50 | tree->compare function should be ALWAYS called as |
493 | 51 | (*tree->compare)(custom_arg, ELEMENT_KEY(tree,element), key) | 51 | (*compare)(custom_arg, element_key(element), key) |
494 | 52 | and not other way around, as | 52 | and NOT the other way around, as |
495 | 53 | (*tree->compare)(custom_arg, key, ELEMENT_KEY(tree,element)) | 53 | (*compare)(custom_arg, key, element_key(element)) |
496 | 54 | */ | 54 | */ |
497 | 55 | 55 | ||
498 | 56 | #include <config.h> | 56 | #include <config.h> |
499 | @@ -58,150 +58,88 @@ | |||
500 | 58 | #include <drizzled/tree.h> | 58 | #include <drizzled/tree.h> |
501 | 59 | #include <drizzled/internal/my_sys.h> | 59 | #include <drizzled/internal/my_sys.h> |
502 | 60 | #include <drizzled/internal/m_string.h> | 60 | #include <drizzled/internal/m_string.h> |
503 | 61 | #include <drizzled/memory/root.h> | ||
504 | 62 | 61 | ||
505 | 63 | #define BLACK 1 | 62 | #define BLACK 1 |
506 | 64 | #define RED 0 | 63 | #define RED 0 |
507 | 65 | #define DEFAULT_ALLOC_SIZE 8192 | 64 | #define DEFAULT_ALLOC_SIZE 8192 |
508 | 66 | #define DEFAULT_ALIGN_SIZE 8192 | 65 | #define DEFAULT_ALIGN_SIZE 8192 |
509 | 67 | 66 | ||
510 | 68 | #define ELEMENT_KEY(tree,element)\ | ||
511 | 69 | (tree->offset_to_key ? (void*)((unsigned char*) element+tree->offset_to_key) :\ | ||
512 | 70 | *((void**) (element+1))) | ||
513 | 71 | #define ELEMENT_CHILD(element, offs) (*(TREE_ELEMENT**)((char*)element + offs)) | ||
514 | 72 | 67 | ||
515 | 73 | namespace drizzled | 68 | namespace drizzled |
516 | 74 | { | 69 | { |
517 | 75 | 70 | ||
533 | 76 | 71 | /** | |
534 | 77 | static void delete_tree_element(TREE *,TREE_ELEMENT *); | 72 | * Tree class public methods |
535 | 78 | static int tree_walk_left_root_right(TREE *,TREE_ELEMENT *, | 73 | */ |
536 | 79 | tree_walk_action,void *); | 74 | |
537 | 80 | static int tree_walk_right_root_left(TREE *,TREE_ELEMENT *, | 75 | void Tree::init_tree(size_t default_alloc_size, uint32_t mem_limit, |
538 | 81 | tree_walk_action,void *); | 76 | uint32_t size, qsort_cmp2 compare_callback, bool free_with_tree, |
539 | 82 | static void left_rotate(TREE_ELEMENT **parent,TREE_ELEMENT *leaf); | 77 | tree_element_free free_callback, void *caller_arg) |
525 | 83 | static void right_rotate(TREE_ELEMENT **parent, TREE_ELEMENT *leaf); | ||
526 | 84 | static void rb_insert(TREE *tree,TREE_ELEMENT ***parent, | ||
527 | 85 | TREE_ELEMENT *leaf); | ||
528 | 86 | |||
529 | 87 | |||
530 | 88 | void init_tree(TREE *tree, size_t default_alloc_size, uint32_t memory_limit, | ||
531 | 89 | uint32_t size, qsort_cmp2 compare, bool with_delete, | ||
532 | 90 | tree_element_free free_element, void *custom_arg) | ||
540 | 91 | { | 78 | { |
541 | 92 | if (default_alloc_size < DEFAULT_ALLOC_SIZE) | 79 | if (default_alloc_size < DEFAULT_ALLOC_SIZE) |
542 | 93 | default_alloc_size= DEFAULT_ALLOC_SIZE; | 80 | default_alloc_size= DEFAULT_ALLOC_SIZE; |
543 | 94 | default_alloc_size= MY_ALIGN(default_alloc_size, DEFAULT_ALIGN_SIZE); | 81 | default_alloc_size= MY_ALIGN(default_alloc_size, DEFAULT_ALIGN_SIZE); |
557 | 95 | memset(&tree->null_element, 0, sizeof(tree->null_element)); | 82 | memset(&this->null_element, 0, sizeof(this->null_element)); |
558 | 96 | tree->root= &tree->null_element; | 83 | root= &this->null_element; |
559 | 97 | tree->compare= compare; | 84 | compare= compare_callback; |
560 | 98 | tree->size_of_element= size > 0 ? (uint32_t) size : 0; | 85 | size_of_element= size > 0 ? (uint32_t) size : 0; |
561 | 99 | tree->memory_limit= memory_limit; | 86 | memory_limit= mem_limit; |
562 | 100 | tree->free= free_element; | 87 | free= free_callback; |
563 | 101 | tree->allocated= 0; | 88 | allocated= 0; |
564 | 102 | tree->elements_in_tree= 0; | 89 | elements_in_tree= 0; |
565 | 103 | tree->custom_arg = custom_arg; | 90 | custom_arg = caller_arg; |
566 | 104 | tree->null_element.colour= BLACK; | 91 | null_element.colour= BLACK; |
567 | 105 | tree->null_element.left=tree->null_element.right= 0; | 92 | null_element.left=this->null_element.right= 0; |
568 | 106 | tree->flag= 0; | 93 | flag= 0; |
569 | 107 | if (!free_element && | 94 | if (!free_callback && |
570 | 108 | (size <= sizeof(void*) || ((uint32_t) size & (sizeof(void*)-1)))) | 95 | (size <= sizeof(void*) || ((uint32_t) size & (sizeof(void*)-1)))) |
571 | 109 | { | 96 | { |
572 | 110 | /* | 97 | /* |
573 | 111 | We know that the data doesn't have to be aligned (like if the key | 98 | We know that the data doesn't have to be aligned (like if the key |
574 | 112 | contains a double), so we can store the data combined with the | 99 | contains a double), so we can store the data combined with the |
576 | 113 | TREE_ELEMENT. | 100 | Tree_Element. |
577 | 114 | */ | 101 | */ |
579 | 115 | tree->offset_to_key= sizeof(TREE_ELEMENT); /* Put key after element */ | 102 | offset_to_key= sizeof(Tree_Element); /* Put key after element */ |
580 | 116 | /* Fix allocation size so that we don't lose any memory */ | 103 | /* Fix allocation size so that we don't lose any memory */ |
582 | 117 | default_alloc_size/= (sizeof(TREE_ELEMENT)+size); | 104 | default_alloc_size/= (sizeof(Tree_Element)+size); |
583 | 118 | if (!default_alloc_size) | 105 | if (!default_alloc_size) |
584 | 119 | default_alloc_size= 1; | 106 | default_alloc_size= 1; |
586 | 120 | default_alloc_size*= (sizeof(TREE_ELEMENT)+size); | 107 | default_alloc_size*= (sizeof(Tree_Element)+size); |
587 | 121 | } | 108 | } |
588 | 122 | else | 109 | else |
589 | 123 | { | 110 | { |
630 | 124 | tree->offset_to_key= 0; /* use key through pointer */ | 111 | offset_to_key= 0; /* use key through pointer */ |
631 | 125 | tree->size_of_element+= sizeof(void*); | 112 | size_of_element+= sizeof(void*); |
632 | 126 | } | 113 | } |
633 | 127 | if (! (tree->with_delete= with_delete)) | 114 | if (! (with_delete= free_with_tree)) |
634 | 128 | { | 115 | { |
635 | 129 | tree->mem_root.init(default_alloc_size); | 116 | mem_root.init(default_alloc_size); |
636 | 130 | tree->mem_root.min_malloc= (sizeof(TREE_ELEMENT)+tree->size_of_element); | 117 | mem_root.min_malloc= (sizeof(Tree_Element)+size_of_element); |
637 | 131 | } | 118 | } |
638 | 132 | } | 119 | } |
639 | 133 | 120 | ||
640 | 134 | static void free_tree(TREE *tree, myf free_flags) | 121 | void Tree::delete_tree() |
641 | 135 | { | 122 | { |
642 | 136 | if (tree->root) /* If initialized */ | 123 | free_tree(MYF(0)); /* free() mem_root if applicable */ |
643 | 137 | { | 124 | } |
644 | 138 | if (tree->with_delete) | 125 | |
645 | 139 | delete_tree_element(tree,tree->root); | 126 | void Tree::reset_tree() |
606 | 140 | else | ||
607 | 141 | { | ||
608 | 142 | if (tree->free) | ||
609 | 143 | { | ||
610 | 144 | if (tree->memory_limit) | ||
611 | 145 | (*tree->free)(NULL, free_init, tree->custom_arg); | ||
612 | 146 | delete_tree_element(tree,tree->root); | ||
613 | 147 | if (tree->memory_limit) | ||
614 | 148 | (*tree->free)(NULL, free_end, tree->custom_arg); | ||
615 | 149 | } | ||
616 | 150 | tree->mem_root.free_root(free_flags); | ||
617 | 151 | } | ||
618 | 152 | } | ||
619 | 153 | tree->root= &tree->null_element; | ||
620 | 154 | tree->elements_in_tree= 0; | ||
621 | 155 | tree->allocated= 0; | ||
622 | 156 | } | ||
623 | 157 | |||
624 | 158 | void delete_tree(TREE* tree) | ||
625 | 159 | { | ||
626 | 160 | free_tree(tree, MYF(0)); /* free() mem_root if applicable */ | ||
627 | 161 | } | ||
628 | 162 | |||
629 | 163 | void reset_tree(TREE* tree) | ||
646 | 164 | { | 127 | { |
647 | 165 | /* do not free mem_root, just mark blocks as free */ | 128 | /* do not free mem_root, just mark blocks as free */ |
676 | 166 | free_tree(tree, MYF(memory::MARK_BLOCKS_FREE)); | 129 | free_tree(MYF(memory::MARK_BLOCKS_FREE)); |
677 | 167 | } | 130 | } |
678 | 168 | 131 | ||
679 | 169 | 132 | Tree_Element* Tree::tree_insert(void* key, uint32_t key_size, void* caller_arg) | |
652 | 170 | static void delete_tree_element(TREE *tree, TREE_ELEMENT *element) | ||
653 | 171 | { | ||
654 | 172 | if (element != &tree->null_element) | ||
655 | 173 | { | ||
656 | 174 | delete_tree_element(tree,element->left); | ||
657 | 175 | if (tree->free) | ||
658 | 176 | (*tree->free)(ELEMENT_KEY(tree,element), free_free, tree->custom_arg); | ||
659 | 177 | delete_tree_element(tree,element->right); | ||
660 | 178 | if (tree->with_delete) | ||
661 | 179 | free((char*) element); | ||
662 | 180 | } | ||
663 | 181 | } | ||
664 | 182 | |||
665 | 183 | |||
666 | 184 | /* | ||
667 | 185 | insert, search and delete of elements | ||
668 | 186 | |||
669 | 187 | The following should be true: | ||
670 | 188 | parent[0] = & parent[-1][0]->left || | ||
671 | 189 | parent[0] = & parent[-1][0]->right | ||
672 | 190 | */ | ||
673 | 191 | |||
674 | 192 | TREE_ELEMENT *tree_insert(TREE *tree, void *key, uint32_t key_size, | ||
675 | 193 | void* custom_arg) | ||
680 | 194 | { | 133 | { |
681 | 195 | int cmp; | 134 | int cmp; |
683 | 196 | TREE_ELEMENT *element,***parent; | 135 | Tree_Element *element,***parent; |
684 | 197 | 136 | ||
687 | 198 | parent= tree->parents; | 137 | parent= this->parents; |
688 | 199 | *parent = &tree->root; element= tree->root; | 138 | *parent = &this->root; element= this->root; |
689 | 200 | for (;;) | 139 | for (;;) |
690 | 201 | { | 140 | { |
694 | 202 | if (element == &tree->null_element || | 141 | if (element == &this->null_element || |
695 | 203 | (cmp = (*tree->compare)(custom_arg, ELEMENT_KEY(tree,element), | 142 | (cmp = (*compare)(caller_arg, element_key(element), key)) == 0) |
693 | 204 | key)) == 0) | ||
696 | 205 | break; | 143 | break; |
697 | 206 | if (cmp < 0) | 144 | if (cmp < 0) |
698 | 207 | { | 145 | { |
699 | @@ -212,26 +150,26 @@ | |||
700 | 212 | *++parent = &element->left; element= element->left; | 150 | *++parent = &element->left; element= element->left; |
701 | 213 | } | 151 | } |
702 | 214 | } | 152 | } |
704 | 215 | if (element == &tree->null_element) | 153 | if (element == &this->null_element) |
705 | 216 | { | 154 | { |
708 | 217 | size_t alloc_size= sizeof(TREE_ELEMENT)+key_size+tree->size_of_element; | 155 | size_t alloc_size= sizeof(Tree_Element)+key_size+this->size_of_element; |
709 | 218 | tree->allocated+= alloc_size; | 156 | this->allocated+= alloc_size; |
710 | 219 | 157 | ||
713 | 220 | if (tree->memory_limit && tree->elements_in_tree | 158 | if (this->memory_limit && this->elements_in_tree |
714 | 221 | && tree->allocated > tree->memory_limit) | 159 | && this->allocated > this->memory_limit) |
715 | 222 | { | 160 | { |
718 | 223 | reset_tree(tree); | 161 | reset_tree(); |
719 | 224 | return tree_insert(tree, key, key_size, custom_arg); | 162 | return tree_insert(key, key_size, caller_arg); |
720 | 225 | } | 163 | } |
721 | 226 | 164 | ||
725 | 227 | key_size+= tree->size_of_element; | 165 | key_size+= this->size_of_element; |
726 | 228 | if (tree->with_delete) | 166 | if (this->with_delete) |
727 | 229 | element= (TREE_ELEMENT *) malloc(alloc_size); | 167 | element= (Tree_Element *) malloc(alloc_size); |
728 | 230 | else | 168 | else |
730 | 231 | element= (TREE_ELEMENT *) tree->mem_root.alloc(alloc_size); | 169 | element= (Tree_Element *) this->mem_root.alloc(alloc_size); |
731 | 232 | **parent= element; | 170 | **parent= element; |
734 | 233 | element->left= element->right= &tree->null_element; | 171 | element->left= element->right= &this->null_element; |
735 | 234 | if (!tree->offset_to_key) | 172 | if (!this->offset_to_key) |
736 | 235 | { | 173 | { |
737 | 236 | if (key_size == sizeof(void*)) /* no length, save pointer */ | 174 | if (key_size == sizeof(void*)) /* no length, save pointer */ |
738 | 237 | *((void**) (element+1))= key; | 175 | *((void**) (element+1))= key; |
739 | @@ -242,14 +180,14 @@ | |||
740 | 242 | } | 180 | } |
741 | 243 | } | 181 | } |
742 | 244 | else | 182 | else |
744 | 245 | memcpy((unsigned char*) element + tree->offset_to_key, key, key_size); | 183 | memcpy((unsigned char*) element + this->offset_to_key, key, key_size); |
745 | 246 | element->count= 1; /* May give warning in purify */ | 184 | element->count= 1; /* May give warning in purify */ |
748 | 247 | tree->elements_in_tree++; | 185 | this->elements_in_tree++; |
749 | 248 | rb_insert(tree,parent,element); /* rebalance tree */ | 186 | rb_insert(parent,element); /* rebalance tree */ |
750 | 249 | } | 187 | } |
751 | 250 | else | 188 | else |
752 | 251 | { | 189 | { |
754 | 252 | if (tree->flag & TREE_NO_DUPS) | 190 | if (this->flag & TREE_NO_DUPS) |
755 | 253 | return(NULL); | 191 | return(NULL); |
756 | 254 | element->count++; | 192 | element->count++; |
757 | 255 | /* Avoid a wrap over of the count. */ | 193 | /* Avoid a wrap over of the count. */ |
758 | @@ -260,238 +198,123 @@ | |||
759 | 260 | return element; | 198 | return element; |
760 | 261 | } | 199 | } |
761 | 262 | 200 | ||
926 | 263 | void *tree_search_key(TREE *tree, const void *key, | 201 | int Tree::tree_walk(tree_walk_action action, void *argument, TREE_WALK visit) |
927 | 264 | TREE_ELEMENT **parents, TREE_ELEMENT ***last_pos, | 202 | { |
928 | 265 | enum ha_rkey_function flag, void *custom_arg) | 203 | switch (visit) { |
929 | 266 | { | 204 | case left_root_right: |
930 | 267 | TREE_ELEMENT *element= tree->root; | 205 | return tree_walk_left_root_right(root,action,argument); |
931 | 268 | TREE_ELEMENT **last_left_step_parent= NULL, **last_right_step_parent= NULL; | 206 | case right_root_left: |
932 | 269 | TREE_ELEMENT **last_equal_element= NULL; | 207 | return tree_walk_right_root_left(root,action,argument); |
769 | 270 | |||
770 | 271 | /* | ||
771 | 272 | TODO: support for HA_READ_KEY_OR_PREV, HA_READ_PREFIX flags if needed. | ||
772 | 273 | */ | ||
773 | 274 | |||
774 | 275 | *parents = &tree->null_element; | ||
775 | 276 | while (element != &tree->null_element) | ||
776 | 277 | { | ||
777 | 278 | int cmp; | ||
778 | 279 | |||
779 | 280 | *++parents= element; | ||
780 | 281 | |||
781 | 282 | if ((cmp= (*tree->compare)(custom_arg, ELEMENT_KEY(tree, element), | ||
782 | 283 | key)) == 0) | ||
783 | 284 | { | ||
784 | 285 | switch (flag) { | ||
785 | 286 | case HA_READ_KEY_EXACT: | ||
786 | 287 | case HA_READ_KEY_OR_NEXT: | ||
787 | 288 | case HA_READ_BEFORE_KEY: | ||
788 | 289 | last_equal_element= parents; | ||
789 | 290 | cmp= 1; | ||
790 | 291 | break; | ||
791 | 292 | case HA_READ_AFTER_KEY: | ||
792 | 293 | cmp= -1; | ||
793 | 294 | break; | ||
794 | 295 | case HA_READ_PREFIX_LAST: | ||
795 | 296 | case HA_READ_PREFIX_LAST_OR_PREV: | ||
796 | 297 | last_equal_element= parents; | ||
797 | 298 | cmp= -1; | ||
798 | 299 | break; | ||
799 | 300 | default: | ||
800 | 301 | return NULL; | ||
801 | 302 | } | ||
802 | 303 | } | ||
803 | 304 | if (cmp < 0) /* element < key */ | ||
804 | 305 | { | ||
805 | 306 | last_right_step_parent= parents; | ||
806 | 307 | element= element->right; | ||
807 | 308 | } | ||
808 | 309 | else | ||
809 | 310 | { | ||
810 | 311 | last_left_step_parent= parents; | ||
811 | 312 | element= element->left; | ||
812 | 313 | } | ||
813 | 314 | } | ||
814 | 315 | switch (flag) { | ||
815 | 316 | case HA_READ_KEY_EXACT: | ||
816 | 317 | case HA_READ_PREFIX_LAST: | ||
817 | 318 | *last_pos= last_equal_element; | ||
818 | 319 | break; | ||
819 | 320 | case HA_READ_KEY_OR_NEXT: | ||
820 | 321 | *last_pos= last_equal_element ? last_equal_element : last_left_step_parent; | ||
821 | 322 | break; | ||
822 | 323 | case HA_READ_AFTER_KEY: | ||
823 | 324 | *last_pos= last_left_step_parent; | ||
824 | 325 | break; | ||
825 | 326 | case HA_READ_PREFIX_LAST_OR_PREV: | ||
826 | 327 | *last_pos= last_equal_element ? last_equal_element : last_right_step_parent; | ||
827 | 328 | break; | ||
828 | 329 | case HA_READ_BEFORE_KEY: | ||
829 | 330 | *last_pos= last_right_step_parent; | ||
830 | 331 | break; | ||
831 | 332 | default: | ||
832 | 333 | return NULL; | ||
833 | 334 | } | ||
834 | 335 | |||
835 | 336 | return *last_pos ? ELEMENT_KEY(tree, **last_pos) : NULL; | ||
836 | 337 | } | ||
837 | 338 | |||
838 | 339 | void *tree_search_next(TREE *tree, TREE_ELEMENT ***last_pos, int l_offs, | ||
839 | 340 | int r_offs) | ||
840 | 341 | { | ||
841 | 342 | TREE_ELEMENT *x= **last_pos; | ||
842 | 343 | |||
843 | 344 | if (ELEMENT_CHILD(x, r_offs) != &tree->null_element) | ||
844 | 345 | { | ||
845 | 346 | x= ELEMENT_CHILD(x, r_offs); | ||
846 | 347 | *++*last_pos= x; | ||
847 | 348 | while (ELEMENT_CHILD(x, l_offs) != &tree->null_element) | ||
848 | 349 | { | ||
849 | 350 | x= ELEMENT_CHILD(x, l_offs); | ||
850 | 351 | *++*last_pos= x; | ||
851 | 352 | } | ||
852 | 353 | return ELEMENT_KEY(tree, x); | ||
853 | 354 | } | ||
854 | 355 | else | ||
855 | 356 | { | ||
856 | 357 | TREE_ELEMENT *y= *--*last_pos; | ||
857 | 358 | while (y != &tree->null_element && x == ELEMENT_CHILD(y, r_offs)) | ||
858 | 359 | { | ||
859 | 360 | x= y; | ||
860 | 361 | y= *--*last_pos; | ||
861 | 362 | } | ||
862 | 363 | return y == &tree->null_element ? NULL : ELEMENT_KEY(tree, y); | ||
863 | 364 | } | ||
864 | 365 | } | ||
865 | 366 | |||
866 | 367 | /* | ||
867 | 368 | Expected that tree is fully balanced | ||
868 | 369 | (each path from root to leaf has the same length) | ||
869 | 370 | */ | ||
870 | 371 | ha_rows tree_record_pos(TREE *tree, const void *key, | ||
871 | 372 | enum ha_rkey_function flag, void *custom_arg) | ||
872 | 373 | { | ||
873 | 374 | TREE_ELEMENT *element= tree->root; | ||
874 | 375 | double left= 1; | ||
875 | 376 | double right= tree->elements_in_tree; | ||
876 | 377 | |||
877 | 378 | while (element != &tree->null_element) | ||
878 | 379 | { | ||
879 | 380 | int cmp; | ||
880 | 381 | |||
881 | 382 | if ((cmp= (*tree->compare)(custom_arg, ELEMENT_KEY(tree, element), | ||
882 | 383 | key)) == 0) | ||
883 | 384 | { | ||
884 | 385 | switch (flag) { | ||
885 | 386 | case HA_READ_KEY_EXACT: | ||
886 | 387 | case HA_READ_BEFORE_KEY: | ||
887 | 388 | cmp= 1; | ||
888 | 389 | break; | ||
889 | 390 | case HA_READ_AFTER_KEY: | ||
890 | 391 | cmp= -1; | ||
891 | 392 | break; | ||
892 | 393 | default: | ||
893 | 394 | return HA_POS_ERROR; | ||
894 | 395 | } | ||
895 | 396 | } | ||
896 | 397 | if (cmp < 0) /* element < key */ | ||
897 | 398 | { | ||
898 | 399 | element= element->right; | ||
899 | 400 | left= (left + right) / 2; | ||
900 | 401 | } | ||
901 | 402 | else | ||
902 | 403 | { | ||
903 | 404 | element= element->left; | ||
904 | 405 | right= (left + right) / 2; | ||
905 | 406 | } | ||
906 | 407 | } | ||
907 | 408 | |||
908 | 409 | switch (flag) { | ||
909 | 410 | case HA_READ_KEY_EXACT: | ||
910 | 411 | case HA_READ_BEFORE_KEY: | ||
911 | 412 | return (ha_rows) right; | ||
912 | 413 | case HA_READ_AFTER_KEY: | ||
913 | 414 | return (ha_rows) left; | ||
914 | 415 | default: | ||
915 | 416 | return HA_POS_ERROR; | ||
916 | 417 | } | ||
917 | 418 | } | ||
918 | 419 | |||
919 | 420 | int tree_walk(TREE *tree, tree_walk_action action, void *argument, TREE_WALK visit) | ||
920 | 421 | { | ||
921 | 422 | switch (visit) { | ||
922 | 423 | case left_root_right: | ||
923 | 424 | return tree_walk_left_root_right(tree,tree->root,action,argument); | ||
924 | 425 | case right_root_left: | ||
925 | 426 | return tree_walk_right_root_left(tree,tree->root,action,argument); | ||
933 | 427 | } | 208 | } |
934 | 428 | 209 | ||
935 | 429 | return 0; /* Keep gcc happy */ | 210 | return 0; /* Keep gcc happy */ |
936 | 430 | } | 211 | } |
937 | 431 | 212 | ||
939 | 432 | static int tree_walk_left_root_right(TREE *tree, TREE_ELEMENT *element, tree_walk_action action, void *argument) | 213 | /** |
940 | 214 | * Tree class private methods | ||
941 | 215 | */ | ||
942 | 216 | |||
943 | 217 | void Tree::free_tree(myf free_flags) | ||
944 | 218 | { | ||
945 | 219 | if (root) /* If initialized */ | ||
946 | 220 | { | ||
947 | 221 | if (with_delete) | ||
948 | 222 | delete_tree_element(root); | ||
949 | 223 | else | ||
950 | 224 | { | ||
951 | 225 | if (free) | ||
952 | 226 | { | ||
953 | 227 | if (memory_limit) | ||
954 | 228 | (*free)(NULL, free_init, custom_arg); | ||
955 | 229 | delete_tree_element(root); | ||
956 | 230 | if (memory_limit) | ||
957 | 231 | (*free)(NULL, free_end, custom_arg); | ||
958 | 232 | } | ||
959 | 233 | mem_root.free_root(free_flags); | ||
960 | 234 | } | ||
961 | 235 | } | ||
962 | 236 | root= &null_element; | ||
963 | 237 | elements_in_tree= 0; | ||
964 | 238 | allocated= 0; | ||
965 | 239 | } | ||
966 | 240 | |||
967 | 241 | void* Tree::element_key(Tree_Element* element) | ||
968 | 242 | { | ||
969 | 243 | return offset_to_key ? (void*)((unsigned char*) element + offset_to_key) | ||
970 | 244 | : *((void**)(element + 1)); | ||
971 | 245 | } | ||
972 | 246 | |||
973 | 247 | void Tree::delete_tree_element(Tree_Element *element) | ||
974 | 248 | { | ||
975 | 249 | if (element != &null_element) | ||
976 | 250 | { | ||
977 | 251 | delete_tree_element(element->left); | ||
978 | 252 | if (free) | ||
979 | 253 | (*free)(element_key(element), free_free, custom_arg); | ||
980 | 254 | delete_tree_element(element->right); | ||
981 | 255 | if (with_delete) | ||
982 | 256 | delete element; | ||
983 | 257 | } | ||
984 | 258 | } | ||
985 | 259 | |||
986 | 260 | int Tree::tree_walk_left_root_right(Tree_Element *element, tree_walk_action action, void *argument) | ||
987 | 433 | { | 261 | { |
988 | 434 | int error; | 262 | int error; |
989 | 435 | if (element->left) /* Not null_element */ | 263 | if (element->left) /* Not null_element */ |
990 | 436 | { | 264 | { |
992 | 437 | if ((error=tree_walk_left_root_right(tree,element->left,action, | 265 | if ((error=tree_walk_left_root_right(element->left,action, |
993 | 438 | argument)) == 0 && | 266 | argument)) == 0 && |
998 | 439 | (error=(*action)(ELEMENT_KEY(tree,element), | 267 | (error=(*action)(element_key(element), element->count, argument)) == 0) |
999 | 440 | element->count, | 268 | error=tree_walk_left_root_right(element->right,action,argument); |
996 | 441 | argument)) == 0) | ||
997 | 442 | error=tree_walk_left_root_right(tree,element->right,action,argument); | ||
1000 | 443 | return error; | 269 | return error; |
1001 | 444 | } | 270 | } |
1002 | 445 | 271 | ||
1003 | 446 | return 0; | 272 | return 0; |
1004 | 447 | } | 273 | } |
1005 | 448 | 274 | ||
1007 | 449 | static int tree_walk_right_root_left(TREE *tree, TREE_ELEMENT *element, tree_walk_action action, void *argument) | 275 | int Tree::tree_walk_right_root_left(Tree_Element *element, tree_walk_action action, void *argument) |
1008 | 450 | { | 276 | { |
1009 | 451 | int error; | 277 | int error; |
1010 | 452 | if (element->right) /* Not null_element */ | 278 | if (element->right) /* Not null_element */ |
1011 | 453 | { | 279 | { |
1013 | 454 | if ((error=tree_walk_right_root_left(tree,element->right,action, | 280 | if ((error=tree_walk_right_root_left(element->right,action, |
1014 | 455 | argument)) == 0 && | 281 | argument)) == 0 && |
1016 | 456 | (error=(*action)(ELEMENT_KEY(tree,element), | 282 | (error=(*action)(element_key(element), |
1017 | 457 | element->count, | 283 | element->count, |
1018 | 458 | argument)) == 0) | 284 | argument)) == 0) |
1020 | 459 | error=tree_walk_right_root_left(tree,element->left,action,argument); | 285 | error=tree_walk_right_root_left(element->left,action,argument); |
1021 | 460 | return error; | 286 | return error; |
1022 | 461 | } | 287 | } |
1023 | 462 | 288 | ||
1024 | 463 | return 0; | 289 | return 0; |
1025 | 464 | } | 290 | } |
1026 | 465 | 291 | ||
1031 | 466 | 292 | void Tree::left_rotate(Tree_Element **parent, Tree_Element *element) | |
1028 | 467 | /* Functions to fix up the tree after insert and delete */ | ||
1029 | 468 | |||
1030 | 469 | static void left_rotate(TREE_ELEMENT **parent, TREE_ELEMENT *leaf) | ||
1032 | 470 | { | 293 | { |
1034 | 471 | TREE_ELEMENT *y; | 294 | Tree_Element *y; |
1035 | 472 | 295 | ||
1038 | 473 | y= leaf->right; | 296 | y= element->right; |
1039 | 474 | leaf->right= y->left; | 297 | element->right= y->left; |
1040 | 475 | parent[0]= y; | 298 | parent[0]= y; |
1042 | 476 | y->left= leaf; | 299 | y->left= element; |
1043 | 477 | } | 300 | } |
1044 | 478 | 301 | ||
1046 | 479 | static void right_rotate(TREE_ELEMENT **parent, TREE_ELEMENT *leaf) | 302 | void Tree::right_rotate(Tree_Element **parent, Tree_Element *element) |
1047 | 480 | { | 303 | { |
1049 | 481 | TREE_ELEMENT *x; | 304 | Tree_Element *x; |
1050 | 482 | 305 | ||
1053 | 483 | x= leaf->left; | 306 | x= element->left; |
1054 | 484 | leaf->left= x->right; | 307 | element->left= x->right; |
1055 | 485 | parent[0]= x; | 308 | parent[0]= x; |
1057 | 486 | x->right= leaf; | 309 | x->right= element; |
1058 | 487 | } | 310 | } |
1059 | 488 | 311 | ||
1061 | 489 | static void rb_insert(TREE *tree, TREE_ELEMENT ***parent, TREE_ELEMENT *leaf) | 312 | void Tree::rb_insert(Tree_Element ***parent, Tree_Element *element) |
1062 | 490 | { | 313 | { |
1064 | 491 | TREE_ELEMENT *y,*par,*par2; | 314 | Tree_Element *y,*par,*par2; |
1065 | 492 | 315 | ||
1068 | 493 | leaf->colour=RED; | 316 | element->colour=RED; |
1069 | 494 | while (leaf != tree->root && (par=parent[-1][0])->colour == RED) | 317 | while (element != root && (par=parent[-1][0])->colour == RED) |
1070 | 495 | { | 318 | { |
1071 | 496 | if (par == (par2=parent[-2][0])->left) | 319 | if (par == (par2=parent[-2][0])->left) |
1072 | 497 | { | 320 | { |
1073 | @@ -500,16 +323,16 @@ | |||
1074 | 500 | { | 323 | { |
1075 | 501 | par->colour= BLACK; | 324 | par->colour= BLACK; |
1076 | 502 | y->colour= BLACK; | 325 | y->colour= BLACK; |
1078 | 503 | leaf= par2; | 326 | element= par2; |
1079 | 504 | parent-= 2; | 327 | parent-= 2; |
1081 | 505 | leaf->colour= RED; /* And the loop continues */ | 328 | element->colour= RED; /* And the loop continues */ |
1082 | 506 | } | 329 | } |
1083 | 507 | else | 330 | else |
1084 | 508 | { | 331 | { |
1086 | 509 | if (leaf == par->right) | 332 | if (element == par->right) |
1087 | 510 | { | 333 | { |
1088 | 511 | left_rotate(parent[-1],par); | 334 | left_rotate(parent[-1],par); |
1090 | 512 | par= leaf; /* leaf is now parent to old leaf */ | 335 | par= element; /* element is now parent to old element */ |
1091 | 513 | } | 336 | } |
1092 | 514 | par->colour= BLACK; | 337 | par->colour= BLACK; |
1093 | 515 | par2->colour= RED; | 338 | par2->colour= RED; |
1094 | @@ -524,16 +347,16 @@ | |||
1095 | 524 | { | 347 | { |
1096 | 525 | par->colour= BLACK; | 348 | par->colour= BLACK; |
1097 | 526 | y->colour= BLACK; | 349 | y->colour= BLACK; |
1099 | 527 | leaf= par2; | 350 | element= par2; |
1100 | 528 | parent-= 2; | 351 | parent-= 2; |
1102 | 529 | leaf->colour= RED; /* And the loop continues */ | 352 | element->colour= RED; /* And the loop continues */ |
1103 | 530 | } | 353 | } |
1104 | 531 | else | 354 | else |
1105 | 532 | { | 355 | { |
1107 | 533 | if (leaf == par->left) | 356 | if (element == par->left) |
1108 | 534 | { | 357 | { |
1109 | 535 | right_rotate(parent[-1],par); | 358 | right_rotate(parent[-1],par); |
1111 | 536 | par= leaf; | 359 | par= element; |
1112 | 537 | } | 360 | } |
1113 | 538 | par->colour= BLACK; | 361 | par->colour= BLACK; |
1114 | 539 | par2->colour= RED; | 362 | par2->colour= RED; |
1115 | @@ -542,7 +365,7 @@ | |||
1116 | 542 | } | 365 | } |
1117 | 543 | } | 366 | } |
1118 | 544 | } | 367 | } |
1120 | 545 | tree->root->colour=BLACK; | 368 | root->colour=BLACK; |
1121 | 546 | } | 369 | } |
1122 | 547 | 370 | ||
1123 | 548 | } /* namespace drizzled */ | 371 | } /* namespace drizzled */ |
1124 | 549 | 372 | ||
1125 | === modified file 'drizzled/tree.h' | |||
1126 | --- drizzled/tree.h 2011-03-14 05:40:28 +0000 | |||
1127 | +++ drizzled/tree.h 2011-12-24 17:41:25 +0000 | |||
1128 | @@ -17,14 +17,14 @@ | |||
1129 | 17 | 17 | ||
1130 | 18 | #include <unistd.h> | 18 | #include <unistd.h> |
1131 | 19 | 19 | ||
1133 | 20 | #include <drizzled/base.h> /* get 'enum ha_rkey_function' */ | 20 | #include <drizzled/base.h> // for 'enum ha_rkey_function' |
1134 | 21 | #include <drizzled/memory/root.h> | ||
1135 | 21 | #include <drizzled/qsort_cmp.h> | 22 | #include <drizzled/qsort_cmp.h> |
1136 | 22 | #include <drizzled/memory/root.h> | ||
1137 | 23 | 23 | ||
1138 | 24 | namespace drizzled | 24 | namespace drizzled |
1139 | 25 | { | 25 | { |
1140 | 26 | 26 | ||
1142 | 27 | /* Worst case tree is half full. This gives use 2^(MAX_TREE_HEIGHT/2) leafs */ | 27 | // Worst case tree is half full. This gives us 2^(MAX_TREE_HEIGHT/2) leaves |
1143 | 28 | static const int MAX_TREE_HEIGHT= 64; | 28 | static const int MAX_TREE_HEIGHT= 64; |
1144 | 29 | 29 | ||
1145 | 30 | static const int TREE_NO_DUPS= 1; | 30 | static const int TREE_NO_DUPS= 1; |
1146 | @@ -35,56 +35,77 @@ | |||
1147 | 35 | typedef enum { free_init, free_free, free_end } TREE_FREE; | 35 | typedef enum { free_init, free_free, free_end } TREE_FREE; |
1148 | 36 | typedef void (*tree_element_free)(void*, TREE_FREE, void *); | 36 | typedef void (*tree_element_free)(void*, TREE_FREE, void *); |
1149 | 37 | 37 | ||
1200 | 38 | typedef struct st_tree_element { | 38 | |
1201 | 39 | struct st_tree_element *left,*right; | 39 | class Tree_Element |
1202 | 40 | uint32_t count:31, | 40 | { |
1203 | 41 | colour:1; /* black is marked as 1 */ | 41 | public: |
1204 | 42 | } TREE_ELEMENT; | 42 | Tree_Element *left,*right; |
1205 | 43 | 43 | uint32_t count:31, | |
1206 | 44 | static const int TREE_ELEMENT_EXTRA_SIZE= (sizeof(TREE_ELEMENT) + sizeof(void*)); | 44 | colour:1; /* black is marked as 1 */ |
1207 | 45 | 45 | }; | |
1208 | 46 | 46 | ||
1209 | 47 | typedef struct st_tree { | 47 | static const int TREE_ELEMENT_EXTRA_SIZE= (sizeof(Tree_Element) + sizeof(void*)); |
1210 | 48 | TREE_ELEMENT *root,null_element; | 48 | |
1211 | 49 | TREE_ELEMENT **parents[MAX_TREE_HEIGHT]; | 49 | /** |
1212 | 50 | uint32_t offset_to_key, elements_in_tree, size_of_element; | 50 | * red-black binary tree class |
1213 | 51 | size_t memory_limit; | 51 | * |
1214 | 52 | size_t allocated; | 52 | * NOTE: unused search code removed 11/2011 |
1215 | 53 | qsort_cmp2 compare; | 53 | */ |
1216 | 54 | void *custom_arg; | 54 | class Tree |
1217 | 55 | memory::Root mem_root; | 55 | { |
1218 | 56 | bool with_delete; | 56 | private: |
1219 | 57 | tree_element_free free; | 57 | Tree_Element *root, null_element; |
1220 | 58 | uint32_t flag; | 58 | void *custom_arg; |
1221 | 59 | } TREE; | 59 | Tree_Element **parents[MAX_TREE_HEIGHT]; |
1222 | 60 | 60 | uint32_t offset_to_key, elements_in_tree, size_of_element; | |
1223 | 61 | /* Functions on whole tree */ | 61 | size_t memory_limit; |
1224 | 62 | void init_tree(TREE *tree, size_t default_alloc_size, uint32_t memory_limit, | 62 | size_t allocated; |
1225 | 63 | uint32_t size, qsort_cmp2 compare, bool with_delete, | 63 | qsort_cmp2 compare; |
1226 | 64 | tree_element_free free_element, void *custom_arg); | 64 | memory::Root mem_root; |
1227 | 65 | void delete_tree(TREE*); | 65 | bool with_delete; |
1228 | 66 | void reset_tree(TREE*); | 66 | tree_element_free free; |
1229 | 67 | 67 | uint32_t flag; | |
1230 | 68 | /* | 68 | |
1231 | 69 | similar to delete tree, except we do not free() blocks in mem_root | 69 | public: |
1232 | 70 | */ | 70 | void* getCustomArg() { |
1233 | 71 | #define is_tree_inited(tree) ((tree)->root != 0) | 71 | return custom_arg; |
1234 | 72 | 72 | } | |
1235 | 73 | /* Functions on leafs */ | 73 | Tree_Element* getRoot() { |
1236 | 74 | TREE_ELEMENT *tree_insert(TREE *tree,void *key, uint32_t key_size, | 74 | return root; |
1237 | 75 | void *custom_arg); | 75 | } |
1238 | 76 | int tree_walk(TREE *tree,tree_walk_action action, | 76 | void setRoot(Tree_Element* root_arg) { |
1239 | 77 | void *argument, TREE_WALK visit); | 77 | root = root_arg; |
1240 | 78 | int tree_delete(TREE *tree, void *key, uint32_t key_size, void *custom_arg); | 78 | } |
1241 | 79 | void *tree_search_key(TREE *tree, const void *key, | 79 | uint32_t getElementsInTree() { |
1242 | 80 | TREE_ELEMENT **parents, TREE_ELEMENT ***last_pos, | 80 | return elements_in_tree; |
1243 | 81 | enum ha_rkey_function flag, void *custom_arg); | 81 | } |
1244 | 82 | void *tree_search_edge(TREE *tree, TREE_ELEMENT **parents, | 82 | // tree methods |
1245 | 83 | TREE_ELEMENT ***last_pos, int child_offs); | 83 | void init_tree(size_t default_alloc_size, uint32_t memory_limit, |
1246 | 84 | void *tree_search_next(TREE *tree, TREE_ELEMENT ***last_pos, int l_offs, | 84 | uint32_t size, qsort_cmp2 compare, bool with_delete, |
1247 | 85 | int r_offs); | 85 | tree_element_free free_element, void *custom_arg); |
1248 | 86 | ha_rows tree_record_pos(TREE *tree, const void *key, | 86 | bool is_inited() |
1249 | 87 | enum ha_rkey_function search_flag, void *custom_arg); | 87 | { |
1250 | 88 | return this->root != 0; | ||
1251 | 89 | } | ||
1252 | 90 | void delete_tree(); | ||
1253 | 91 | void reset_tree(); | ||
1254 | 92 | |||
1255 | 93 | // element methods | ||
1256 | 94 | Tree_Element *tree_insert(void *key, uint32_t key_size, void *custom_arg); | ||
1257 | 95 | int tree_walk(tree_walk_action action, void *argument, TREE_WALK visit); | ||
1258 | 96 | |||
1259 | 97 | private: | ||
1260 | 98 | void free_tree(myf free_flags); | ||
1261 | 99 | |||
1262 | 100 | void* element_key(Tree_Element* element); | ||
1263 | 101 | void delete_tree_element(Tree_Element* element); | ||
1264 | 102 | int tree_walk_left_root_right(Tree_Element* element, tree_walk_action action, void* argument); | ||
1265 | 103 | int tree_walk_right_root_left(Tree_Element* element, tree_walk_action action, void* argument); | ||
1266 | 104 | |||
1267 | 105 | void left_rotate(Tree_Element **parent,Tree_Element *element); | ||
1268 | 106 | void right_rotate(Tree_Element **parent, Tree_Element *element); | ||
1269 | 107 | void rb_insert(Tree_Element ***parent, Tree_Element *element); | ||
1270 | 108 | }; | ||
1271 | 88 | 109 | ||
1272 | 89 | } /* namespace drizzled */ | 110 | } /* namespace drizzled */ |
1273 | 90 | 111 | ||
1274 | 91 | 112 | ||
1275 | === modified file 'drizzled/unique.cc' | |||
1276 | --- drizzled/unique.cc 2011-03-19 17:01:16 +0000 | |||
1277 | +++ drizzled/unique.cc 2011-12-24 17:41:25 +0000 | |||
1278 | @@ -62,7 +62,7 @@ | |||
1279 | 62 | elements(0) | 62 | elements(0) |
1280 | 63 | { | 63 | { |
1281 | 64 | // Second element is max size for memory use in unique sort | 64 | // Second element is max size for memory use in unique sort |
1283 | 65 | init_tree(&tree, 0, 0, size, comp_func, false, | 65 | tree.init_tree(0, 0, size, comp_func, false, |
1284 | 66 | NULL, comp_func_fixed_arg); | 66 | NULL, comp_func_fixed_arg); |
1285 | 67 | } | 67 | } |
1286 | 68 | 68 | ||
1287 | @@ -146,7 +146,7 @@ | |||
1288 | 146 | double result; | 146 | double result; |
1289 | 147 | 147 | ||
1290 | 148 | max_elements_in_tree= ((ulong) max_in_memory_size_arg / | 148 | max_elements_in_tree= ((ulong) max_in_memory_size_arg / |
1292 | 149 | ALIGN_SIZE(sizeof(TREE_ELEMENT)+key_size)); | 149 | ALIGN_SIZE(sizeof(Tree_Element)+key_size)); |
1293 | 150 | 150 | ||
1294 | 151 | last_tree_elems= nkeys % max_elements_in_tree; | 151 | last_tree_elems= nkeys % max_elements_in_tree; |
1295 | 152 | 152 | ||
1296 | @@ -159,7 +159,7 @@ | |||
1297 | 159 | 159 | ||
1298 | 160 | Unique::~Unique() | 160 | Unique::~Unique() |
1299 | 161 | { | 161 | { |
1301 | 162 | delete_tree(&tree); | 162 | tree.delete_tree(); |
1302 | 163 | } | 163 | } |
1303 | 164 | 164 | ||
1304 | 165 | 165 | ||
1305 | @@ -171,7 +171,7 @@ | |||
1306 | 171 | void | 171 | void |
1307 | 172 | Unique::reset() | 172 | Unique::reset() |
1308 | 173 | { | 173 | { |
1310 | 174 | reset_tree(&tree); | 174 | tree.reset_tree(); |
1311 | 175 | assert(elements == 0); | 175 | assert(elements == 0); |
1312 | 176 | } | 176 | } |
1313 | 177 | 177 | ||
1314 | @@ -198,7 +198,7 @@ | |||
1315 | 198 | 198 | ||
1316 | 199 | bool Unique::walk(tree_walk_action action, void *walk_action_arg) | 199 | bool Unique::walk(tree_walk_action action, void *walk_action_arg) |
1317 | 200 | { | 200 | { |
1319 | 201 | return tree_walk(&tree, action, walk_action_arg, left_root_right); | 201 | return tree.tree_walk(action, walk_action_arg, left_root_right); |
1320 | 202 | } | 202 | } |
1321 | 203 | 203 | ||
1322 | 204 | /* | 204 | /* |
1323 | @@ -208,12 +208,12 @@ | |||
1324 | 208 | 208 | ||
1325 | 209 | bool Unique::get(Table *table) | 209 | bool Unique::get(Table *table) |
1326 | 210 | { | 210 | { |
1328 | 211 | table->sort.found_records= elements+tree.elements_in_tree; | 211 | table->sort.found_records= elements+tree.getElementsInTree(); |
1329 | 212 | 212 | ||
1330 | 213 | if ((record_pointers=table->sort.record_pointers= (unsigned char*) | 213 | if ((record_pointers=table->sort.record_pointers= (unsigned char*) |
1332 | 214 | malloc(size * tree.elements_in_tree))) | 214 | malloc(size * tree.getElementsInTree()))) |
1333 | 215 | { | 215 | { |
1335 | 216 | (void) tree_walk(&tree, (tree_walk_action) unique_write_to_ptrs, | 216 | (void) tree.tree_walk((tree_walk_action) unique_write_to_ptrs, |
1336 | 217 | this, left_root_right); | 217 | this, left_root_right); |
1337 | 218 | return 0; | 218 | return 0; |
1338 | 219 | } | 219 | } |
1339 | 220 | 220 | ||
1340 | === modified file 'drizzled/unique.h' | |||
1341 | --- drizzled/unique.h 2011-04-29 00:19:38 +0000 | |||
1342 | +++ drizzled/unique.h 2011-12-24 17:41:25 +0000 | |||
1343 | @@ -40,7 +40,7 @@ | |||
1344 | 40 | class Unique : public memory::SqlAlloc | 40 | class Unique : public memory::SqlAlloc |
1345 | 41 | { | 41 | { |
1346 | 42 | size_t max_in_memory_size; | 42 | size_t max_in_memory_size; |
1348 | 43 | TREE tree; | 43 | Tree tree; |
1349 | 44 | unsigned char *record_pointers; | 44 | unsigned char *record_pointers; |
1350 | 45 | uint32_t size; | 45 | uint32_t size; |
1351 | 46 | 46 | ||
1352 | @@ -49,10 +49,10 @@ | |||
1353 | 49 | Unique(qsort_cmp2 comp_func, void *comp_func_fixed_arg, | 49 | Unique(qsort_cmp2 comp_func, void *comp_func_fixed_arg, |
1354 | 50 | uint32_t size_arg, size_t max_in_memory_size_arg); | 50 | uint32_t size_arg, size_t max_in_memory_size_arg); |
1355 | 51 | ~Unique(); | 51 | ~Unique(); |
1357 | 52 | ulong elements_in_tree() { return tree.elements_in_tree; } | 52 | ulong elements_in_tree() { return tree.getElementsInTree(); } |
1358 | 53 | inline bool unique_add(void *ptr) | 53 | inline bool unique_add(void *ptr) |
1359 | 54 | { | 54 | { |
1361 | 55 | return (not tree_insert(&tree, ptr, 0, tree.custom_arg)); | 55 | return (not tree.tree_insert(ptr, 0, tree.getCustomArg())); |
1362 | 56 | } | 56 | } |
1363 | 57 | 57 | ||
1364 | 58 | bool get(Table *table); | 58 | bool get(Table *table); |
1365 | @@ -62,7 +62,7 @@ | |||
1366 | 62 | size_t sortbuff_size) | 62 | size_t sortbuff_size) |
1367 | 63 | { | 63 | { |
1368 | 64 | register size_t max_elems_in_tree= | 64 | register size_t max_elems_in_tree= |
1370 | 65 | (1 + sortbuff_size / ALIGN_SIZE(sizeof(TREE_ELEMENT)+key_size)); | 65 | (1 + sortbuff_size / ALIGN_SIZE(sizeof(Tree_Element)+key_size)); |
1371 | 66 | return (int) (sizeof(uint32_t)*(1 + nkeys/max_elems_in_tree)); | 66 | return (int) (sizeof(uint32_t)*(1 + nkeys/max_elems_in_tree)); |
1372 | 67 | } | 67 | } |
1373 | 68 | 68 | ||
1374 | 69 | 69 | ||
1375 | === modified file 'plugin/myisam/mi_write.cc' | |||
1376 | --- plugin/myisam/mi_write.cc 2011-02-17 00:14:13 +0000 | |||
1377 | +++ plugin/myisam/mi_write.cc 2011-12-24 17:41:25 +0000 | |||
1378 | @@ -19,6 +19,7 @@ | |||
1379 | 19 | 19 | ||
1380 | 20 | #include <drizzled/internal/m_string.h> | 20 | #include <drizzled/internal/m_string.h> |
1381 | 21 | #include <drizzled/util/test.h> | 21 | #include <drizzled/util/test.h> |
1382 | 22 | #include <drizzled/tree.h> | ||
1383 | 22 | 23 | ||
1384 | 23 | using namespace drizzled; | 24 | using namespace drizzled; |
1385 | 24 | 25 | ||
1386 | @@ -97,7 +98,7 @@ | |||
1387 | 97 | { | 98 | { |
1388 | 98 | bool local_lock_tree= (lock_tree && | 99 | bool local_lock_tree= (lock_tree && |
1389 | 99 | !(info->bulk_insert && | 100 | !(info->bulk_insert && |
1391 | 100 | is_tree_inited(&info->bulk_insert[i]))); | 101 | info->bulk_insert[i].is_inited())); |
1392 | 101 | if (local_lock_tree) | 102 | if (local_lock_tree) |
1393 | 102 | { | 103 | { |
1394 | 103 | share->keyinfo[i].version++; | 104 | share->keyinfo[i].version++; |
1395 | @@ -188,7 +189,7 @@ | |||
1396 | 188 | 189 | ||
1397 | 189 | int _mi_ck_write(MI_INFO *info, uint32_t keynr, unsigned char *key, uint32_t key_length) | 190 | int _mi_ck_write(MI_INFO *info, uint32_t keynr, unsigned char *key, uint32_t key_length) |
1398 | 190 | { | 191 | { |
1400 | 191 | if (info->bulk_insert && is_tree_inited(&info->bulk_insert[keynr])) | 192 | if (info->bulk_insert && info->bulk_insert[keynr].is_inited()) |
1401 | 192 | { | 193 | { |
1402 | 193 | return(_mi_ck_write_tree(info, keynr, key, key_length)); | 194 | return(_mi_ck_write_tree(info, keynr, key, key_length)); |
1403 | 194 | } | 195 | } |
1404 | @@ -716,9 +717,9 @@ | |||
1405 | 716 | { | 717 | { |
1406 | 717 | int error; | 718 | int error; |
1407 | 718 | 719 | ||
1409 | 719 | error= tree_insert(&info->bulk_insert[keynr], key, | 720 | error= info->bulk_insert[keynr].tree_insert(key, |
1410 | 720 | key_length + info->s->rec_reflength, | 721 | key_length + info->s->rec_reflength, |
1412 | 721 | info->bulk_insert[keynr].custom_arg) ? 0 : HA_ERR_OUT_OF_MEM ; | 722 | info->bulk_insert[keynr].getCustomArg()) ? 0 : HA_ERR_OUT_OF_MEM ; |
1413 | 722 | 723 | ||
1414 | 723 | return(error); | 724 | return(error); |
1415 | 724 | } /* _mi_ck_write_tree */ | 725 | } /* _mi_ck_write_tree */ |
1416 | @@ -797,8 +798,7 @@ | |||
1417 | 797 | else | 798 | else |
1418 | 798 | cache_size/=total_keylength*16; | 799 | cache_size/=total_keylength*16; |
1419 | 799 | 800 | ||
1422 | 800 | info->bulk_insert=(TREE *) | 801 | info->bulk_insert=(Tree *) malloc((sizeof(Tree)*share->base.keys+ |
1421 | 801 | malloc((sizeof(TREE)*share->base.keys+ | ||
1423 | 802 | sizeof(bulk_insert_param)*num_keys)); | 802 | sizeof(bulk_insert_param)*num_keys)); |
1424 | 803 | 803 | ||
1425 | 804 | if (!info->bulk_insert) | 804 | if (!info->bulk_insert) |
1426 | @@ -812,14 +812,13 @@ | |||
1427 | 812 | params->info=info; | 812 | params->info=info; |
1428 | 813 | params->keynr=i; | 813 | params->keynr=i; |
1429 | 814 | /* Only allocate a 16'th of the buffer at a time */ | 814 | /* Only allocate a 16'th of the buffer at a time */ |
1432 | 815 | init_tree(&info->bulk_insert[i], | 815 | info->bulk_insert[i].init_tree(cache_size * key[i].maxlength, |
1431 | 816 | cache_size * key[i].maxlength, | ||
1433 | 817 | cache_size * key[i].maxlength, 0, | 816 | cache_size * key[i].maxlength, 0, |
1434 | 818 | (qsort_cmp2)keys_compare, false, | 817 | (qsort_cmp2)keys_compare, false, |
1435 | 819 | (tree_element_free) keys_free, (void *)params++); | 818 | (tree_element_free) keys_free, (void *)params++); |
1436 | 820 | } | 819 | } |
1437 | 821 | else | 820 | else |
1439 | 822 | info->bulk_insert[i].root=0; | 821 | info->bulk_insert[i].setRoot(0); |
1440 | 823 | } | 822 | } |
1441 | 824 | 823 | ||
1442 | 825 | return(0); | 824 | return(0); |
1443 | @@ -829,8 +828,8 @@ | |||
1444 | 829 | { | 828 | { |
1445 | 830 | if (info->bulk_insert) | 829 | if (info->bulk_insert) |
1446 | 831 | { | 830 | { |
1449 | 832 | if (is_tree_inited(&info->bulk_insert[inx])) | 831 | if (info->bulk_insert[inx].is_inited()) |
1450 | 833 | reset_tree(&info->bulk_insert[inx]); | 832 | info->bulk_insert[inx].reset_tree(); |
1451 | 834 | } | 833 | } |
1452 | 835 | } | 834 | } |
1453 | 836 | 835 | ||
1454 | @@ -841,9 +840,9 @@ | |||
1455 | 841 | uint32_t i; | 840 | uint32_t i; |
1456 | 842 | for (i=0 ; i < info->s->base.keys ; i++) | 841 | for (i=0 ; i < info->s->base.keys ; i++) |
1457 | 843 | { | 842 | { |
1459 | 844 | if (is_tree_inited(& info->bulk_insert[i])) | 843 | if (info->bulk_insert[i].is_inited()) |
1460 | 845 | { | 844 | { |
1462 | 846 | delete_tree(& info->bulk_insert[i]); | 845 | info->bulk_insert[i].delete_tree(); |
1463 | 847 | } | 846 | } |
1464 | 848 | } | 847 | } |
1465 | 849 | free((void *)info->bulk_insert); | 848 | free((void *)info->bulk_insert); |
1466 | 850 | 849 | ||
1467 | === modified file 'plugin/myisam/myisam_priv.h' | |||
1468 | --- plugin/myisam/myisam_priv.h 2011-08-22 13:44:06 +0000 | |||
1469 | +++ plugin/myisam/myisam_priv.h 2011-12-24 17:41:25 +0000 | |||
1470 | @@ -21,7 +21,8 @@ | |||
1471 | 21 | 21 | ||
1472 | 22 | #include "myisam.h" /* Structs & some defines */ | 22 | #include "myisam.h" /* Structs & some defines */ |
1473 | 23 | #include "myisampack.h" /* packing of keys */ | 23 | #include "myisampack.h" /* packing of keys */ |
1475 | 24 | #include <drizzled/tree.h> | 24 | #include <drizzled/memory/root.h> |
1476 | 25 | |||
1477 | 25 | #include <drizzled/internal/my_pthread.h> | 26 | #include <drizzled/internal/my_pthread.h> |
1478 | 26 | #include <drizzled/thr_lock.h> | 27 | #include <drizzled/thr_lock.h> |
1479 | 27 | #include <drizzled/common.h> | 28 | #include <drizzled/common.h> |
1480 | @@ -36,6 +37,10 @@ | |||
1481 | 36 | 37 | ||
1482 | 37 | #include <boost/thread/mutex.hpp> | 38 | #include <boost/thread/mutex.hpp> |
1483 | 38 | 39 | ||
1484 | 40 | namespace drizzled { | ||
1485 | 41 | class Tree; | ||
1486 | 42 | } | ||
1487 | 43 | |||
1488 | 39 | #if defined(my_write) | 44 | #if defined(my_write) |
1489 | 40 | #undef my_write /* undef map from my_nosys; We need test-if-disk full */ | 45 | #undef my_write /* undef map from my_nosys; We need test-if-disk full */ |
1490 | 41 | #endif | 46 | #endif |
1491 | @@ -249,7 +254,7 @@ | |||
1492 | 249 | MI_BLOB *blobs; /* Pointer to blobs */ | 254 | MI_BLOB *blobs; /* Pointer to blobs */ |
1493 | 250 | MI_BIT_BUFF bit_buff; | 255 | MI_BIT_BUFF bit_buff; |
1494 | 251 | /* accumulate indexfile changes between write's */ | 256 | /* accumulate indexfile changes between write's */ |
1496 | 252 | drizzled::TREE *bulk_insert; | 257 | drizzled::Tree *bulk_insert; |
1497 | 253 | drizzled::Session *in_use; /* Thread using this table */ | 258 | drizzled::Session *in_use; /* Thread using this table */ |
1498 | 254 | char *filename; /* parameter to open filename */ | 259 | char *filename; /* parameter to open filename */ |
1499 | 255 | unsigned char *buff, /* Temp area for key */ | 260 | unsigned char *buff, /* Temp area for key */ |
+ void* getCustomArg() {
Hi Mark,
I think indentation is too much and the brace should be on the next line.
Greetings,