~drizzle-developers/ubuntu/natty/drizzle/natty

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
1273.112.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
1273.3.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
33
namespace drizzled
34
{
35
36
namespace internal
37
{
0.1.1 by Monty Taylor
Import upstream version 2010.01.1273
38
typedef struct st_io_cache IO_CACHE;
1273.3.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
39
}
0.1.1 by Monty Taylor
Import upstream version 2010.01.1273
40
1273.3.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
  {
1273.578.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,
63
                                            size_t max_in_memory_size)
64
  {
65
    register size_t max_elems_in_tree=
66
      (1 + max_in_memory_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
0.1.1 by Monty Taylor
Import upstream version 2010.01.1273
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
1273.3.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 */