00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #pragma once
00022
00023 #include <drizzled/tree.h>
00024
00025
00026
00027
00028
00029
00030
00031
00032 namespace drizzled
00033 {
00034
00035 namespace internal
00036 {
00037 typedef struct st_io_cache IO_CACHE;
00038 }
00039
00040 class Unique : public memory::SqlAlloc
00041 {
00042 size_t max_in_memory_size;
00043 TREE tree;
00044 unsigned char *record_pointers;
00045 uint32_t size;
00046
00047 public:
00048 ulong elements;
00049 Unique(qsort_cmp2 comp_func, void *comp_func_fixed_arg,
00050 uint32_t size_arg, size_t max_in_memory_size_arg);
00051 ~Unique();
00052 ulong elements_in_tree() { return tree.elements_in_tree; }
00053 inline bool unique_add(void *ptr)
00054 {
00055 return (not tree_insert(&tree, ptr, 0, tree.custom_arg));
00056 }
00057
00058 bool get(Table *table);
00059 static double get_use_cost(uint32_t *buffer, uint32_t nkeys, uint32_t key_size,
00060 size_t max_in_memory_size);
00061 inline static int get_cost_calc_buff_size(ulong nkeys, uint32_t key_size,
00062 size_t sortbuff_size)
00063 {
00064 register size_t max_elems_in_tree=
00065 (1 + sortbuff_size / ALIGN_SIZE(sizeof(TREE_ELEMENT)+key_size));
00066 return (int) (sizeof(uint32_t)*(1 + nkeys/max_elems_in_tree));
00067 }
00068
00069 void reset();
00070 bool walk(tree_walk_action action, void *walk_action_arg);
00071
00072 friend int unique_write_to_file(unsigned char* key, uint32_t count, Unique *unique);
00073 friend int unique_write_to_ptrs(unsigned char* key, uint32_t count, Unique *unique);
00074 };
00075
00076 }
00077