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