Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
fb452643
Commit
fb452643
authored
Apr 06, 2006
by
osku
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add ib_vector datatype.
parent
3d11e335
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
155 additions
and
2 deletions
+155
-2
Makefile.am
Makefile.am
+1
-1
include/ut0vec.h
include/ut0vec.h
+73
-0
include/ut0vec.ic
include/ut0vec.ic
+26
-0
ut/Makefile.am
ut/Makefile.am
+1
-1
ut/ut0vec.c
ut/ut0vec.c
+54
-0
No files found.
Makefile.am
View file @
fb452643
...
...
@@ -76,7 +76,7 @@ EXTRA_DIST = include/btr0btr.h include/btr0btr.ic include/btr0cur.h include/btr
include/univ.i include/usr0sess.h include/usr0sess.ic include/usr0types.h
\
include/ut0byte.h include/ut0byte.ic include/ut0dbg.h include/ut0lst.h
\
include/ut0mem.h include/ut0mem.ic include/ut0rnd.h include/ut0rnd.ic
\
include/ut0sort.h include/ut0ut.h include/ut0ut.ic
include/ut0sort.h include/ut0ut.h include/ut0ut.ic
include/ut0vec.h include/ut0vec.ic
# Don't update the files from bitkeeper
%
::
SCCS/s.%
include/ut0vec.h
0 → 100644
View file @
fb452643
#ifndef IB_VECTOR_H
#define IB_VECTOR_H
#include "univ.i"
#include "mem0mem.h"
typedef
struct
ib_vector_struct
ib_vector
;
/* An automatically resizing vector datatype with the following properties:
-Contains void* items.
-The items are owned by the caller.
-All memory allocation is done through a heap owned by the caller, who is
responsible for freeing it when done with the vector.
-When the vector is resized, the old memory area is left allocated since it
uses the same heap as the new memory area, so this is best used for
relatively small or short-lived uses.
*/
/********************************************************************
Create a new vector with the given initial size. */
ib_vector
*
ib_vector_create
(
/*=============*/
/* out: vector */
mem_heap_t
*
heap
,
/* in: heap */
ulint
size
);
/* in: initial size */
/********************************************************************
Push a new element to the vector, increasing its size if necessary. */
void
ib_vector_push
(
/*===========*/
ib_vector
*
vec
,
/* in: vector */
void
*
elem
);
/* in: data element */
/********************************************************************
Get the number of elements in the vector. */
UNIV_INLINE
ulint
ib_vector_size
(
/*===========*/
/* out: number of elements in vector */
ib_vector
*
vec
);
/* in: vector */
/********************************************************************
Get the n'th element. */
UNIV_INLINE
void
*
ib_vector_get
(
/*==========*/
/* out: n'th element */
ib_vector
*
vec
,
/* in: vector */
ulint
n
);
/* in: element index to get */
/* See comment at beginning of file. */
struct
ib_vector_struct
{
mem_heap_t
*
heap
;
/* heap */
void
**
data
;
/* data elements */
ulint
used
;
/* number of elements currently used */
ulint
total
;
/* number of elements allocated */
};
#ifndef UNIV_NONINL
#include "ut0vec.ic"
#endif
#endif
include/ut0vec.ic
0 → 100644
View file @
fb452643
/********************************************************************
Get number of elements in vector. */
UNIV_INLINE
ulint
ib_vector_size(
/*===========*/
/* out: number of elements in vector */
ib_vector* vec) /* in: vector */
{
return(vec->used);
}
/********************************************************************
Get n'th element. */
UNIV_INLINE
void*
ib_vector_get(
/*==========*/
/* out: n'th element */
ib_vector* vec, /* in: vector */
ulint n) /* in: element index to get */
{
ut_a(n < vec->used);
return(vec->data[n]);
}
ut/Makefile.am
View file @
fb452643
...
...
@@ -19,6 +19,6 @@ include ../include/Makefile.i
noinst_LIBRARIES
=
libut.a
libut_a_SOURCES
=
ut0byte.c ut0dbg.c ut0mem.c ut0rnd.c ut0ut.c
libut_a_SOURCES
=
ut0byte.c ut0dbg.c ut0mem.c ut0rnd.c ut0ut.c
ut0vec.c
EXTRA_PROGRAMS
=
ut/ut0vec.c
0 → 100644
View file @
fb452643
#include "ut0vec.h"
#ifdef UNIV_NONINL
#include "ut0vec.ic"
#endif
#include <string.h>
/********************************************************************
Create a new vector with the given initial size. */
ib_vector
*
ib_vector_create
(
/*=============*/
/* out: vector */
mem_heap_t
*
heap
,
/* in: heap */
ulint
size
)
/* in: initial size */
{
ib_vector
*
vec
;
ut_a
(
size
>
0
);
vec
=
mem_heap_alloc
(
heap
,
sizeof
(
*
vec
));
vec
->
heap
=
heap
;
vec
->
data
=
mem_heap_alloc
(
heap
,
sizeof
(
void
*
)
*
size
);
vec
->
used
=
0
;
vec
->
total
=
size
;
return
(
vec
);
}
/********************************************************************
Push a new element to the vector, increasing its size if necessary. */
void
ib_vector_push
(
/*===========*/
ib_vector
*
vec
,
/* in: vector */
void
*
elem
)
/* in: data element */
{
if
(
vec
->
used
>=
vec
->
total
)
{
void
**
new_data
;
ulint
new_total
=
vec
->
total
*
2
;
new_data
=
mem_heap_alloc
(
vec
->
heap
,
sizeof
(
void
*
)
*
new_total
);
memcpy
(
new_data
,
vec
->
data
,
sizeof
(
void
*
)
*
vec
->
total
);
vec
->
data
=
new_data
;
vec
->
total
=
new_total
;
}
vec
->
data
[
vec
->
used
]
=
elem
;
vec
->
used
++
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment