Merge lp:~ivolucien/drizzle/trunk-bug-621861 into lp:~drizzle-trunk/drizzle/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
Reviewer Review Type Date Requested Status
Mark Atwood Pending
Review via email: mp+86857@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Olaf van der Spek (olafvdspek) wrote :

+ void* getCustomArg() {

Hi Mark,

I think indentation is too much and the brace should be on the next line.

Greetings,

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file '.bzrignore'
--- .bzrignore 1970-01-01 00:00:00 +0000
+++ .bzrignore 2011-12-24 17:41:25 +0000
@@ -0,0 +1,386 @@
1*.bb
2*.bbg
3*.da
4*.dirstamp
5*.gcda
6*.gcno
7*.gmo
8*.gz
9*.la
10*.linted
11*.lo
12*.orig
13*.rej
14*.reject
15*.rpm
16*replication.pb.*
17*stamp-h
18./ChangeLog
19.DS_Store
20.deps
21.libs
22.plugin.ini.stamp
23.plugin.scan
24ChangeLog
25DEPENDENCIES
26INSTALL
27Makefile
28Makefile.in
29TAGS
30aclocal.m4
31authentication.gcno
32autom4te.cache/
33cached_item.gcno
34calendar.gcno
35check_stack_overrun.gcno
36client/Makefile.in
37client/drizzle
38client/drizzleadmin
39client/drizzlebinlog
40client/drizzlecheck
41client/drizzledump
42client/drizzleimport
43client/drizzleslap
44client/drizzletest
45client/mysqlslap
46comp_creator.gcno
47compile
48config.guess
49config.h
50config.h.gch
51config.h.in
52config.log
53config.status
54config.sub
55config/bzr_revinfo
56config/pandora-plugin.list
57config/pandora_vc_revinfo
58config/plugin-list.ac
59config/plugin-list.am
60config/plugin.ac
61config/plugin.am
62config/plugin.list
63config/plugin.stamp
64config/top.h
65configure
66configvar.gcno
67current_session.gcno
68dbug/Makefile.in
69depcomp
70docs
71docs/doctrees
72docs/html
73docs/plugins/*
74docs/plugins/list.rst
75doxerr.log
76drizzle-2010.01.1315.tar.gz
77drizzle.pot
78drizzled.gcno
79drizzled/configmake.h
80drizzled/drizzled
81drizzled/drizzled_safe
82drizzled/function_hash.h
83drizzled/gen_lex_hash
84drizzled/generated_probes.h
85drizzled/lex_hash.h
86drizzled/message/alter_table.pb.cc
87drizzled/message/alter_table.pb.h
88drizzled/message/binary_log.pb.cc
89drizzled/message/binary_log.pb.h
90drizzled/message/binlog_reader
91drizzled/message/binlog_writer
92drizzled/message/command_reader
93drizzled/message/engine.pb.cc
94drizzled/message/engine.pb.h
95drizzled/message/event.pb.cc
96drizzled/message/event.pb.h
97drizzled/message/length
98drizzled/message/replication.pb.cc
99drizzled/message/replication.pb.h
100drizzled/message/replication_event.pb.cc
101drizzled/message/replication_event.pb.h
102drizzled/message/replication_event_reader
103drizzled/message/replication_event_writer
104drizzled/message/resultset.pb.cc
105drizzled/message/resultset.pb.h
106drizzled/message/schema.pb.cc
107drizzled/message/schema.pb.h
108drizzled/message/schema_reader
109drizzled/message/schema_writer
110drizzled/message/table.pb.cc
111drizzled/message/table.pb.h
112drizzled/message/table_raw_reader
113drizzled/message/table_reader
114drizzled/message/table_writer
115drizzled/message/transaction.pb.cc
116drizzled/message/transaction.pb.h
117drizzled/message/transaction_writer
118drizzled/module/load_list.h
119drizzled/plugin/version.h
120drizzled/schema.pb.cc
121drizzled/schema.pb.h
122drizzled/sql_builtin.cc
123drizzled/sql_yacc.cc
124drizzled/sql_yacc.h
125drizzled/sql_yacc.output
126drizzled/sql_reserved_words.h
127drizzled/symbol_hash.h
128drizzled/version.h
129dtcollation.gcno
130errmsg.gcno
131errmsg_print.gcno
132error.gcno
133examples/client
134examples/pipe_query
135examples/proxy
136examples/server
137examples/simple
138examples/simple_multi
139examples/sqlite_server
140extra/Makefile.in
141extra/comp_err
142extra/innochecksum
143extra/my_print_defaults
144extra/mysql_waitpid
145field.gcno
146field_conv.gcno
147field_iterator.gcno
148filesort.gcno
149gnulib/getopt.h
150gnulib/time.h
151gnulib/unistd.h
152ha_trx_info.gcno
153handler.gcno
154handlerton.gcno
155hybrid_type_traits.gcno
156hybrid_type_traits_decimal.gcno
157hybrid_type_traits_integer.gcno
158include/Makefile.in
159include/config.h
160include/drizzle_version.h
161include/mysqld_ername.h
162include/mysqld_error.h
163include/sql_state.h
164include/stamp-h1
165install-sh
166item.gcno
167key.gcno
168key_map.gcno
169libdrizzle-2.0/libdrizzle/mysql_password_hash
170libdrizzle-2.0/libdrizzle/drizzle_password_hash
171libmysql/Makefile.in
172libserialutil_la-db.gcno
173libserialutil_la-unireg.gcno
174libtool
175lint-rules.am
176lock.gcno
177log.gcno
178logging.gcno
179ltmain.sh
180m4/bzr_version.m4
181m4/libtool.m4
182m4/ltoptions.m4
183m4/ltsugar.m4
184m4/ltversion.m4
185m4/lt~obsolete.m4
186mf_iocache.gcno
187missing
188my_decimal.gcno
189mysql-test/Makefile.in
190mysys/Makefile.in
191mysys/tests/Makefile.in
192name_resolution_context_state.gcno
193natural_join_column.gcno
194opt_range.gcno
195opt_sum.gcno
196out
197pandora-plugin.ac
198pandora-plugin.am
199parser.gcno
200patch
201plugin/Makefile.in
202plugin/archive/Makefile.in
203plugin/archive/archive_performance
204plugin/archive/archive_reader
205plugin/archive/archive_test
206plugin/archive/concurrency_test
207plugin/blackhole/Makefile.in
208plugin/csv/Makefile.in
209plugin/heap/Makefile.in
210plugin/innobase/Makefile.in
211plugin/innobase/include/pars0grm.hh
212plugin/innobase/include/pars0grm.h
213plugin/innobase/pars/pars0grm.c
214plugin/innobase/pars/pars0grm.cc
215plugin/innobase/pars/pars0grm.h
216plugin/innobase/pars/pars0lex.c
217plugin/memcached_functions/start_mc.sh
218plugin/memcached_functions/tests/start_mc.sh
219plugin/myisam/Makefile.in
220plugin/myisam/myisamchk
221plugin/myisam/myisamlog
222plugin/myisam/myisampack
223plugin/storage_engine_api_tester/cursor_states_to_dot
224plugin/storage_engine_api_tester/engine_states_to_dot
225plugin/transaction_log/utilities/drizzletrx
226po/POTFILES
227po/drizzle7.pot
228po/remove-potcdate.sed
229po/stamp-it
230po/stamp-po
231protocol.gcno
232qcache.gcno
233query_id.gcno
234records.gcno
235regex/Makefile.in
236rename.gcno
237replicator.gcno
238scheduling.gcno
239scripts/Makefile.in
240server/drizzled_safe
241server/gen_lex_hash
242server/lex_hash.h
243server/share/czech/
244server/share/danish/
245server/share/dutch/
246server/share/english/
247server/share/estonian/
248server/share/french/
249server/share/german/
250server/share/greek/
251server/share/hungarian/
252server/share/italian/
253server/share/japanese-sjis/
254server/share/japanese/
255server/share/korean/
256server/share/norwegian-ny/
257server/share/norwegian/
258server/share/polish/
259server/share/portuguese/
260server/share/romanian/
261server/share/russian/
262server/share/serbian/
263server/share/slovak/
264server/share/spanish/
265server/share/swedish/
266server/share/ukrainian/
267server/sql_yacc.cc
268server/sql_yacc.h
269server/sql_yacc.output
270session.gcno
271set_var.gcno
272show.gcno
273sj_tmp_table.gcno
274sql-common/Makefile.in
275sql/Makefile.in
276sql/share/Makefile.in
277sql_base.gcno
278sql_client.gcno
279sql_connect.gcno
280sql_delete.gcno
281sql_derived.gcno
282sql_error.gcno
283sql_handler.gcno
284sql_insert.gcno
285sql_lex.gcno
286sql_list.gcno
287sql_load.gcno
288sql_locale.gcno
289sql_parse.gcno
290sql_plugin.gcno
291sql_select.gcno
292sql_state.gcno
293sql_string.gcno
294sql_table.gcno
295sql_udf.gcno
296sql_union.gcno
297sql_update.gcno
298sql_yacc.gcno
299stacktrace.gcno
300stamp-h1
301strfunc.gcno
302strings/Makefile.in
303strings/tests/Makefile.in
304support-files/Makefile.in
305support-files/drizzle-log-rotate
306support-files/drizzle7.pc
307support-files/drizzle.server
308support-files/drizzle.spec
309support-files/libdrizzle.pc
310support-files/libdrizzle-1.0.pc
311support-files/libdrizzle-2.0.pc
312support-files/libdrizzleclient.pc
313support-files/smf/Makefile.in
314support-files/smf/drizzle
315support-files/smf/drizzle.xml
316support-files/smf/install.sh
317table.gcno
318table_map_iterator.gcno
319temporal.gcno
320temporal_format.gcno
321tests/Makefile.in
322tests/dtr
323tests/dtr@
324tests/dbqp
325tests/dbqp_data/uuid
326tests/dbqp_work
327tests/install_test_db
328tests/mtr
329tests/mtr@
330tests/resolve_stack_dump
331tests/stripped_log
332tests/test-run
333tests/test-run@
334tests/total_warning_count
335tests/var
336tests/workdir
337thr_malloc.gcno
338time.gcno
339tmp_table.gcno
340tztime.gcno
341uniques.gcno
342unittests/atomics_test
343unittests/calendar_test
344unittests/unittests
345unittests/uwagi.txt
346virtual_column_info.gcno
347xid.gcno
348ylwrap
349docs/html
350docs/dirhtml
351docs/singlehtml
352docs/pickle
353docs/json
354docs/htmlhelp
355docs/qthelp
356docs/devhelp
357docs/epub
358docs/latex
359docs/latexpdf
360docs/text
361docs/man
362docs/changes
363docs/linkcheck
364docs/doctest
365.pc
366drizzled/message/catalog.pb.cc
367drizzled/message/catalog.pb.h
368drizzled/message/catalog_reader
369drizzled/message/catalog_writer
370drizzled/message/replication_options.pb.cc
371drizzled/message/replication_options.pb.h
372drizzled/message/access.pb.cc
373drizzled/message/access.pb.h
374drizzled/execute/parser.cc
375drizzled/execute/parser.h
376drizzled/execute/parser.output
377drizzled/execute/scanner.cc
378drizzled/execute/scanner.h
379plugin/innobase/xtrabackup/drizzlebackup.innobase
380libdrizzle-2.0/drizzle_password_hash
381libdrizzle-2.0/mysql_password_hash
382.autotools
383.cproject
384.metadata
385.project
386.settings
0387
=== renamed file '.bzrignore' => '.bzrignore.THIS'
=== modified file 'drizzled/item/sum.cc'
--- drizzled/item/sum.cc 2011-10-19 09:25:53 +0000
+++ drizzled/item/sum.cc 2011-12-24 17:41:25 +0000
@@ -3048,7 +3048,7 @@
3048 table= 0;3048 table= 0;
3049 if (tree)3049 if (tree)
3050 {3050 {
3051 delete_tree(tree);3051 tree->delete_tree();
3052 tree= 0;3052 tree= 0;
3053 }3053 }
30543054
@@ -3083,7 +3083,7 @@
3083 warning_for_row= false;3083 warning_for_row= false;
3084 no_appended= true;3084 no_appended= true;
3085 if (tree)3085 if (tree)
3086 reset_tree(tree);3086 tree->reset_tree();
3087 if (distinct)3087 if (distinct)
3088 unique_filter->reset();3088 unique_filter->reset();
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 */
@@ -3121,10 +3121,10 @@
3121 row_eligible= false;3121 row_eligible= false;
3122 }3122 }
31233123
3124 TREE_ELEMENT *el= 0; // Only for safety3124 Tree_Element *el= 0; // Only for safety
3125 if (row_eligible && tree)3125 if (row_eligible && tree)
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,
3127 tree->custom_arg);3127 tree->getCustomArg());
3128 /*3128 /*
3129 If the row is not a duplicate (el->count == 1)3129 If the row is not a duplicate (el->count == 1)
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...)
@@ -3273,7 +3273,7 @@
3273 syntax of this function). If there is no ORDER BY clause, we don't3273 syntax of this function). If there is no ORDER BY clause, we don't
3274 create this tree.3274 create this tree.
3275 */3275 */
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,
3277 (uint64_t)(session->variables.sortbuff_size/16)), 3277 (uint64_t)(session->variables.sortbuff_size/16)),
3278 0,3278 0,
3279 tree_key_length,3279 tree_key_length,
@@ -3325,8 +3325,7 @@
3325 return 0;3325 return 0;
3326 if (no_appended && tree)3326 if (no_appended && tree)
3327 /* Tree is used for sorting as in ORDER BY */3327 /* Tree is used for sorting as in ORDER BY */
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);
3329 left_root_right);
3330 if (count_cut_values && !warning)3329 if (count_cut_values && !warning)
3331 {3330 {
3332 /*3331 /*
33333332
=== modified file 'drizzled/item/sum.h'
--- drizzled/item/sum.h 2011-04-20 22:18:30 +0000
+++ drizzled/item/sum.h 2011-12-24 17:41:25 +0000
@@ -950,8 +950,8 @@
950 DRIZZLE_ERROR *warning;950 DRIZZLE_ERROR *warning;
951 String result;951 String result;
952 String *separator;952 String *separator;
953 TREE tree_base;953 Tree tree_base;
954 TREE *tree;954 Tree *tree;
955955
956 /**956 /**
957 If DISTINCT is used with this GROUP_CONCAT, this member is used to filter957 If DISTINCT is used with this GROUP_CONCAT, this member is used to filter
958958
=== modified file 'drizzled/tree.cc'
--- drizzled/tree.cc 2011-06-22 14:19:44 +0000
+++ drizzled/tree.cc 2011-12-24 17:41:25 +0000
@@ -15,7 +15,7 @@
1515
16/*16/*
17 Code for handling red-black (balanced) binary trees.17 Code for handling red-black (balanced) binary trees.
18 key in tree is allocated accrding to following:18 key in tree is allocated according to following:
1919
20 1) If size < 0 then tree will not allocate keys and only a pointer to20 1) If size < 0 then tree will not allocate keys and only a pointer to
21 each key is saved in tree.21 each key is saved in tree.
@@ -29,8 +29,8 @@
29 3) if key_size is given to init_tree then each node will continue the29 3) if key_size is given to init_tree then each node will continue the
30 key and calls to insert_key may increase length of key.30 key and calls to insert_key may increase length of key.
31 if key_size > sizeof(pointer) and key_size is a multiple of 8 (double31 if key_size > sizeof(pointer) and key_size is a multiple of 8 (double
32 allign) then key will be put on a 8 alligned adress. Else32 align) then key will be put on a 8 aligned address. Else
33 the key will be on adress (element+1). This is transparent for user33 the key will be on address (element+1). This is transparent for user
34 compare and search functions uses a pointer to given key-argument.34 compare and search functions uses a pointer to given key-argument.
3535
36 - If you use a free function for tree-elements and you are freeing36 - If you use a free function for tree-elements and you are freeing
@@ -48,9 +48,9 @@
48/*48/*
49 NOTE:49 NOTE:
50 tree->compare function should be ALWAYS called as50 tree->compare function should be ALWAYS called as
51 (*tree->compare)(custom_arg, ELEMENT_KEY(tree,element), key)51 (*compare)(custom_arg, element_key(element), key)
52 and not other way around, as52 and NOT the other way around, as
53 (*tree->compare)(custom_arg, key, ELEMENT_KEY(tree,element))53 (*compare)(custom_arg, key, element_key(element))
54*/54*/
5555
56#include <config.h>56#include <config.h>
@@ -58,150 +58,88 @@
58#include <drizzled/tree.h>58#include <drizzled/tree.h>
59#include <drizzled/internal/my_sys.h>59#include <drizzled/internal/my_sys.h>
60#include <drizzled/internal/m_string.h>60#include <drizzled/internal/m_string.h>
61#include <drizzled/memory/root.h>
6261
63#define BLACK 162#define BLACK 1
64#define RED 063#define RED 0
65#define DEFAULT_ALLOC_SIZE 819264#define DEFAULT_ALLOC_SIZE 8192
66#define DEFAULT_ALIGN_SIZE 819265#define DEFAULT_ALIGN_SIZE 8192
6766
68#define ELEMENT_KEY(tree,element)\
69(tree->offset_to_key ? (void*)((unsigned char*) element+tree->offset_to_key) :\
70 *((void**) (element+1)))
71#define ELEMENT_CHILD(element, offs) (*(TREE_ELEMENT**)((char*)element + offs))
7267
73namespace drizzled68namespace drizzled
74{69{
7570
7671/**
77static void delete_tree_element(TREE *,TREE_ELEMENT *);72 * Tree class public methods
78static int tree_walk_left_root_right(TREE *,TREE_ELEMENT *,73 */
79 tree_walk_action,void *);74
80static int tree_walk_right_root_left(TREE *,TREE_ELEMENT *,75void Tree::init_tree(size_t default_alloc_size, uint32_t mem_limit,
81 tree_walk_action,void *);76 uint32_t size, qsort_cmp2 compare_callback, bool free_with_tree,
82static void left_rotate(TREE_ELEMENT **parent,TREE_ELEMENT *leaf);77 tree_element_free free_callback, void *caller_arg)
83static void right_rotate(TREE_ELEMENT **parent, TREE_ELEMENT *leaf);
84static void rb_insert(TREE *tree,TREE_ELEMENT ***parent,
85 TREE_ELEMENT *leaf);
86
87
88void init_tree(TREE *tree, size_t default_alloc_size, uint32_t memory_limit,
89 uint32_t size, qsort_cmp2 compare, bool with_delete,
90 tree_element_free free_element, void *custom_arg)
91{78{
92 if (default_alloc_size < DEFAULT_ALLOC_SIZE)79 if (default_alloc_size < DEFAULT_ALLOC_SIZE)
93 default_alloc_size= DEFAULT_ALLOC_SIZE;80 default_alloc_size= DEFAULT_ALLOC_SIZE;
94 default_alloc_size= MY_ALIGN(default_alloc_size, DEFAULT_ALIGN_SIZE);81 default_alloc_size= MY_ALIGN(default_alloc_size, DEFAULT_ALIGN_SIZE);
95 memset(&tree->null_element, 0, sizeof(tree->null_element));82 memset(&this->null_element, 0, sizeof(this->null_element));
96 tree->root= &tree->null_element;83 root= &this->null_element;
97 tree->compare= compare;84 compare= compare_callback;
98 tree->size_of_element= size > 0 ? (uint32_t) size : 0;85 size_of_element= size > 0 ? (uint32_t) size : 0;
99 tree->memory_limit= memory_limit;86 memory_limit= mem_limit;
100 tree->free= free_element;87 free= free_callback;
101 tree->allocated= 0;88 allocated= 0;
102 tree->elements_in_tree= 0;89 elements_in_tree= 0;
103 tree->custom_arg = custom_arg;90 custom_arg = caller_arg;
104 tree->null_element.colour= BLACK;91 null_element.colour= BLACK;
105 tree->null_element.left=tree->null_element.right= 0;92 null_element.left=this->null_element.right= 0;
106 tree->flag= 0;93 flag= 0;
107 if (!free_element &&94 if (!free_callback &&
108 (size <= sizeof(void*) || ((uint32_t) size & (sizeof(void*)-1))))95 (size <= sizeof(void*) || ((uint32_t) size & (sizeof(void*)-1))))
109 {96 {
110 /*97 /*
111 We know that the data doesn't have to be aligned (like if the key98 We know that the data doesn't have to be aligned (like if the key
112 contains a double), so we can store the data combined with the99 contains a double), so we can store the data combined with the
113 TREE_ELEMENT.100 Tree_Element.
114 */101 */
115 tree->offset_to_key= sizeof(TREE_ELEMENT); /* Put key after element */102 offset_to_key= sizeof(Tree_Element); /* Put key after element */
116 /* Fix allocation size so that we don't lose any memory */103 /* Fix allocation size so that we don't lose any memory */
117 default_alloc_size/= (sizeof(TREE_ELEMENT)+size);104 default_alloc_size/= (sizeof(Tree_Element)+size);
118 if (!default_alloc_size)105 if (!default_alloc_size)
119 default_alloc_size= 1;106 default_alloc_size= 1;
120 default_alloc_size*= (sizeof(TREE_ELEMENT)+size);107 default_alloc_size*= (sizeof(Tree_Element)+size);
121 }108 }
122 else109 else
123 {110 {
124 tree->offset_to_key= 0; /* use key through pointer */111 offset_to_key= 0; /* use key through pointer */
125 tree->size_of_element+= sizeof(void*);112 size_of_element+= sizeof(void*);
126 }113 }
127 if (! (tree->with_delete= with_delete))114 if (! (with_delete= free_with_tree))
128 {115 {
129 tree->mem_root.init(default_alloc_size);116 mem_root.init(default_alloc_size);
130 tree->mem_root.min_malloc= (sizeof(TREE_ELEMENT)+tree->size_of_element);117 mem_root.min_malloc= (sizeof(Tree_Element)+size_of_element);
131 }118 }
132}119}
133120
134static void free_tree(TREE *tree, myf free_flags)121void Tree::delete_tree()
135{122{
136 if (tree->root) /* If initialized */123 free_tree(MYF(0)); /* free() mem_root if applicable */
137 {124}
138 if (tree->with_delete)125
139 delete_tree_element(tree,tree->root);126void Tree::reset_tree()
140 else
141 {
142 if (tree->free)
143 {
144 if (tree->memory_limit)
145 (*tree->free)(NULL, free_init, tree->custom_arg);
146 delete_tree_element(tree,tree->root);
147 if (tree->memory_limit)
148 (*tree->free)(NULL, free_end, tree->custom_arg);
149 }
150 tree->mem_root.free_root(free_flags);
151 }
152 }
153 tree->root= &tree->null_element;
154 tree->elements_in_tree= 0;
155 tree->allocated= 0;
156}
157
158void delete_tree(TREE* tree)
159{
160 free_tree(tree, MYF(0)); /* free() mem_root if applicable */
161}
162
163void reset_tree(TREE* tree)
164{127{
165 /* do not free mem_root, just mark blocks as free */128 /* do not free mem_root, just mark blocks as free */
166 free_tree(tree, MYF(memory::MARK_BLOCKS_FREE));129 free_tree(MYF(memory::MARK_BLOCKS_FREE));
167}130}
168131
169132Tree_Element* Tree::tree_insert(void* key, uint32_t key_size, void* caller_arg)
170static void delete_tree_element(TREE *tree, TREE_ELEMENT *element)
171{
172 if (element != &tree->null_element)
173 {
174 delete_tree_element(tree,element->left);
175 if (tree->free)
176 (*tree->free)(ELEMENT_KEY(tree,element), free_free, tree->custom_arg);
177 delete_tree_element(tree,element->right);
178 if (tree->with_delete)
179 free((char*) element);
180 }
181}
182
183
184/*
185 insert, search and delete of elements
186
187 The following should be true:
188 parent[0] = & parent[-1][0]->left ||
189 parent[0] = & parent[-1][0]->right
190*/
191
192TREE_ELEMENT *tree_insert(TREE *tree, void *key, uint32_t key_size,
193 void* custom_arg)
194{133{
195 int cmp;134 int cmp;
196 TREE_ELEMENT *element,***parent;135 Tree_Element *element,***parent;
197136
198 parent= tree->parents;137 parent= this->parents;
199 *parent = &tree->root; element= tree->root;138 *parent = &this->root; element= this->root;
200 for (;;)139 for (;;)
201 {140 {
202 if (element == &tree->null_element ||141 if (element == &this->null_element ||
203 (cmp = (*tree->compare)(custom_arg, ELEMENT_KEY(tree,element),142 (cmp = (*compare)(caller_arg, element_key(element), key)) == 0)
204 key)) == 0)
205 break;143 break;
206 if (cmp < 0)144 if (cmp < 0)
207 {145 {
@@ -212,26 +150,26 @@
212 *++parent = &element->left; element= element->left;150 *++parent = &element->left; element= element->left;
213 }151 }
214 }152 }
215 if (element == &tree->null_element)153 if (element == &this->null_element)
216 {154 {
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;
218 tree->allocated+= alloc_size;156 this->allocated+= alloc_size;
219157
220 if (tree->memory_limit && tree->elements_in_tree158 if (this->memory_limit && this->elements_in_tree
221 && tree->allocated > tree->memory_limit)159 && this->allocated > this->memory_limit)
222 {160 {
223 reset_tree(tree);161 reset_tree();
224 return tree_insert(tree, key, key_size, custom_arg);162 return tree_insert(key, key_size, caller_arg);
225 }163 }
226164
227 key_size+= tree->size_of_element;165 key_size+= this->size_of_element;
228 if (tree->with_delete)166 if (this->with_delete)
229 element= (TREE_ELEMENT *) malloc(alloc_size);167 element= (Tree_Element *) malloc(alloc_size);
230 else168 else
231 element= (TREE_ELEMENT *) tree->mem_root.alloc(alloc_size);169 element= (Tree_Element *) this->mem_root.alloc(alloc_size);
232 **parent= element;170 **parent= element;
233 element->left= element->right= &tree->null_element;171 element->left= element->right= &this->null_element;
234 if (!tree->offset_to_key)172 if (!this->offset_to_key)
235 {173 {
236 if (key_size == sizeof(void*)) /* no length, save pointer */174 if (key_size == sizeof(void*)) /* no length, save pointer */
237 *((void**) (element+1))= key;175 *((void**) (element+1))= key;
@@ -242,14 +180,14 @@
242 }180 }
243 }181 }
244 else182 else
245 memcpy((unsigned char*) element + tree->offset_to_key, key, key_size);183 memcpy((unsigned char*) element + this->offset_to_key, key, key_size);
246 element->count= 1; /* May give warning in purify */184 element->count= 1; /* May give warning in purify */
247 tree->elements_in_tree++;185 this->elements_in_tree++;
248 rb_insert(tree,parent,element); /* rebalance tree */186 rb_insert(parent,element); /* rebalance tree */
249 }187 }
250 else188 else
251 {189 {
252 if (tree->flag & TREE_NO_DUPS)190 if (this->flag & TREE_NO_DUPS)
253 return(NULL);191 return(NULL);
254 element->count++;192 element->count++;
255 /* Avoid a wrap over of the count. */193 /* Avoid a wrap over of the count. */
@@ -260,238 +198,123 @@
260 return element;198 return element;
261}199}
262200
263void *tree_search_key(TREE *tree, const void *key,201int Tree::tree_walk(tree_walk_action action, void *argument, TREE_WALK visit)
264 TREE_ELEMENT **parents, TREE_ELEMENT ***last_pos,202{
265 enum ha_rkey_function flag, void *custom_arg)203 switch (visit) {
266{204 case left_root_right:
267 TREE_ELEMENT *element= tree->root;205 return tree_walk_left_root_right(root,action,argument);
268 TREE_ELEMENT **last_left_step_parent= NULL, **last_right_step_parent= NULL;206 case right_root_left:
269 TREE_ELEMENT **last_equal_element= NULL;207 return tree_walk_right_root_left(root,action,argument);
270
271/*
272 TODO: support for HA_READ_KEY_OR_PREV, HA_READ_PREFIX flags if needed.
273*/
274
275 *parents = &tree->null_element;
276 while (element != &tree->null_element)
277 {
278 int cmp;
279
280 *++parents= element;
281
282 if ((cmp= (*tree->compare)(custom_arg, ELEMENT_KEY(tree, element),
283 key)) == 0)
284 {
285 switch (flag) {
286 case HA_READ_KEY_EXACT:
287 case HA_READ_KEY_OR_NEXT:
288 case HA_READ_BEFORE_KEY:
289 last_equal_element= parents;
290 cmp= 1;
291 break;
292 case HA_READ_AFTER_KEY:
293 cmp= -1;
294 break;
295 case HA_READ_PREFIX_LAST:
296 case HA_READ_PREFIX_LAST_OR_PREV:
297 last_equal_element= parents;
298 cmp= -1;
299 break;
300 default:
301 return NULL;
302 }
303 }
304 if (cmp < 0) /* element < key */
305 {
306 last_right_step_parent= parents;
307 element= element->right;
308 }
309 else
310 {
311 last_left_step_parent= parents;
312 element= element->left;
313 }
314 }
315 switch (flag) {
316 case HA_READ_KEY_EXACT:
317 case HA_READ_PREFIX_LAST:
318 *last_pos= last_equal_element;
319 break;
320 case HA_READ_KEY_OR_NEXT:
321 *last_pos= last_equal_element ? last_equal_element : last_left_step_parent;
322 break;
323 case HA_READ_AFTER_KEY:
324 *last_pos= last_left_step_parent;
325 break;
326 case HA_READ_PREFIX_LAST_OR_PREV:
327 *last_pos= last_equal_element ? last_equal_element : last_right_step_parent;
328 break;
329 case HA_READ_BEFORE_KEY:
330 *last_pos= last_right_step_parent;
331 break;
332 default:
333 return NULL;
334 }
335
336 return *last_pos ? ELEMENT_KEY(tree, **last_pos) : NULL;
337}
338
339void *tree_search_next(TREE *tree, TREE_ELEMENT ***last_pos, int l_offs,
340 int r_offs)
341{
342 TREE_ELEMENT *x= **last_pos;
343
344 if (ELEMENT_CHILD(x, r_offs) != &tree->null_element)
345 {
346 x= ELEMENT_CHILD(x, r_offs);
347 *++*last_pos= x;
348 while (ELEMENT_CHILD(x, l_offs) != &tree->null_element)
349 {
350 x= ELEMENT_CHILD(x, l_offs);
351 *++*last_pos= x;
352 }
353 return ELEMENT_KEY(tree, x);
354 }
355 else
356 {
357 TREE_ELEMENT *y= *--*last_pos;
358 while (y != &tree->null_element && x == ELEMENT_CHILD(y, r_offs))
359 {
360 x= y;
361 y= *--*last_pos;
362 }
363 return y == &tree->null_element ? NULL : ELEMENT_KEY(tree, y);
364 }
365}
366
367/*
368 Expected that tree is fully balanced
369 (each path from root to leaf has the same length)
370*/
371ha_rows tree_record_pos(TREE *tree, const void *key,
372 enum ha_rkey_function flag, void *custom_arg)
373{
374 TREE_ELEMENT *element= tree->root;
375 double left= 1;
376 double right= tree->elements_in_tree;
377
378 while (element != &tree->null_element)
379 {
380 int cmp;
381
382 if ((cmp= (*tree->compare)(custom_arg, ELEMENT_KEY(tree, element),
383 key)) == 0)
384 {
385 switch (flag) {
386 case HA_READ_KEY_EXACT:
387 case HA_READ_BEFORE_KEY:
388 cmp= 1;
389 break;
390 case HA_READ_AFTER_KEY:
391 cmp= -1;
392 break;
393 default:
394 return HA_POS_ERROR;
395 }
396 }
397 if (cmp < 0) /* element < key */
398 {
399 element= element->right;
400 left= (left + right) / 2;
401 }
402 else
403 {
404 element= element->left;
405 right= (left + right) / 2;
406 }
407 }
408
409 switch (flag) {
410 case HA_READ_KEY_EXACT:
411 case HA_READ_BEFORE_KEY:
412 return (ha_rows) right;
413 case HA_READ_AFTER_KEY:
414 return (ha_rows) left;
415 default:
416 return HA_POS_ERROR;
417 }
418}
419
420int tree_walk(TREE *tree, tree_walk_action action, void *argument, TREE_WALK visit)
421{
422 switch (visit) {
423 case left_root_right:
424 return tree_walk_left_root_right(tree,tree->root,action,argument);
425 case right_root_left:
426 return tree_walk_right_root_left(tree,tree->root,action,argument);
427 }208 }
428209
429 return 0; /* Keep gcc happy */210 return 0; /* Keep gcc happy */
430}211}
431212
432static int tree_walk_left_root_right(TREE *tree, TREE_ELEMENT *element, tree_walk_action action, void *argument)213/**
214 * Tree class private methods
215 */
216
217void Tree::free_tree(myf free_flags)
218{
219 if (root) /* If initialized */
220 {
221 if (with_delete)
222 delete_tree_element(root);
223 else
224 {
225 if (free)
226 {
227 if (memory_limit)
228 (*free)(NULL, free_init, custom_arg);
229 delete_tree_element(root);
230 if (memory_limit)
231 (*free)(NULL, free_end, custom_arg);
232 }
233 mem_root.free_root(free_flags);
234 }
235 }
236 root= &null_element;
237 elements_in_tree= 0;
238 allocated= 0;
239}
240
241void* Tree::element_key(Tree_Element* element)
242{
243 return offset_to_key ? (void*)((unsigned char*) element + offset_to_key)
244 : *((void**)(element + 1));
245}
246
247void Tree::delete_tree_element(Tree_Element *element)
248{
249 if (element != &null_element)
250 {
251 delete_tree_element(element->left);
252 if (free)
253 (*free)(element_key(element), free_free, custom_arg);
254 delete_tree_element(element->right);
255 if (with_delete)
256 delete element;
257 }
258}
259
260int Tree::tree_walk_left_root_right(Tree_Element *element, tree_walk_action action, void *argument)
433{261{
434 int error;262 int error;
435 if (element->left) /* Not null_element */263 if (element->left) /* Not null_element */
436 {264 {
437 if ((error=tree_walk_left_root_right(tree,element->left,action,265 if ((error=tree_walk_left_root_right(element->left,action,
438 argument)) == 0 &&266 argument)) == 0 &&
439 (error=(*action)(ELEMENT_KEY(tree,element),267 (error=(*action)(element_key(element), element->count, argument)) == 0)
440 element->count,268 error=tree_walk_left_root_right(element->right,action,argument);
441 argument)) == 0)
442 error=tree_walk_left_root_right(tree,element->right,action,argument);
443 return error;269 return error;
444 }270 }
445271
446 return 0;272 return 0;
447}273}
448274
449static int tree_walk_right_root_left(TREE *tree, TREE_ELEMENT *element, tree_walk_action action, void *argument)275int Tree::tree_walk_right_root_left(Tree_Element *element, tree_walk_action action, void *argument)
450{276{
451 int error;277 int error;
452 if (element->right) /* Not null_element */278 if (element->right) /* Not null_element */
453 {279 {
454 if ((error=tree_walk_right_root_left(tree,element->right,action,280 if ((error=tree_walk_right_root_left(element->right,action,
455 argument)) == 0 &&281 argument)) == 0 &&
456 (error=(*action)(ELEMENT_KEY(tree,element),282 (error=(*action)(element_key(element),
457 element->count,283 element->count,
458 argument)) == 0)284 argument)) == 0)
459 error=tree_walk_right_root_left(tree,element->left,action,argument);285 error=tree_walk_right_root_left(element->left,action,argument);
460 return error;286 return error;
461 }287 }
462288
463 return 0;289 return 0;
464}290}
465291
466292void Tree::left_rotate(Tree_Element **parent, Tree_Element *element)
467/* Functions to fix up the tree after insert and delete */
468
469static void left_rotate(TREE_ELEMENT **parent, TREE_ELEMENT *leaf)
470{293{
471 TREE_ELEMENT *y;294 Tree_Element *y;
472295
473 y= leaf->right;296 y= element->right;
474 leaf->right= y->left;297 element->right= y->left;
475 parent[0]= y;298 parent[0]= y;
476 y->left= leaf;299 y->left= element;
477}300}
478301
479static void right_rotate(TREE_ELEMENT **parent, TREE_ELEMENT *leaf)302void Tree::right_rotate(Tree_Element **parent, Tree_Element *element)
480{303{
481 TREE_ELEMENT *x;304 Tree_Element *x;
482305
483 x= leaf->left;306 x= element->left;
484 leaf->left= x->right;307 element->left= x->right;
485 parent[0]= x;308 parent[0]= x;
486 x->right= leaf;309 x->right= element;
487}310}
488311
489static void rb_insert(TREE *tree, TREE_ELEMENT ***parent, TREE_ELEMENT *leaf)312void Tree::rb_insert(Tree_Element ***parent, Tree_Element *element)
490{313{
491 TREE_ELEMENT *y,*par,*par2;314 Tree_Element *y,*par,*par2;
492315
493 leaf->colour=RED;316 element->colour=RED;
494 while (leaf != tree->root && (par=parent[-1][0])->colour == RED)317 while (element != root && (par=parent[-1][0])->colour == RED)
495 {318 {
496 if (par == (par2=parent[-2][0])->left)319 if (par == (par2=parent[-2][0])->left)
497 {320 {
@@ -500,16 +323,16 @@
500 {323 {
501 par->colour= BLACK;324 par->colour= BLACK;
502 y->colour= BLACK;325 y->colour= BLACK;
503 leaf= par2;326 element= par2;
504 parent-= 2;327 parent-= 2;
505 leaf->colour= RED; /* And the loop continues */328 element->colour= RED; /* And the loop continues */
506 }329 }
507 else330 else
508 {331 {
509 if (leaf == par->right)332 if (element == par->right)
510 {333 {
511 left_rotate(parent[-1],par);334 left_rotate(parent[-1],par);
512 par= leaf; /* leaf is now parent to old leaf */335 par= element; /* element is now parent to old element */
513 }336 }
514 par->colour= BLACK;337 par->colour= BLACK;
515 par2->colour= RED;338 par2->colour= RED;
@@ -524,16 +347,16 @@
524 {347 {
525 par->colour= BLACK;348 par->colour= BLACK;
526 y->colour= BLACK;349 y->colour= BLACK;
527 leaf= par2;350 element= par2;
528 parent-= 2;351 parent-= 2;
529 leaf->colour= RED; /* And the loop continues */352 element->colour= RED; /* And the loop continues */
530 }353 }
531 else354 else
532 {355 {
533 if (leaf == par->left)356 if (element == par->left)
534 {357 {
535 right_rotate(parent[-1],par);358 right_rotate(parent[-1],par);
536 par= leaf;359 par= element;
537 }360 }
538 par->colour= BLACK;361 par->colour= BLACK;
539 par2->colour= RED;362 par2->colour= RED;
@@ -542,7 +365,7 @@
542 }365 }
543 }366 }
544 }367 }
545 tree->root->colour=BLACK;368 root->colour=BLACK;
546}369}
547370
548} /* namespace drizzled */371} /* namespace drizzled */
549372
=== modified file 'drizzled/tree.h'
--- drizzled/tree.h 2011-03-14 05:40:28 +0000
+++ drizzled/tree.h 2011-12-24 17:41:25 +0000
@@ -17,14 +17,14 @@
1717
18#include <unistd.h>18#include <unistd.h>
1919
20#include <drizzled/base.h> /* get 'enum ha_rkey_function' */20#include <drizzled/base.h> // for 'enum ha_rkey_function'
21#include <drizzled/memory/root.h>
21#include <drizzled/qsort_cmp.h>22#include <drizzled/qsort_cmp.h>
22#include <drizzled/memory/root.h>
2323
24namespace drizzled24namespace drizzled
25{25{
2626
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
28static const int MAX_TREE_HEIGHT= 64;28static const int MAX_TREE_HEIGHT= 64;
2929
30static const int TREE_NO_DUPS= 1;30static const int TREE_NO_DUPS= 1;
@@ -35,56 +35,77 @@
35typedef enum { free_init, free_free, free_end } TREE_FREE;35typedef enum { free_init, free_free, free_end } TREE_FREE;
36typedef void (*tree_element_free)(void*, TREE_FREE, void *);36typedef void (*tree_element_free)(void*, TREE_FREE, void *);
3737
38typedef struct st_tree_element {38
39 struct st_tree_element *left,*right;39class Tree_Element
40 uint32_t count:31,40{
41 colour:1; /* black is marked as 1 */41public:
42} TREE_ELEMENT;42 Tree_Element *left,*right;
4343 uint32_t count:31,
44static const int TREE_ELEMENT_EXTRA_SIZE= (sizeof(TREE_ELEMENT) + sizeof(void*));44 colour:1; /* black is marked as 1 */
4545};
4646
47typedef struct st_tree {47static const int TREE_ELEMENT_EXTRA_SIZE= (sizeof(Tree_Element) + sizeof(void*));
48 TREE_ELEMENT *root,null_element;48
49 TREE_ELEMENT **parents[MAX_TREE_HEIGHT];49/**
50 uint32_t offset_to_key, elements_in_tree, size_of_element;50 * red-black binary tree class
51 size_t memory_limit;51 *
52 size_t allocated;52 * NOTE: unused search code removed 11/2011
53 qsort_cmp2 compare;53 */
54 void *custom_arg;54class Tree
55 memory::Root mem_root;55{
56 bool with_delete;56private:
57 tree_element_free free;57 Tree_Element *root, null_element;
58 uint32_t flag;58 void *custom_arg;
59} TREE;59 Tree_Element **parents[MAX_TREE_HEIGHT];
6060 uint32_t offset_to_key, elements_in_tree, size_of_element;
61/* Functions on whole tree */61 size_t memory_limit;
62void init_tree(TREE *tree, size_t default_alloc_size, uint32_t memory_limit,62 size_t allocated;
63 uint32_t size, qsort_cmp2 compare, bool with_delete,63 qsort_cmp2 compare;
64 tree_element_free free_element, void *custom_arg);64 memory::Root mem_root;
65void delete_tree(TREE*);65 bool with_delete;
66void reset_tree(TREE*);66 tree_element_free free;
6767 uint32_t flag;
68/* 68
69 similar to delete tree, except we do not free() blocks in mem_root69public:
70*/70 void* getCustomArg() {
71#define is_tree_inited(tree) ((tree)->root != 0)71 return custom_arg;
7272 }
73/* Functions on leafs */73 Tree_Element* getRoot() {
74TREE_ELEMENT *tree_insert(TREE *tree,void *key, uint32_t key_size,74 return root;
75 void *custom_arg);75 }
76int tree_walk(TREE *tree,tree_walk_action action,76 void setRoot(Tree_Element* root_arg) {
77 void *argument, TREE_WALK visit);77 root = root_arg;
78int tree_delete(TREE *tree, void *key, uint32_t key_size, void *custom_arg);78 }
79void *tree_search_key(TREE *tree, const void *key,79 uint32_t getElementsInTree() {
80 TREE_ELEMENT **parents, TREE_ELEMENT ***last_pos,80 return elements_in_tree;
81 enum ha_rkey_function flag, void *custom_arg);81 }
82void *tree_search_edge(TREE *tree, TREE_ELEMENT **parents,82 // tree methods
83 TREE_ELEMENT ***last_pos, int child_offs);83 void init_tree(size_t default_alloc_size, uint32_t memory_limit,
84void *tree_search_next(TREE *tree, TREE_ELEMENT ***last_pos, int l_offs,84 uint32_t size, qsort_cmp2 compare, bool with_delete,
85 int r_offs);85 tree_element_free free_element, void *custom_arg);
86ha_rows tree_record_pos(TREE *tree, const void *key,86 bool is_inited()
87 enum ha_rkey_function search_flag, void *custom_arg);87 {
88 return this->root != 0;
89 }
90 void delete_tree();
91 void reset_tree();
92
93 // element methods
94 Tree_Element *tree_insert(void *key, uint32_t key_size, void *custom_arg);
95 int tree_walk(tree_walk_action action, void *argument, TREE_WALK visit);
96
97private:
98 void free_tree(myf free_flags);
99
100 void* element_key(Tree_Element* element);
101 void delete_tree_element(Tree_Element* element);
102 int tree_walk_left_root_right(Tree_Element* element, tree_walk_action action, void* argument);
103 int tree_walk_right_root_left(Tree_Element* element, tree_walk_action action, void* argument);
104
105 void left_rotate(Tree_Element **parent,Tree_Element *element);
106 void right_rotate(Tree_Element **parent, Tree_Element *element);
107 void rb_insert(Tree_Element ***parent, Tree_Element *element);
108};
88109
89} /* namespace drizzled */110} /* namespace drizzled */
90111
91112
=== modified file 'drizzled/unique.cc'
--- drizzled/unique.cc 2011-03-19 17:01:16 +0000
+++ drizzled/unique.cc 2011-12-24 17:41:25 +0000
@@ -62,7 +62,7 @@
62 elements(0)62 elements(0)
63{63{
64 // Second element is max size for memory use in unique sort64 // Second element is max size for memory use in unique sort
65 init_tree(&tree, 0, 0, size, comp_func, false,65 tree.init_tree(0, 0, size, comp_func, false,
66 NULL, comp_func_fixed_arg);66 NULL, comp_func_fixed_arg);
67}67}
6868
@@ -146,7 +146,7 @@
146 double result;146 double result;
147147
148 max_elements_in_tree= ((ulong) max_in_memory_size_arg /148 max_elements_in_tree= ((ulong) max_in_memory_size_arg /
149 ALIGN_SIZE(sizeof(TREE_ELEMENT)+key_size));149 ALIGN_SIZE(sizeof(Tree_Element)+key_size));
150150
151 last_tree_elems= nkeys % max_elements_in_tree;151 last_tree_elems= nkeys % max_elements_in_tree;
152152
@@ -159,7 +159,7 @@
159159
160Unique::~Unique()160Unique::~Unique()
161{161{
162 delete_tree(&tree);162 tree.delete_tree();
163}163}
164164
165165
@@ -171,7 +171,7 @@
171void171void
172Unique::reset()172Unique::reset()
173{173{
174 reset_tree(&tree);174 tree.reset_tree();
175 assert(elements == 0);175 assert(elements == 0);
176}176}
177177
@@ -198,7 +198,7 @@
198198
199bool Unique::walk(tree_walk_action action, void *walk_action_arg)199bool Unique::walk(tree_walk_action action, void *walk_action_arg)
200{200{
201 return tree_walk(&tree, action, walk_action_arg, left_root_right);201 return tree.tree_walk(action, walk_action_arg, left_root_right);
202}202}
203203
204/*204/*
@@ -208,12 +208,12 @@
208208
209bool Unique::get(Table *table)209bool Unique::get(Table *table)
210{210{
211 table->sort.found_records= elements+tree.elements_in_tree;211 table->sort.found_records= elements+tree.getElementsInTree();
212212
213 if ((record_pointers=table->sort.record_pointers= (unsigned char*)213 if ((record_pointers=table->sort.record_pointers= (unsigned char*)
214 malloc(size * tree.elements_in_tree)))214 malloc(size * tree.getElementsInTree())))
215 {215 {
216 (void) tree_walk(&tree, (tree_walk_action) unique_write_to_ptrs,216 (void) tree.tree_walk((tree_walk_action) unique_write_to_ptrs,
217 this, left_root_right);217 this, left_root_right);
218 return 0;218 return 0;
219 }219 }
220220
=== modified file 'drizzled/unique.h'
--- drizzled/unique.h 2011-04-29 00:19:38 +0000
+++ drizzled/unique.h 2011-12-24 17:41:25 +0000
@@ -40,7 +40,7 @@
40class Unique : public memory::SqlAlloc40class Unique : public memory::SqlAlloc
41{41{
42 size_t max_in_memory_size;42 size_t max_in_memory_size;
43 TREE tree;43 Tree tree;
44 unsigned char *record_pointers;44 unsigned char *record_pointers;
45 uint32_t size;45 uint32_t size;
4646
@@ -49,10 +49,10 @@
49 Unique(qsort_cmp2 comp_func, void *comp_func_fixed_arg,49 Unique(qsort_cmp2 comp_func, void *comp_func_fixed_arg,
50 uint32_t size_arg, size_t max_in_memory_size_arg);50 uint32_t size_arg, size_t max_in_memory_size_arg);
51 ~Unique();51 ~Unique();
52 ulong elements_in_tree() { return tree.elements_in_tree; }52 ulong elements_in_tree() { return tree.getElementsInTree(); }
53 inline bool unique_add(void *ptr)53 inline bool unique_add(void *ptr)
54 {54 {
55 return (not tree_insert(&tree, ptr, 0, tree.custom_arg));55 return (not tree.tree_insert(ptr, 0, tree.getCustomArg()));
56 }56 }
5757
58 bool get(Table *table);58 bool get(Table *table);
@@ -62,7 +62,7 @@
62 size_t sortbuff_size)62 size_t sortbuff_size)
63 {63 {
64 register size_t max_elems_in_tree=64 register size_t max_elems_in_tree=
65 (1 + sortbuff_size / ALIGN_SIZE(sizeof(TREE_ELEMENT)+key_size));65 (1 + sortbuff_size / ALIGN_SIZE(sizeof(Tree_Element)+key_size));
66 return (int) (sizeof(uint32_t)*(1 + nkeys/max_elems_in_tree));66 return (int) (sizeof(uint32_t)*(1 + nkeys/max_elems_in_tree));
67 }67 }
6868
6969
=== modified file 'plugin/myisam/mi_write.cc'
--- plugin/myisam/mi_write.cc 2011-02-17 00:14:13 +0000
+++ plugin/myisam/mi_write.cc 2011-12-24 17:41:25 +0000
@@ -19,6 +19,7 @@
1919
20#include <drizzled/internal/m_string.h>20#include <drizzled/internal/m_string.h>
21#include <drizzled/util/test.h>21#include <drizzled/util/test.h>
22#include <drizzled/tree.h>
2223
23using namespace drizzled;24using namespace drizzled;
2425
@@ -97,7 +98,7 @@
97 {98 {
98 bool local_lock_tree= (lock_tree &&99 bool local_lock_tree= (lock_tree &&
99 !(info->bulk_insert &&100 !(info->bulk_insert &&
100 is_tree_inited(&info->bulk_insert[i])));101 info->bulk_insert[i].is_inited()));
101 if (local_lock_tree)102 if (local_lock_tree)
102 {103 {
103 share->keyinfo[i].version++;104 share->keyinfo[i].version++;
@@ -188,7 +189,7 @@
188189
189int _mi_ck_write(MI_INFO *info, uint32_t keynr, unsigned char *key, uint32_t key_length)190int _mi_ck_write(MI_INFO *info, uint32_t keynr, unsigned char *key, uint32_t key_length)
190{191{
191 if (info->bulk_insert && is_tree_inited(&info->bulk_insert[keynr]))192 if (info->bulk_insert && info->bulk_insert[keynr].is_inited())
192 {193 {
193 return(_mi_ck_write_tree(info, keynr, key, key_length));194 return(_mi_ck_write_tree(info, keynr, key, key_length));
194 }195 }
@@ -716,9 +717,9 @@
716{717{
717 int error;718 int error;
718719
719 error= tree_insert(&info->bulk_insert[keynr], key,720 error= info->bulk_insert[keynr].tree_insert(key,
720 key_length + info->s->rec_reflength,721 key_length + info->s->rec_reflength,
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 ;
722723
723 return(error);724 return(error);
724} /* _mi_ck_write_tree */725} /* _mi_ck_write_tree */
@@ -797,8 +798,7 @@
797 else798 else
798 cache_size/=total_keylength*16;799 cache_size/=total_keylength*16;
799800
800 info->bulk_insert=(TREE *)801 info->bulk_insert=(Tree *) malloc((sizeof(Tree)*share->base.keys+
801 malloc((sizeof(TREE)*share->base.keys+
802 sizeof(bulk_insert_param)*num_keys));802 sizeof(bulk_insert_param)*num_keys));
803803
804 if (!info->bulk_insert)804 if (!info->bulk_insert)
@@ -812,14 +812,13 @@
812 params->info=info;812 params->info=info;
813 params->keynr=i;813 params->keynr=i;
814 /* Only allocate a 16'th of the buffer at a time */814 /* Only allocate a 16'th of the buffer at a time */
815 init_tree(&info->bulk_insert[i],815 info->bulk_insert[i].init_tree(cache_size * key[i].maxlength,
816 cache_size * key[i].maxlength,
817 cache_size * key[i].maxlength, 0,816 cache_size * key[i].maxlength, 0,
818 (qsort_cmp2)keys_compare, false,817 (qsort_cmp2)keys_compare, false,
819 (tree_element_free) keys_free, (void *)params++);818 (tree_element_free) keys_free, (void *)params++);
820 }819 }
821 else820 else
822 info->bulk_insert[i].root=0;821 info->bulk_insert[i].setRoot(0);
823 }822 }
824823
825 return(0);824 return(0);
@@ -829,8 +828,8 @@
829{828{
830 if (info->bulk_insert)829 if (info->bulk_insert)
831 {830 {
832 if (is_tree_inited(&info->bulk_insert[inx]))831 if (info->bulk_insert[inx].is_inited())
833 reset_tree(&info->bulk_insert[inx]);832 info->bulk_insert[inx].reset_tree();
834 }833 }
835}834}
836835
@@ -841,9 +840,9 @@
841 uint32_t i;840 uint32_t i;
842 for (i=0 ; i < info->s->base.keys ; i++)841 for (i=0 ; i < info->s->base.keys ; i++)
843 {842 {
844 if (is_tree_inited(& info->bulk_insert[i]))843 if (info->bulk_insert[i].is_inited())
845 {844 {
846 delete_tree(& info->bulk_insert[i]);845 info->bulk_insert[i].delete_tree();
847 }846 }
848 }847 }
849 free((void *)info->bulk_insert);848 free((void *)info->bulk_insert);
850849
=== modified file 'plugin/myisam/myisam_priv.h'
--- plugin/myisam/myisam_priv.h 2011-08-22 13:44:06 +0000
+++ plugin/myisam/myisam_priv.h 2011-12-24 17:41:25 +0000
@@ -21,7 +21,8 @@
2121
22#include "myisam.h" /* Structs & some defines */22#include "myisam.h" /* Structs & some defines */
23#include "myisampack.h" /* packing of keys */23#include "myisampack.h" /* packing of keys */
24#include <drizzled/tree.h>24#include <drizzled/memory/root.h>
25
25#include <drizzled/internal/my_pthread.h>26#include <drizzled/internal/my_pthread.h>
26#include <drizzled/thr_lock.h>27#include <drizzled/thr_lock.h>
27#include <drizzled/common.h>28#include <drizzled/common.h>
@@ -36,6 +37,10 @@
3637
37#include <boost/thread/mutex.hpp>38#include <boost/thread/mutex.hpp>
3839
40namespace drizzled {
41class Tree;
42}
43
39#if defined(my_write)44#if defined(my_write)
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 */
41#endif46#endif
@@ -249,7 +254,7 @@
249 MI_BLOB *blobs; /* Pointer to blobs */254 MI_BLOB *blobs; /* Pointer to blobs */
250 MI_BIT_BUFF bit_buff;255 MI_BIT_BUFF bit_buff;
251 /* accumulate indexfile changes between write's */256 /* accumulate indexfile changes between write's */
252 drizzled::TREE *bulk_insert;257 drizzled::Tree *bulk_insert;
253 drizzled::Session *in_use; /* Thread using this table */258 drizzled::Session *in_use; /* Thread using this table */
254 char *filename; /* parameter to open filename */259 char *filename; /* parameter to open filename */
255 unsigned char *buff, /* Temp area for key */260 unsigned char *buff, /* Temp area for key */