851
by Brian Aker
Class rewrite of Session (aka get all of the junk out) |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
4 |
* Copyright (C) 2008 Sun Microsystems
|
|
5 |
*
|
|
6 |
* This program is free software; you can redistribute it and/or modify
|
|
7 |
* it under the terms of the GNU General Public License as published by
|
|
8 |
* the Free Software Foundation; version 2 of the License.
|
|
9 |
*
|
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
* GNU General Public License for more details.
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License
|
|
16 |
* along with this program; if not, write to the Free Software
|
|
17 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
18 |
*/
|
|
19 |
||
20 |
||
21 |
#ifndef DRIZZLED_UNIQUE_H
|
|
22 |
#define DRIZZLED_UNIQUE_H
|
|
23 |
||
24 |
/*
|
|
25 |
Unique -- class for unique (removing of duplicates).
|
|
26 |
Puts all values to the TREE. If the tree becomes too big,
|
|
27 |
it's dumped to the file. User can request sorted values, or
|
|
28 |
just iterate through them. In the last case tree merging is performed in
|
|
29 |
memory simultaneously with iteration, so it should be ~2-3x faster.
|
|
30 |
*/
|
|
31 |
||
32 |
class Unique :public Sql_alloc |
|
33 |
{
|
|
34 |
DYNAMIC_ARRAY file_ptrs; |
|
35 |
ulong max_elements; |
|
36 |
size_t max_in_memory_size; |
|
37 |
IO_CACHE file; |
|
38 |
TREE tree; |
|
39 |
unsigned char *record_pointers; |
|
40 |
bool flush(); |
|
41 |
uint32_t size; |
|
42 |
||
43 |
public: |
|
44 |
ulong elements; |
|
45 |
Unique(qsort_cmp2 comp_func, void *comp_func_fixed_arg, |
|
46 |
uint32_t size_arg, size_t max_in_memory_size_arg); |
|
47 |
~Unique(); |
|
48 |
ulong elements_in_tree() { return tree.elements_in_tree; } |
|
49 |
inline bool unique_add(void *ptr) |
|
50 |
{
|
|
51 |
if (tree.elements_in_tree > max_elements && flush()) |
|
52 |
return(1); |
|
53 |
return(!tree_insert(&tree, ptr, 0, tree.custom_arg)); |
|
54 |
}
|
|
55 |
||
56 |
bool get(Table *table); |
|
57 |
static double get_use_cost(uint32_t *buffer, uint32_t nkeys, uint32_t key_size, |
|
58 |
size_t max_in_memory_size); |
|
59 |
inline static int get_cost_calc_buff_size(ulong nkeys, uint32_t key_size, |
|
60 |
size_t max_in_memory_size) |
|
61 |
{
|
|
62 |
register size_t max_elems_in_tree= |
|
63 |
(1 + max_in_memory_size / ALIGN_SIZE(sizeof(TREE_ELEMENT)+key_size)); |
|
895
by Brian Aker
Completion (?) of uint conversion. |
64 |
return (int) (sizeof(uint32_t)*(1 + nkeys/max_elems_in_tree)); |
851
by Brian Aker
Class rewrite of Session (aka get all of the junk out) |
65 |
}
|
66 |
||
67 |
void reset(); |
|
68 |
bool walk(tree_walk_action action, void *walk_action_arg); |
|
69 |
||
70 |
friend int unique_write_to_file(unsigned char* key, element_count count, Unique *unique); |
|
71 |
friend int unique_write_to_ptrs(unsigned char* key, element_count count, Unique *unique); |
|
72 |
};
|
|
73 |
||
74 |
#endif /* DRIZZLED_UNIQUE_H */ |