1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
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.
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.
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
1
/* Copyright (C) 2003 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
20
16
#include <mysys/my_sys.h>
19
A typesafe wrapper around DYNAMIC_ARRAY
22
template <class Elem> class Dynamic_array
26
Dynamic_array(uint prealloc=16, uint increment=16)
28
init(prealloc, increment);
31
void init(uint prealloc=16, uint increment=16)
33
my_init_dynamic_array(&array, sizeof(Elem), prealloc, increment);
38
return *(((Elem*)array.buffer) + idx);
43
return (Elem*)array.buffer;
48
return ((Elem*)array.buffer) + array.elements;
53
return (insert_dynamic(&array, (uchar*)&el));
58
return array.elements;
68
delete_dynamic(&array);
71
typedef int (*CMP_FUNC)(const Elem *el1, const Elem *el2);
73
void sort(CMP_FUNC cmp_func)
75
my_qsort(array.buffer, array.elements, sizeof(Elem), (qsort_cmp)cmp_func);
23
81
Array of pointers to Elem that uses memory from MEM_ROOT
31
89
enum {alloc_increment = 16};
33
uint32_t n_elements, max_element;
91
uint n_elements, max_element;
35
Array(MEM_ROOT *mem_root, uint32_t prealloc=16)
93
Array(MEM_ROOT *mem_root, uint prealloc=16)
37
95
buffer= (Elem**)alloc_root(mem_root, prealloc * sizeof(Elem**));
38
96
max_element = buffer? prealloc : 0;