~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/unique.h

  • Committer: Stewart Smith
  • Date: 2009-06-16 00:45:15 UTC
  • mto: (1119.2.6 merge)
  • mto: This revision was merged to the branch mainline in revision 1124.
  • Revision ID: stewart@flamingspork.com-20090616004515-bgr8e62psvn2820l
make snowman test not leave tables behind after running

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
21
21
#ifndef DRIZZLED_UNIQUE_H
22
22
#define DRIZZLED_UNIQUE_H
23
23
 
24
 
#include "drizzled/tree.h"
25
24
/*
26
25
   Unique -- class for unique (removing of duplicates).
27
26
   Puts all values to the TREE. If the tree becomes too big,
30
29
   memory simultaneously with iteration, so it should be ~2-3x faster.
31
30
 */
32
31
 
33
 
namespace drizzled
34
 
{
35
 
 
36
 
namespace internal
37
 
{
38
 
typedef struct st_io_cache IO_CACHE;
39
 
}
40
 
 
41
 
class Unique : public memory::SqlAlloc
42
 
{
 
32
class Unique :public Sql_alloc
 
33
{
 
34
  DYNAMIC_ARRAY file_ptrs;
 
35
  ulong max_elements;
43
36
  size_t max_in_memory_size;
 
37
  IO_CACHE file;
44
38
  TREE tree;
45
39
  unsigned char *record_pointers;
 
40
  bool flush();
46
41
  uint32_t size;
47
42
 
48
43
public:
53
48
  ulong elements_in_tree() { return tree.elements_in_tree; }
54
49
  inline bool unique_add(void *ptr)
55
50
  {
56
 
    return (not tree_insert(&tree, ptr, 0, tree.custom_arg));
 
51
    if (tree.elements_in_tree > max_elements && flush())
 
52
      return(1);
 
53
    return(!tree_insert(&tree, ptr, 0, tree.custom_arg));
57
54
  }
58
55
 
59
56
  bool get(Table *table);
60
57
  static double get_use_cost(uint32_t *buffer, uint32_t nkeys, uint32_t key_size,
61
58
                             size_t max_in_memory_size);
62
59
  inline static int get_cost_calc_buff_size(ulong nkeys, uint32_t key_size,
63
 
                                            size_t sortbuff_size)
 
60
                                            size_t max_in_memory_size)
64
61
  {
65
62
    register size_t max_elems_in_tree=
66
 
      (1 + sortbuff_size / ALIGN_SIZE(sizeof(TREE_ELEMENT)+key_size));
 
63
      (1 + max_in_memory_size / ALIGN_SIZE(sizeof(TREE_ELEMENT)+key_size));
67
64
    return (int) (sizeof(uint32_t)*(1 + nkeys/max_elems_in_tree));
68
65
  }
69
66
 
70
67
  void reset();
71
68
  bool walk(tree_walk_action action, void *walk_action_arg);
72
69
 
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);
 
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);
75
72
};
76
73
 
77
 
} /* namespace drizzled */
78
 
 
79
74
#endif /* DRIZZLED_UNIQUE_H */