~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/unique.h

  • Committer: Brian Aker
  • Date: 2010-08-12 17:19:46 UTC
  • mfrom: (1701.1.1 turn-off-csv)
  • Revision ID: brian@tangent.org-20100812171946-n44naaqhg27gehlh
MErge Monty, remove CSV from auto-build

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>
 
24
#include "drizzled/tree.h"
25
25
/*
26
26
   Unique -- class for unique (removing of duplicates).
27
27
   Puts all values to the TREE. If the tree becomes too big,
40
40
 
41
41
class Unique : public memory::SqlAlloc
42
42
{
 
43
  DYNAMIC_ARRAY file_ptrs;
 
44
  ulong max_elements;
43
45
  size_t max_in_memory_size;
 
46
  internal::IO_CACHE *file;
44
47
  TREE tree;
45
48
  unsigned char *record_pointers;
 
49
  bool flush();
46
50
  uint32_t size;
47
51
 
48
52
public:
53
57
  ulong elements_in_tree() { return tree.elements_in_tree; }
54
58
  inline bool unique_add(void *ptr)
55
59
  {
56
 
    return (not tree_insert(&tree, ptr, 0, tree.custom_arg));
 
60
    if (tree.elements_in_tree > max_elements && flush())
 
61
      return(1);
 
62
    return(!tree_insert(&tree, ptr, 0, tree.custom_arg));
57
63
  }
58
64
 
59
65
  bool get(Table *table);
60
66
  static double get_use_cost(uint32_t *buffer, uint32_t nkeys, uint32_t key_size,
61
67
                             size_t max_in_memory_size);
62
68
  inline static int get_cost_calc_buff_size(ulong nkeys, uint32_t key_size,
63
 
                                            size_t sortbuff_size)
 
69
                                            size_t max_in_memory_size)
64
70
  {
65
71
    register size_t max_elems_in_tree=
66
 
      (1 + sortbuff_size / ALIGN_SIZE(sizeof(TREE_ELEMENT)+key_size));
 
72
      (1 + max_in_memory_size / ALIGN_SIZE(sizeof(TREE_ELEMENT)+key_size));
67
73
    return (int) (sizeof(uint32_t)*(1 + nkeys/max_elems_in_tree));
68
74
  }
69
75