1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems, Inc.
4
* Copyright (C) 2008 Sun Microsystems
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
24
#include "drizzled/tree.h"
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.
38
typedef struct st_io_cache IO_CACHE;
41
class Unique : public memory::SqlAlloc
32
class Unique :public Sql_alloc
34
DYNAMIC_ARRAY file_ptrs;
43
36
size_t max_in_memory_size;
45
39
unsigned char *record_pointers;
53
48
ulong elements_in_tree() { return tree.elements_in_tree; }
54
49
inline bool unique_add(void *ptr)
56
return (not tree_insert(&tree, ptr, 0, tree.custom_arg));
51
if (tree.elements_in_tree > max_elements && flush())
53
return(!tree_insert(&tree, ptr, 0, tree.custom_arg));
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,
60
size_t max_in_memory_size)
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));
71
68
bool walk(tree_walk_action action, void *walk_action_arg);
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);
77
} /* namespace drizzled */
79
74
#endif /* DRIZZLED_UNIQUE_H */