INGOR
ytIntArray.h
1/*
2 ytIntArray.{h,c} : Expanable int Array
3 Copyright (C) 2016, Yoshinori Tamada <tamada A T ytlab.jp>
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
9
10 * Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12
13 * Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in
15 the documentation and/or other materials provided with the
16 distribution.
17
18 * Neither the name of Kyoto University nor the names of its
19 contributors may be used to endorse or promote products derived
20 from this software without specific prior written permission.
21
22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 POSSIBILITY OF SUCH DAMAGE.
34*/
35
36#ifndef __YTLIB_INT_ARRAY_H
37#define __YTLIB_INT_ARRAY_H
38
39#include <stdio.h>
40#include <stdlib.h>
41
42#include "lang/ytObject.h"
43
44#define ytIntArray_ERROR_VALUE ((size_t) -1)
45
50/*typedef struct ytIntArray_t ytIntArray;*/
51#ifndef DOXY
52typedef struct ytIntArray_t {
53 ytObject obj;
54 int * ptr;
55 size_t size;
56 size_t buff_size;
58#endif
59
60#ifdef YTLIB_MEMCHECK
61#define ytIntArray_new() ytIntArray_newm(__FILE__,__LINE__)
62ytIntArray * ytIntArray_newm(const char * file, int line);
63#else
65#endif
66void ytIntArray_delete(ytIntArray * this);
67void ytIntArray_deletev(void * this);
69void ytIntArray_deleteAllv(void * this);
71ytObject * ytIntArray_cloneI(const ytObject * this);
72ytIntArray * ytIntArray_arrayNew(size_t size);
73void ytIntArray_arrayDelete(ytIntArray * this, size_t size);
74void ytIntArray_dump(const ytIntArray * this, FILE * fp);
75void ytIntArray_dumpv(const ytObject * this, FILE * fp);
76size_t ytIntArray_size(const ytIntArray * this);
77size_t ytIntArray_buffSize(const ytIntArray * this);
78size_t ytIntArray_memSize(const ytIntArray * this);
79size_t ytIntArray_arrayMemSize(const ytIntArray * this, size_t n);
80void ytIntArray_clear(ytIntArray * this);
81ytIntArray * ytIntArray_setBuffSize(ytIntArray * this, size_t new_size);
82void ytIntArray_add(ytIntArray * this, int value);
83void ytIntArray_addIntArray(ytIntArray * this, const ytIntArray * values);
84void ytIntArray_set(ytIntArray * this, size_t index, int value);
85void ytIntArray_setSize(ytIntArray * this, size_t size);
86void ytIntArray_insert(ytIntArray * this, size_t index, int value);
87int ytIntArray_remove(ytIntArray * this, size_t index);
88void ytIntArray_copy(ytIntArray * this, const ytIntArray * src);
89void ytIntArray_copyArray(ytIntArray * this, size_t index, const int * array, size_t size);
90int ytIntArray_get(const ytIntArray * this, size_t index);
91int ytIntArray_pop(ytIntArray * this);
92int * ytIntArray_ptr(ytIntArray * this);
93void ytIntArray_sort(ytIntArray * this);
94size_t ytIntArray_find(const ytIntArray * this, const int v);
95void ytIntArray_print(const ytIntArray * this, FILE * fp, char * delim);
96int ytIntArray_sprint(const ytIntArray * this, char * buff, size_t size, char * delim);
97ytObject * ytIntArray_obj(ytIntArray * this);
98ytObject * ytIntArray_pObj(ytIntArray ** ptr);
99ytIntArray * ytIntArray_from(ytObject * this);
100ytIntArray ** ytIntArray_objP(ytObject * this);
101size_t ytIntArray_memorySize(const ytIntArray * this);
102size_t ytIntArray_memorySizeI(const ytObject * this);
103ytByte * ytIntArray_serializeI(const ytObject * obj, ytByte ** pptr);
104ytByte * ytIntArray_serialize(const ytIntArray * this, ytByte ** pptr);
105ytIntArray * ytIntArray_deserialize(ytByte ** const pptr);
106ytObject * ytIntArray_deserializeI(ytByte ** const ptr);
107#ifdef USE_MPI
108#include <mpi.h>
109void ytIntArray_MPI_Bcast(ytIntArray ** pObj, int root, MPI_Comm comm);
110void ytIntArray_MPI_BcastI(ytObject ** pObject, int root, MPI_Comm comm);
111#endif
112
113#endif /* __YTLIB_INT_ARRAY_H */
Expandable array.
void ytIntArray_copy(ytIntArray *this, const ytIntArray *src)
Copies values in another array into this.
Definition: ytIntArray.c:404
ytIntArray * ytIntArray_arrayNew(size_t size)
Creates the array of ytIntArray instances.
Definition: ytIntArray.c:180
ytIntArray * ytIntArray_setBuffSize(ytIntArray *this, size_t new_size)
Changes the size of buffer.
Definition: ytIntArray.c:239
void ytIntArray_MPI_Bcast(ytIntArray **pObject, int root, MPI_Comm comm)
Broadcasts the array with MPI.
Definition: ytIntArray.c:648
ytIntArray * ytIntArray_new()
Creates a new ytIntArray instance.
Definition: ytIntArray.c:84
size_t ytIntArray_arrayMemSize(const ytIntArray *this, size_t n)
Returns the total size of memory used by the array of the array.
Definition: ytIntArray.c:266
ytObject * ytIntArray_cloneI(const ytObject *this)
Returns the clone of this ytIntArray instance.
Definition: ytIntArray.c:153
size_t ytIntArray_find(const ytIntArray *this, const int v)
Returns the index of the value identical to the given one.
Definition: ytIntArray.c:466
void ytIntArray_deleteAll(ytIntArray *this)
Releases the array and all the elements in the array.
Definition: ytIntArray.c:114
size_t ytIntArray_memSize(const ytIntArray *this)
Returns the size of memory where the specified instance occupies.
Definition: ytIntArray.c:258
void ytIntArray_clear(ytIntArray *this)
Removes all the elements in the array.
Definition: ytIntArray.c:280
void ytIntArray_add(ytIntArray *this, int value)
Adds a value.
Definition: ytIntArray.c:288
size_t ytIntArray_buffSize(const ytIntArray *this)
Returns the current buffer size allocated.
Definition: ytIntArray.c:227
void ytIntArray_insert(ytIntArray *this, size_t index, int value)
Inserts a value at the specified position.
Definition: ytIntArray.c:369
int ytIntArray_pop(ytIntArray *this)
Returns the last element.
Definition: ytIntArray.c:440
void ytIntArray_sort(ytIntArray *this)
Sorts the elements in ascending order.
Definition: ytIntArray.c:457
ytIntArray * ytIntArray_clone(const ytIntArray *this)
Returns the clone of this ytIntArray instance.
Definition: ytIntArray.c:138
void ytIntArray_set(ytIntArray *this, size_t index, int value)
Sets a value at the specified position.
Definition: ytIntArray.c:323
void ytIntArray_setSize(ytIntArray *this, size_t size)
Changes the size of the array.
Definition: ytIntArray.c:357
void ytIntArray_arrayDelete(ytIntArray *this, size_t size)
Deletes the array of ytIntArray instances.
Definition: ytIntArray.c:197
void ytIntArray_print(const ytIntArray *this, FILE *fp, char *delim)
Prints the elements in the array.
Definition: ytIntArray.c:480
void ytIntArray_copyArray(ytIntArray *this, size_t index, const int *array, size_t size)
Copies values in an array into this array.
Definition: ytIntArray.c:418
int ytIntArray_remove(ytIntArray *this, size_t index)
Definition: ytIntArray.c:392
The basis class.