INGOR
ytDoubleArray.h
1/*
2 ytDoubleArray.{h,c} : Expanable double 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_DOUBLE_ARRAY_H
37#define __YTLIB_DOUBLE_ARRAY_H
38
39#include <stdio.h>
40#include <stdlib.h>
41
42#include "lang/ytObject.h"
43
44#define ytDoubleArray_ERROR_VALUE ((size_t) -1)
45
50/*typedef struct ytDoubleArray_t ytDoubleArray;*/
51#ifndef DOXY
52typedef struct ytDoubleArray_t {
53 ytObject obj;
54 double * ptr;
55 size_t size;
56 size_t buff_size;
58#endif
59
60#ifdef YTLIB_MEMCHECK
61#define ytDoubleArray_new() ytDoubleArray_newm(__FILE__,__LINE__)
62ytDoubleArray * ytDoubleArray_newm(const char * file, int line);
63#else
65#endif
66void ytDoubleArray_delete(ytDoubleArray * this);
67void ytDoubleArray_deletev(void * this);
69void ytDoubleArray_deleteAllv(void * this);
73void ytDoubleArray_arrayDelete(ytDoubleArray * this, size_t size);
74void ytDoubleArray_dump(const ytDoubleArray * this, FILE * fp);
75void ytDoubleArray_dumpv(const ytObject * this, FILE * fp);
76size_t ytDoubleArray_size(const ytDoubleArray * this);
77size_t ytDoubleArray_buffSize(const ytDoubleArray * this);
78size_t ytDoubleArray_memSize(const ytDoubleArray * this);
79size_t ytDoubleArray_arrayMemSize(const ytDoubleArray * this, size_t n);
82void ytDoubleArray_add(ytDoubleArray * this, double value);
83void ytDoubleArray_addDoubleArray(ytDoubleArray * this, const ytDoubleArray * values);
84void ytDoubleArray_set(ytDoubleArray * this, size_t index, double value);
85void ytDoubleArray_setSize(ytDoubleArray * this, size_t size);
86void ytDoubleArray_insert(ytDoubleArray * this, size_t index, double value);
87double ytDoubleArray_remove(ytDoubleArray * this, size_t index);
88void ytDoubleArray_copy(ytDoubleArray * this, const ytDoubleArray * src);
89void ytDoubleArray_copyArray(ytDoubleArray * this, size_t index, const double * array, size_t size);
90double ytDoubleArray_get(const ytDoubleArray * this, size_t index);
91double ytDoubleArray_pop(ytDoubleArray * this);
92double * ytDoubleArray_ptr(ytDoubleArray * this);
94size_t ytDoubleArray_find(const ytDoubleArray * this, const double v);
95void ytDoubleArray_print(const ytDoubleArray * this, FILE * fp, char * delim);
96int ytDoubleArray_sprint(const ytDoubleArray * this, char * buff, size_t size, char * delim);
97ytObject * ytDoubleArray_obj(ytDoubleArray * this);
98ytObject * ytDoubleArray_pObj(ytDoubleArray ** ptr);
99ytDoubleArray * ytDoubleArray_from(ytObject * this);
100ytDoubleArray ** ytDoubleArray_objP(ytObject * this);
101size_t ytDoubleArray_memorySize(const ytDoubleArray * this);
102size_t ytDoubleArray_memorySizeI(const ytObject * this);
103ytByte * ytDoubleArray_serializeI(const ytObject * obj, ytByte ** pptr);
104ytByte * ytDoubleArray_serialize(const ytDoubleArray * this, ytByte ** pptr);
105ytDoubleArray * ytDoubleArray_deserialize(ytByte ** const pptr);
106ytObject * ytDoubleArray_deserializeI(ytByte ** const ptr);
107#ifdef USE_MPI
108#include <mpi.h>
109void ytDoubleArray_MPI_Bcast(ytDoubleArray ** pObj, int root, MPI_Comm comm);
110void ytDoubleArray_MPI_BcastI(ytObject ** pObject, int root, MPI_Comm comm);
111#endif
112
113#endif /* __YTLIB_DOUBLE_ARRAY_H */
Expandable array.
void ytDoubleArray_print(const ytDoubleArray *this, FILE *fp, char *delim)
Prints the elements in the array.
Definition: ytDoubleArray.c:480
void ytDoubleArray_arrayDelete(ytDoubleArray *this, size_t size)
Deletes the array of ytDoubleArray instances.
Definition: ytDoubleArray.c:197
ytDoubleArray * ytDoubleArray_setBuffSize(ytDoubleArray *this, size_t new_size)
Changes the size of buffer.
Definition: ytDoubleArray.c:239
size_t ytDoubleArray_arrayMemSize(const ytDoubleArray *this, size_t n)
Returns the total size of memory used by the array of the array.
Definition: ytDoubleArray.c:266
void ytDoubleArray_set(ytDoubleArray *this, size_t index, double value)
Sets a value at the specified position.
Definition: ytDoubleArray.c:323
double ytDoubleArray_remove(ytDoubleArray *this, size_t index)
Definition: ytDoubleArray.c:392
void ytDoubleArray_copy(ytDoubleArray *this, const ytDoubleArray *src)
Copies values in another array into this.
Definition: ytDoubleArray.c:404
ytDoubleArray * ytDoubleArray_new()
Creates a new ytDoubleArray instance.
Definition: ytDoubleArray.c:84
size_t ytDoubleArray_memSize(const ytDoubleArray *this)
Returns the size of memory where the specified instance occupies.
Definition: ytDoubleArray.c:258
ytDoubleArray * ytDoubleArray_arrayNew(size_t size)
Creates the array of ytDoubleArray instances.
Definition: ytDoubleArray.c:180
void ytDoubleArray_insert(ytDoubleArray *this, size_t index, double value)
Inserts a value at the specified position.
Definition: ytDoubleArray.c:369
void ytDoubleArray_setSize(ytDoubleArray *this, size_t size)
Changes the size of the array.
Definition: ytDoubleArray.c:357
double ytDoubleArray_pop(ytDoubleArray *this)
Returns the last element.
Definition: ytDoubleArray.c:440
void ytDoubleArray_add(ytDoubleArray *this, double value)
Adds a value.
Definition: ytDoubleArray.c:288
void ytDoubleArray_MPI_Bcast(ytDoubleArray **pObject, int root, MPI_Comm comm)
Broadcasts the array with MPI.
Definition: ytDoubleArray.c:648
void ytDoubleArray_clear(ytDoubleArray *this)
Removes all the elements in the array.
Definition: ytDoubleArray.c:280
size_t ytDoubleArray_buffSize(const ytDoubleArray *this)
Returns the current buffer size allocated.
Definition: ytDoubleArray.c:227
size_t ytDoubleArray_find(const ytDoubleArray *this, const double v)
Returns the index of the value identical to the given one.
Definition: ytDoubleArray.c:466
void ytDoubleArray_deleteAll(ytDoubleArray *this)
Releases the array and all the elements in the array.
Definition: ytDoubleArray.c:114
ytDoubleArray * ytDoubleArray_clone(const ytDoubleArray *this)
Returns the clone of this ytDoubleArray instance.
Definition: ytDoubleArray.c:138
void ytDoubleArray_copyArray(ytDoubleArray *this, size_t index, const double *array, size_t size)
Copies values in an array into this array.
Definition: ytDoubleArray.c:418
ytObject * ytDoubleArray_cloneI(const ytObject *this)
Returns the clone of this ytDoubleArray instance.
Definition: ytDoubleArray.c:153
void ytDoubleArray_sort(ytDoubleArray *this)
Sorts the elements in ascending order.
Definition: ytDoubleArray.c:457
The basis class.