Drizzled Public API Documentation

ut0vec.cc

00001 /*****************************************************************************
00002 
00003 Copyright (C) 2006, 2009, Innobase Oy. All Rights Reserved.
00004 
00005 This program is free software; you can redistribute it and/or modify it under
00006 the terms of the GNU General Public License as published by the Free Software
00007 Foundation; version 2 of the License.
00008 
00009 This program is distributed in the hope that it will be useful, but WITHOUT
00010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00011 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
00012 
00013 You should have received a copy of the GNU General Public License along with
00014 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
00015 St, Fifth Floor, Boston, MA 02110-1301 USA
00016 
00017 *****************************************************************************/
00018 
00019 /*******************************************************************/
00026 #include "ut0vec.h"
00027 #ifdef UNIV_NONINL
00028 #include "ut0vec.ic"
00029 #endif
00030 #include <string.h>
00031 
00032 /****************************************************************/
00035 UNIV_INTERN
00036 ib_vector_t*
00037 ib_vector_create(
00038 /*=============*/
00039   mem_heap_t* heap, 
00040   ulint   size) 
00041 {
00042   ut_a(size > 0);
00043 
00044   ib_vector_t *vec = static_cast<ib_vector_t*>(mem_heap_alloc(heap, sizeof(*vec)));
00045 
00046   vec->heap = heap;
00047   vec->data = static_cast<void **>(mem_heap_alloc(heap, sizeof(void*) * size));
00048   vec->used = 0;
00049   vec->total = size;
00050 
00051   return(vec);
00052 }
00053 
00054 /****************************************************************/
00056 UNIV_INTERN
00057 void
00058 ib_vector_push(
00059 /*===========*/
00060   ib_vector_t*  vec,  
00061   void*   elem) 
00062 {
00063   if (vec->used >= vec->total) {
00064     void**  new_data;
00065     ulint new_total = vec->total * 2;
00066 
00067     new_data = static_cast<void **>(mem_heap_alloc(vec->heap,
00068           sizeof(void*) * new_total));
00069     memcpy(new_data, vec->data, sizeof(void*) * vec->total);
00070 
00071     vec->data = static_cast<void **>(new_data);
00072     vec->total = new_total;
00073   }
00074 
00075   vec->data[vec->used] = elem;
00076   vec->used++;
00077 }