NCBI C++ ToolKit
blast_dynarray.h
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: blast_dynarray.h 33815 2007-05-04 17:18:18Z kazimird $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: Christiam Camacho
27  *
28  */
29 
30 /** @file blast_dynarray.h
31  * Declarations for various dynamic array types
32  */
33 
34 #ifndef ALGO_BLAST_CORE__BLAST_DYNARRAY__H
35 #define ALGO_BLAST_CORE__BLAST_DYNARRAY__H
36 
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 /** Data structure to maintain a dynamically allocated array of Uint4 */
45 typedef struct SDynamicUint4Array {
46  Uint4 num_used; /**< number of elements used in this array */
47  Uint4 num_allocated; /**< size of array below */
48  Uint4* data; /**< array of Uint4 */
50 
51 /** Initial number of elements allocated */
52 #define INIT_NUM_ELEMENTS 8
53 
54 /** Allocate a dynamic array of Uint4 with the initial size of
55  * INIT_NUM_ELEMENTS
56  * @return NULL if out of memory otherwise, newly allocated structure
57  */
60 
61 /** Allocate a dynamic array of Uint4 with an initial size of specified as an
62  * argument to the function
63  * @param init_num_elements Number of elements initially allocated [in]
64  * @return NULL if out of memory otherwise, newly allocated structure
65  */
67 DynamicUint4ArrayNewEx(Uint4 init_num_elements);
68 
69 /** Deallocates a dynamic array structure
70  * @param arr data structure to free [in]
71  * @return NULL
72  */
75 
76 /** Append a Uint4 to the dynamic array structure
77  * @param arr data structure to manipulate [in]
78  * @param element element to add [in]
79  * @return 0 on success or BLASTERR_MEMORY if memory reallocation was needed
80  * and this failed
81  */
84 
85 /** Make a deep copy of the src dynamic array
86  * @param src data structure to duplicate [in]
87  * @return newly allocated data structure or NULL if out of memory
88  */
91 
92 /** Make a shallow copy of the src dynamic array into the dest dynamic array
93  * @param dest data structure to copy to. Its contents will be overwritten and
94  * memory might be allocated if necessary [in|out]
95  * @param src data structure to copy from [in]
96  * @return newly allocated data structure or NULL if out of memory
97  */
100  const SDynamicUint4Array* src);
101 
102 /** Compares dynamic arrays a and b for equality of its contents
103  * @param a dynamic array to compare [in]
104  * @param b dynamic array to compare [in]
105  * @return TRUE if equal, FALSE otherwise
106  */
109  const SDynamicUint4Array* b);
110 
111 /* ========================================================================== */
112 /** Data structure to maintain a dynamically allocated array of Int4 */
113 typedef struct SDynamicInt4Array {
114  Uint4 num_used; /**< number of elements used in this array */
115  Uint4 num_allocated; /**< size of array below */
116  Int4* data; /**< array of Int4 */
118 
119 /** Allocate a dynamic array of Int4 with the initial size of
120  * INIT_NUM_ELEMENTS
121  * @return NULL if out of memory otherwise, newly allocated structure
122  */
125 
126 /** Deallocates a dynamic array structure
127  * @param arr data structure to free [in]
128  * @return NULL
129  */
132 
133 /** Append a Int4 to the dynamic array structure
134  * @param arr data structure to manipulate [in]
135  * @param element element to add [in]
136  * @return 0 on success or BLASTERR_MEMORY if memory reallocation was needed
137  * and this failed
138  */
141 
142 /* ========================================================================== */
143 /** Elements of the SDynamicSGenCodeNodeArray dynamic array */
144 typedef struct SGenCodeNode {
145  Uint4 gc_id; /**< Genetic code id */
146  Uint1* gc_str; /**< Genetic code string */
148 
149 /** Initial number of elements allocated, based on the fact that there are only
150  * a handful of genetic codes available in the NCBI toolkits */
151 #define INIT_NUM_GEN_CODES 30
152 
153 /** Data structure to maintain a dynamically allocated array of SGenCodeNode */
155  Uint4 num_used; /**< number of elements used in this array */
156  Uint4 num_allocated; /**< size of array below */
157  SGenCodeNode* data; /**< array of SGenCodeNode */
159 
160 /** Allocate a dynamic array of SGenCodeNode with the initial size of
161  * INIT_NUM_ELEMENTS
162  * @return NULL if out of memory otherwise, newly allocated structure
163  */
166 
167 /** Deallocates a dynamic array structure
168  * @param arr data structure to free [in]
169  * @return NULL
170  */
173 
174 /** Append a SGenCodeNode to the dynamic array structure
175  * @note No duplicate elements will be inserted
176  * @param arr data structure to manipulate [in]
177  * @param element element to add [in]
178  * @return 0 on success or BLASTERR_MEMORY if memory reallocation was needed
179  * and this failed, or BLASTERR_INVALIDPARAM if the genetic string field of the
180  * element is NULL.
181  */
184  SGenCodeNode element);
185 
186 /** Searches the dynamic array for any element that matches the requested
187  * genetic code id
188  * @param arr dynamic array to search [in]
189  * @param gen_code_id genetic code id to search [in]
190  * @return genetic code string (owned by this structure) or NULL if not found
191  */
192 Uint1*
194  Uint4 gen_code_id);
195 
196 
197 #ifdef __cplusplus
198 }
199 #endif
200 #endif /* !ALGO_BLAST_CORE__BLAST_DYNARRAY__H */
Int2 DynamicUint4Array_Append(SDynamicUint4Array *arr, Uint4 element)
Append a Uint4 to the dynamic array structure.
struct SDynamicUint4Array SDynamicUint4Array
Data structure to maintain a dynamically allocated array of Uint4.
Int2 DynamicInt4Array_Append(SDynamicInt4Array *arr, Int4 element)
Append a Int4 to the dynamic array structure.
struct SDynamicInt4Array SDynamicInt4Array
Data structure to maintain a dynamically allocated array of Int4.
SDynamicSGenCodeNodeArray * DynamicSGenCodeNodeArrayFree(SDynamicSGenCodeNodeArray *arr)
Deallocates a dynamic array structure.
SDynamicUint4Array * DynamicUint4Array_Dup(const SDynamicUint4Array *src)
Make a deep copy of the src dynamic array.
SDynamicInt4Array * DynamicInt4ArrayNew()
Allocate a dynamic array of Int4 with the initial size of INIT_NUM_ELEMENTS.
Int2 DynamicSGenCodeNodeArray_Append(SDynamicSGenCodeNodeArray *arr, SGenCodeNode element)
Append a SGenCodeNode to the dynamic array structure.
Int4 DynamicUint4Array_Copy(SDynamicUint4Array *dest, const SDynamicUint4Array *src)
Make a shallow copy of the src dynamic array into the dest dynamic array.
struct SGenCodeNode SGenCodeNode
Elements of the SDynamicSGenCodeNodeArray dynamic array.
SDynamicSGenCodeNodeArray * DynamicSGenCodeNodeArrayNew()
Allocate a dynamic array of SGenCodeNode with the initial size of INIT_NUM_ELEMENTS.
Uint1 * DynamicSGenCodeNodeArray_Find(const SDynamicSGenCodeNodeArray *arr, Uint4 gen_code_id)
Searches the dynamic array for any element that matches the requested genetic code id.
SDynamicUint4Array * DynamicUint4ArrayNew()
Allocate a dynamic array of Uint4 with the initial size of INIT_NUM_ELEMENTS.
SDynamicUint4Array * DynamicUint4ArrayNewEx(Uint4 init_num_elements)
Allocate a dynamic array of Uint4 with an initial size of specified as an argument to the function.
Boolean DynamicUint4Array_AreEqual(const SDynamicUint4Array *a, const SDynamicUint4Array *b)
Compares dynamic arrays a and b for equality of its contents.
struct SDynamicSGenCodeNodeArray SDynamicSGenCodeNodeArray
Data structure to maintain a dynamically allocated array of SGenCodeNode.
SDynamicInt4Array * DynamicInt4ArrayFree(SDynamicInt4Array *arr)
Deallocates a dynamic array structure.
SDynamicUint4Array * DynamicUint4ArrayFree(SDynamicUint4Array *arr)
Deallocates a dynamic array structure.
Defines to provide correct exporting from BLAST DLL in Windows.
#define NCBI_XBLAST_EXPORT
NULL operations for other cases.
Definition: blast_export.h:65
uint8_t Uint1
1-byte (8-bit) unsigned integer
Definition: ncbitype.h:99
int16_t Int2
2-byte (16-bit) signed integer
Definition: ncbitype.h:100
int32_t Int4
4-byte (32-bit) signed integer
Definition: ncbitype.h:102
uint32_t Uint4
4-byte (32-bit) unsigned integer
Definition: ncbitype.h:103
unsigned int a
Definition: ncbi_localip.c:102
Type and macro definitions from C toolkit that are not defined in C++ toolkit.
Uint1 Boolean
bool replacment for C
Definition: ncbi_std.h:94
Data structure to maintain a dynamically allocated array of Int4.
Int4 * data
array of Int4
Uint4 num_allocated
size of array below
Uint4 num_used
number of elements used in this array
Data structure to maintain a dynamically allocated array of SGenCodeNode.
SGenCodeNode * data
array of SGenCodeNode
Uint4 num_used
number of elements used in this array
Uint4 num_allocated
size of array below
Data structure to maintain a dynamically allocated array of Uint4.
Uint4 * data
array of Uint4
Uint4 num_used
number of elements used in this array
Uint4 num_allocated
size of array below
Elements of the SDynamicSGenCodeNodeArray dynamic array.
Uint1 * gc_str
Genetic code string.
Uint4 gc_id
Genetic code id.
Modified on Sat May 25 14:19:45 2024 by modify_doxy.py rev. 669887