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 #pragma once 00027 #ifndef IB_VECTOR_H 00028 #define IB_VECTOR_H 00029 00030 #include "univ.i" 00031 #include "mem0mem.h" 00032 00034 typedef struct ib_vector_struct ib_vector_t; 00035 00036 /* An automatically resizing vector datatype with the following properties: 00037 00038 -Contains void* items. 00039 00040 -The items are owned by the caller. 00041 00042 -All memory allocation is done through a heap owned by the caller, who is 00043 responsible for freeing it when done with the vector. 00044 00045 -When the vector is resized, the old memory area is left allocated since it 00046 uses the same heap as the new memory area, so this is best used for 00047 relatively small or short-lived uses. 00048 */ 00049 00050 /****************************************************************/ 00053 UNIV_INTERN 00054 ib_vector_t* 00055 ib_vector_create( 00056 /*=============*/ 00057 mem_heap_t* heap, 00058 ulint size); 00060 /****************************************************************/ 00062 UNIV_INTERN 00063 void 00064 ib_vector_push( 00065 /*===========*/ 00066 ib_vector_t* vec, 00067 void* elem); 00069 /****************************************************************/ 00072 UNIV_INLINE 00073 ulint 00074 ib_vector_size( 00075 /*===========*/ 00076 const ib_vector_t* vec); 00078 /****************************************************************/ 00081 UNIV_INLINE 00082 ibool 00083 ib_vector_is_empty( 00084 /*===============*/ 00085 const ib_vector_t* vec); 00087 /****************************************************************/ 00090 UNIV_INLINE 00091 void* 00092 ib_vector_get( 00093 /*==========*/ 00094 ib_vector_t* vec, 00095 ulint n); 00097 /****************************************************************/ 00099 UNIV_INLINE 00100 void* 00101 ib_vector_pop( 00102 /*==========*/ 00103 ib_vector_t* vec); 00105 /****************************************************************/ 00108 UNIV_INLINE 00109 void 00110 ib_vector_free( 00111 /*===========*/ 00112 ib_vector_t* vec); 00115 struct ib_vector_struct { 00116 mem_heap_t* heap; 00117 void** data; 00118 ulint used; 00119 ulint total; 00120 }; 00121 00122 #ifndef UNIV_NONINL 00123 #include "ut0vec.ic" 00124 #endif 00125 00126 #endif