| 1 |
/***************************************************************************** |
| 2 |
|
| 3 |
Copyright (c) 2006, 2026, Oracle and/or its affiliates. |
| 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, version 2.0, as published by the |
| 7 |
Free Software Foundation. |
| 8 |
|
| 9 |
This program is designed to work with certain software (including |
| 10 |
but not limited to OpenSSL) that is licensed under separate terms, |
| 11 |
as designated in a particular file or component or in included license |
| 12 |
documentation. The authors of MySQL hereby grant you an additional |
| 13 |
permission to link the program and your derivative works with the |
| 14 |
separately licensed software that they have either included with |
| 15 |
the program or referenced in the documentation. |
| 16 |
|
| 17 |
This program is distributed in the hope that it will be useful, but WITHOUT |
| 18 |
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 19 |
FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0, |
| 20 |
for more details. |
| 21 |
|
| 22 |
You should have received a copy of the GNU General Public License along with |
| 23 |
this program; if not, write to the Free Software Foundation, Inc., |
| 24 |
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 25 |
|
| 26 |
*****************************************************************************/ |
| 27 |
|
| 28 |
/** @file ut/ut0vec.cc |
| 29 |
A vector of pointers to data items |
| 30 |
|
| 31 |
Created 4/6/2006 Osku Salerma |
| 32 |
************************************************************************/ |
| 33 |
|
| 34 |
#include "ut0vec.h" |
| 35 |
#include "mem0mem.h" |
| 36 |
|
| 37 |
/******************************************************************** |
| 38 |
Create a new vector with the given initial size. */ |
| 39 |
ib_vector_t *ib_vector_create( |
| 40 |
/* out: vector */ |
| 41 |
ib_alloc_t *allocator, /* in: vector allocator */ |
| 42 |
ulint sizeof_value, /* in: size of data item */ |
| 43 |
ulint size) /* in: initial size */ |
| 44 |
{ |
| 45 |
ib_vector_t *vec; |
| 46 |
|
| 47 |
ut_a(size > 0); |
| 48 |
|
| 49 |
vec = static_cast<ib_vector_t *>( |
| 50 |
allocator->mem_malloc(allocator, sizeof(*vec))); |
| 51 |
|
| 52 |
vec->used = 0; |
| 53 |
vec->total = size; |
| 54 |
vec->allocator = allocator; |
| 55 |
vec->sizeof_value = sizeof_value; |
| 56 |
|
| 57 |
vec->data = static_cast<void *>( |
| 58 |
allocator->mem_malloc(allocator, vec->sizeof_value * size)); |
| 59 |
|
| 60 |
return (vec); |
| 61 |
} |
| 62 |
|
| 63 |
/******************************************************************** |
| 64 |
Resize the vector, currently the vector can only grow and we |
| 65 |
expand the number of elements it can hold by 2 times. */ |
| 66 |
void ib_vector_resize(ib_vector_t *vec) /* in: vector */ |
| 67 |
{ |
| 68 |
ulint new_total = vec->total * 2; |
| 69 |
ulint old_size = vec->used * vec->sizeof_value; |
| 70 |
ulint new_size = new_total * vec->sizeof_value; |
| 71 |
|
| 72 |
vec->data = static_cast<void *>(vec->allocator->mem_resize( |
| 73 |
vec->allocator, vec->data, old_size, new_size)); |
| 74 |
|
| 75 |
vec->total = new_total; |
| 76 |
} |