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 |
||
1410.3.4
by Djellel E. Difallah
update references to old my_'s |
24 |
#include "drizzled/tree.h" |
851
by Brian Aker
Class rewrite of Session (aka get all of the junk out) |
25 |
/*
|
26 |
Unique -- class for unique (removing of duplicates).
|
|
27 |
Puts all values to the TREE. If the tree becomes too big,
|
|
28 |
it's dumped to the file. User can request sorted values, or
|
|
29 |
just iterate through them. In the last case tree merging is performed in
|
|
30 |
memory simultaneously with iteration, so it should be ~2-3x faster.
|
|
31 |
*/
|
|
32 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
33 |
namespace drizzled |
34 |
{
|
|
35 |
||
36 |
namespace internal |
|
37 |
{
|
|
1241.9.50
by Monty Taylor
Removed last non-pointer public IO_CACHE from drizzled/ |
38 |
typedef struct st_io_cache IO_CACHE; |
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
39 |
}
|
1241.9.50
by Monty Taylor
Removed last non-pointer public IO_CACHE from drizzled/ |
40 |
|
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
41 |
class Unique : public memory::SqlAlloc |
851
by Brian Aker
Class rewrite of Session (aka get all of the junk out) |
42 |
{
|
43 |
size_t max_in_memory_size; |
|
44 |
TREE tree; |
|
45 |
unsigned char *record_pointers; |
|
46 |
uint32_t size; |
|
47 |
||
48 |
public: |
|
49 |
ulong elements; |
|
50 |
Unique(qsort_cmp2 comp_func, void *comp_func_fixed_arg, |
|
51 |
uint32_t size_arg, size_t max_in_memory_size_arg); |
|
52 |
~Unique(); |
|
53 |
ulong elements_in_tree() { return tree.elements_in_tree; } |
|
54 |
inline bool unique_add(void *ptr) |
|
55 |
{
|
|
1749.3.11
by Brian Aker
Force unique to just use memory and let the OS handle paging. |
56 |
return (not tree_insert(&tree, ptr, 0, tree.custom_arg)); |
851
by Brian Aker
Class rewrite of Session (aka get all of the junk out) |
57 |
}
|
58 |
||
59 |
bool get(Table *table); |
|
60 |
static double get_use_cost(uint32_t *buffer, uint32_t nkeys, uint32_t key_size, |
|
61 |
size_t max_in_memory_size); |
|
62 |
inline static int get_cost_calc_buff_size(ulong nkeys, uint32_t key_size, |
|
1891.2.1
by Monty Taylor
Fixed things to make things compile with clang |
63 |
size_t sortbuff_size) |
851
by Brian Aker
Class rewrite of Session (aka get all of the junk out) |
64 |
{
|
65 |
register size_t max_elems_in_tree= |
|
1891.2.1
by Monty Taylor
Fixed things to make things compile with clang |
66 |
(1 + sortbuff_size / ALIGN_SIZE(sizeof(TREE_ELEMENT)+key_size)); |
895
by Brian Aker
Completion (?) of uint conversion. |
67 |
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) |
68 |
}
|
69 |
||
70 |
void reset(); |
|
71 |
bool walk(tree_walk_action action, void *walk_action_arg); |
|
72 |
||
1241.9.46
by Monty Taylor
Removed some more evil. |
73 |
friend int unique_write_to_file(unsigned char* key, uint32_t count, Unique *unique); |
74 |
friend int unique_write_to_ptrs(unsigned char* key, uint32_t count, Unique *unique); |
|
851
by Brian Aker
Class rewrite of Session (aka get all of the junk out) |
75 |
};
|
76 |
||
1280.1.10
by Monty Taylor
Put everything in drizzled into drizzled namespace. |
77 |
} /* namespace drizzled */ |
78 |
||
851
by Brian Aker
Class rewrite of Session (aka get all of the junk out) |
79 |
#endif /* DRIZZLED_UNIQUE_H */ |