Drizzled Public API Documentation

ut0vec.cc
1 /*****************************************************************************
2 
3 Copyright (C) 2006, 2009, Innobase Oy. All Rights Reserved.
4 
5 This program is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free Software
7 Foundation; version 2 of the License.
8 
9 This program is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12 
13 You should have received a copy of the GNU General Public License along with
14 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
15 St, Fifth Floor, Boston, MA 02110-1301 USA
16 
17 *****************************************************************************/
18 
19 /*******************************************************************/
26 #include "ut0vec.h"
27 #ifdef UNIV_NONINL
28 #include "ut0vec.ic"
29 #endif
30 #include <string.h>
31 
32 /****************************************************************/
35 UNIV_INTERN
38 /*=============*/
39  mem_heap_t* heap,
40  ulint size)
41 {
42  ut_a(size > 0);
43 
44  ib_vector_t *vec = static_cast<ib_vector_t*>(mem_heap_alloc(heap, sizeof(*vec)));
45 
46  vec->heap = heap;
47  vec->data = static_cast<void **>(mem_heap_alloc(heap, sizeof(void*) * size));
48  vec->used = 0;
49  vec->total = size;
50 
51  return(vec);
52 }
53 
54 /****************************************************************/
56 UNIV_INTERN
57 void
59 /*===========*/
60  ib_vector_t* vec,
61  void* elem)
62 {
63  if (vec->used >= vec->total) {
64  void** new_data;
65  ulint new_total = vec->total * 2;
66 
67  new_data = static_cast<void **>(mem_heap_alloc(vec->heap,
68  sizeof(void*) * new_total));
69  memcpy(new_data, vec->data, sizeof(void*) * vec->total);
70 
71  vec->data = static_cast<void **>(new_data);
72  vec->total = new_total;
73  }
74 
75  vec->data[vec->used] = elem;
76  vec->used++;
77 }
UNIV_INTERN ib_vector_t * ib_vector_create(mem_heap_t *heap, ulint size)
Definition: ut0vec.cc:37
void ** data
Definition: ut0vec.h:136
mem_heap_t * heap
Definition: ut0vec.h:135
#define ut_a(EXPR)
Definition: ut0dbg.h:105
UNIV_INLINE void * mem_heap_alloc(mem_heap_t *heap, ulint n)
UNIV_INTERN void ib_vector_push(ib_vector_t *vec, void *elem)
Definition: ut0vec.cc:58