NCBI C++ ToolKit
Functions | Variables
blast_dynarray.c File Reference

Definitions for various dynamic array types. More...

#include "blast_dynarray.h"
#include <algo/blast/core/blast_util.h>
#include <algo/blast/core/blast_message.h>
+ Include dependency graph for blast_dynarray.c:

Go to the source code of this file.

Go to the SVN repository for this file.

Functions

SDynamicUint4ArrayDynamicUint4ArrayFree (SDynamicUint4Array *arr)
 Deallocates a dynamic array structure. More...
 
SDynamicUint4ArrayDynamicUint4ArrayNew ()
 Allocate a dynamic array of Uint4 with the initial size of INIT_NUM_ELEMENTS. More...
 
SDynamicUint4ArrayDynamicUint4ArrayNewEx (Uint4 init_num_elements)
 Allocate a dynamic array of Uint4 with an initial size of specified as an argument to the function. More...
 
static Int2 s_DynamicUint4Array_ReallocIfNecessary (SDynamicUint4Array *arr)
 Grow a dynamic array of Uint4 elements. More...
 
Int2 DynamicUint4Array_Append (SDynamicUint4Array *arr, Uint4 element)
 Append a Uint4 to the dynamic array structure. More...
 
SDynamicUint4ArrayDynamicUint4Array_Dup (const SDynamicUint4Array *src)
 Make a deep copy of the src dynamic array. More...
 
Int4 DynamicUint4Array_Copy (SDynamicUint4Array *dest, const SDynamicUint4Array *src)
 Make a shallow copy of the src dynamic array into the dest dynamic array. More...
 
Boolean DynamicUint4Array_AreEqual (const SDynamicUint4Array *a, const SDynamicUint4Array *b)
 Compares dynamic arrays a and b for equality of its contents. More...
 
SDynamicInt4ArrayDynamicInt4ArrayFree (SDynamicInt4Array *arr)
 Deallocates a dynamic array structure. More...
 
SDynamicInt4ArrayDynamicInt4ArrayNew ()
 Allocate a dynamic array of Int4 with the initial size of INIT_NUM_ELEMENTS. More...
 
static Int2 s_DynamicInt4Array_ReallocIfNecessary (SDynamicInt4Array *arr)
 Grow a dynamic array of Int4 elements. More...
 
Int2 DynamicInt4Array_Append (SDynamicInt4Array *arr, Int4 element)
 Append a Int4 to the dynamic array structure. More...
 
SDynamicSGenCodeNodeArrayDynamicSGenCodeNodeArrayFree (SDynamicSGenCodeNodeArray *arr)
 Deallocates a dynamic array structure. More...
 
SDynamicSGenCodeNodeArrayDynamicSGenCodeNodeArrayNew ()
 Allocate a dynamic array of SGenCodeNode with the initial size of INIT_NUM_ELEMENTS. More...
 
static Int2 s_DynamicSGenCodeNodeArray_ReallocIfNecessary (SDynamicSGenCodeNodeArray *arr)
 Grow a dynamic array of SGenCodeNode elements. More...
 
static Boolean s_DynamicSGenCodeNodeArray_IsSorted (const SDynamicSGenCodeNodeArray *arr)
 Determine if the array is sorted. More...
 
static int s_SGenCodeNodeCompare (const void *a, const void *b)
 Compare function for sorting SGenCodeNode elements. More...
 
static void s_DynamicSGenCodeNodeArray_Sort (SDynamicSGenCodeNodeArray *arr)
 Sort the dynamic array structure. More...
 
Int2 DynamicSGenCodeNodeArray_Append (SDynamicSGenCodeNodeArray *arr, SGenCodeNode element)
 Append a SGenCodeNode to the dynamic array structure. More...
 
static Int4 s_DynamicSGenCodeNodeArray_BinSearch (const SDynamicSGenCodeNodeArray *arr, Uint4 gen_code_id)
 Perform a binary search for the element containing gen_code_id. More...
 
Uint1DynamicSGenCodeNodeArray_Find (const SDynamicSGenCodeNodeArray *arr, Uint4 gen_code_id)
 Searches the dynamic array for any element that matches the requested genetic code id. More...
 

Variables

const size_t kResizeFactor = 2
 factor by which these arrays are resized More...
 

Detailed Description

Definitions for various dynamic array types.

Definition in file blast_dynarray.c.

Function Documentation

◆ DynamicInt4Array_Append()

Int2 DynamicInt4Array_Append ( SDynamicInt4Array arr,
Int4  element 
)

Append a Int4 to the dynamic array structure.

Parameters
arrdata structure to manipulate [in]
elementelement to add [in]
Returns
0 on success or BLASTERR_MEMORY if memory reallocation was needed and this failed

Definition at line 221 of file blast_dynarray.c.

References arr, ASSERT, and s_DynamicInt4Array_ReallocIfNecessary().

Referenced by SplitQueryBlk_AddContextToChunk().

◆ DynamicInt4ArrayFree()

SDynamicInt4Array* DynamicInt4ArrayFree ( SDynamicInt4Array arr)

Deallocates a dynamic array structure.

Parameters
arrdata structure to free [in]
Returns
NULL

Definition at line 170 of file blast_dynarray.c.

References arr, NULL, and sfree.

Referenced by DynamicInt4ArrayNew(), and SplitQueryBlkFree().

◆ DynamicInt4ArrayNew()

SDynamicInt4Array* DynamicInt4ArrayNew ( )

Allocate a dynamic array of Int4 with the initial size of INIT_NUM_ELEMENTS.

Returns
NULL if out of memory otherwise, newly allocated structure

Definition at line 182 of file blast_dynarray.c.

References calloc(), SDynamicInt4Array::data, DynamicInt4ArrayFree(), INIT_NUM_ELEMENTS, NULL, and SDynamicInt4Array::num_allocated.

Referenced by SplitQueryBlkNew().

◆ DynamicSGenCodeNodeArray_Append()

Int2 DynamicSGenCodeNodeArray_Append ( SDynamicSGenCodeNodeArray arr,
SGenCodeNode  element 
)

Append a SGenCodeNode to the dynamic array structure.

Note
No duplicate elements will be inserted
Parameters
arrdata structure to manipulate [in]
elementelement to add [in]
Returns
0 on success or BLASTERR_MEMORY if memory reallocation was needed and this failed, or BLASTERR_INVALIDPARAM if the genetic string field of the element is NULL.

Definition at line 342 of file blast_dynarray.c.

References arr, ASSERT, BLASTERR_INVALIDPARAM, BLASTERR_MEMORY, BlastMemDup(), DynamicSGenCodeNodeArray_Find(), SGenCodeNode::gc_id, SGenCodeNode::gc_str, GENCODE_STRLEN, NULL, s_DynamicSGenCodeNodeArray_ReallocIfNecessary(), and s_DynamicSGenCodeNodeArray_Sort().

Referenced by GenCodeSingletonAdd().

◆ DynamicSGenCodeNodeArray_Find()

Uint1* DynamicSGenCodeNodeArray_Find ( const SDynamicSGenCodeNodeArray arr,
Uint4  gen_code_id 
)

Searches the dynamic array for any element that matches the requested genetic code id.

Parameters
arrdynamic array to search [in]
gen_code_idgenetic code id to search [in]
Returns
genetic code string (owned by this structure) or NULL if not found

Definition at line 396 of file blast_dynarray.c.

References arr, NULL, and s_DynamicSGenCodeNodeArray_BinSearch().

Referenced by DynamicSGenCodeNodeArray_Append(), and GenCodeSingletonFind().

◆ DynamicSGenCodeNodeArrayFree()

SDynamicSGenCodeNodeArray* DynamicSGenCodeNodeArrayFree ( SDynamicSGenCodeNodeArray arr)

Deallocates a dynamic array structure.

Parameters
arrdata structure to free [in]
Returns
NULL

Definition at line 235 of file blast_dynarray.c.

References arr, i, NULL, and sfree.

Referenced by DynamicSGenCodeNodeArrayNew(), and GenCodeSingletonFini().

◆ DynamicSGenCodeNodeArrayNew()

SDynamicSGenCodeNodeArray* DynamicSGenCodeNodeArrayNew ( )

Allocate a dynamic array of SGenCodeNode with the initial size of INIT_NUM_ELEMENTS.

Returns
NULL if out of memory otherwise, newly allocated structure

Definition at line 251 of file blast_dynarray.c.

References calloc(), SDynamicSGenCodeNodeArray::data, DynamicSGenCodeNodeArrayFree(), INIT_NUM_GEN_CODES, NULL, and SDynamicSGenCodeNodeArray::num_allocated.

Referenced by GenCodeSingletonInit().

◆ DynamicUint4Array_Append()

Int2 DynamicUint4Array_Append ( SDynamicUint4Array arr,
Uint4  element 
)

Append a Uint4 to the dynamic array structure.

Parameters
arrdata structure to manipulate [in]
elementelement to add [in]
Returns
0 on success or BLASTERR_MEMORY if memory reallocation was needed and this failed

Definition at line 99 of file blast_dynarray.c.

References arr, ASSERT, and s_DynamicUint4Array_ReallocIfNecessary().

Referenced by _PSIGetAlignedSequencesForPosition(), SplitQueryBlk_AddContextOffsetToChunk(), and SplitQueryBlk_AddQueryToChunk().

◆ DynamicUint4Array_AreEqual()

Boolean DynamicUint4Array_AreEqual ( const SDynamicUint4Array a,
const SDynamicUint4Array b 
)

Compares dynamic arrays a and b for equality of its contents.

Parameters
adynamic array to compare [in]
bdynamic array to compare [in]
Returns
TRUE if equal, FALSE otherwise

Definition at line 152 of file blast_dynarray.c.

References a, b, FALSE, i, and TRUE.

Referenced by _PSIComputeSequenceWeights().

◆ DynamicUint4Array_Copy()

Int4 DynamicUint4Array_Copy ( SDynamicUint4Array dest,
const SDynamicUint4Array src 
)

Make a shallow copy of the src dynamic array into the dest dynamic array.

Parameters
destdata structure to copy to. Its contents will be overwritten and memory might be allocated if necessary [in|out]
srcdata structure to copy from [in]
Returns
newly allocated data structure or NULL if out of memory

Definition at line 128 of file blast_dynarray.c.

References BLASTERR_MEMORY, SDynamicUint4Array::data, i, SDynamicUint4Array::num_allocated, and SDynamicUint4Array::num_used.

Referenced by _PSIComputeSequenceWeights().

◆ DynamicUint4Array_Dup()

SDynamicUint4Array* DynamicUint4Array_Dup ( const SDynamicUint4Array src)

Make a deep copy of the src dynamic array.

Parameters
srcdata structure to duplicate [in]
Returns
newly allocated data structure or NULL if out of memory

Definition at line 113 of file blast_dynarray.c.

References SDynamicUint4Array::data, DynamicUint4ArrayNewEx(), NULL, SDynamicUint4Array::num_allocated, and SDynamicUint4Array::num_used.

Referenced by _PSIComputeSequenceWeights().

◆ DynamicUint4ArrayFree()

SDynamicUint4Array* DynamicUint4ArrayFree ( SDynamicUint4Array arr)

Deallocates a dynamic array structure.

Parameters
arrdata structure to free [in]
Returns
NULL

Definition at line 42 of file blast_dynarray.c.

References arr, NULL, and sfree.

Referenced by _PSIComputeSequenceWeights(), DynamicUint4ArrayNewEx(), and SplitQueryBlkFree().

◆ DynamicUint4ArrayNew()

SDynamicUint4Array* DynamicUint4ArrayNew ( )

Allocate a dynamic array of Uint4 with the initial size of INIT_NUM_ELEMENTS.

Returns
NULL if out of memory otherwise, newly allocated structure

Definition at line 54 of file blast_dynarray.c.

References DynamicUint4ArrayNewEx(), and INIT_NUM_ELEMENTS.

Referenced by SplitQueryBlkNew().

◆ DynamicUint4ArrayNewEx()

SDynamicUint4Array* DynamicUint4ArrayNewEx ( Uint4  init_num_elements)

Allocate a dynamic array of Uint4 with an initial size of specified as an argument to the function.

Parameters
init_num_elementsNumber of elements initially allocated [in]
Returns
NULL if out of memory otherwise, newly allocated structure

Definition at line 59 of file blast_dynarray.c.

References calloc(), SDynamicUint4Array::data, DynamicUint4ArrayFree(), NULL, and SDynamicUint4Array::num_allocated.

Referenced by _PSIComputeSequenceWeights(), DynamicUint4Array_Dup(), and DynamicUint4ArrayNew().

◆ s_DynamicInt4Array_ReallocIfNecessary()

static Int2 s_DynamicInt4Array_ReallocIfNecessary ( SDynamicInt4Array arr)
static

Grow a dynamic array of Int4 elements.

Parameters
arrStructure of array data [in][out]
Returns
zero on success

Definition at line 203 of file blast_dynarray.c.

References arr, ASSERT, BLASTERR_MEMORY, and kResizeFactor.

Referenced by DynamicInt4Array_Append().

◆ s_DynamicSGenCodeNodeArray_BinSearch()

static Int4 s_DynamicSGenCodeNodeArray_BinSearch ( const SDynamicSGenCodeNodeArray arr,
Uint4  gen_code_id 
)
static

Perform a binary search for the element containing gen_code_id.

Parameters
arrdynamic array to search [in]
gen_code_idgenetic code to find [in]
Returns
index where the genetic code was found

Definition at line 376 of file blast_dynarray.c.

References arr, b, ncbi::grid::netcache::search::fields::size, and while().

Referenced by DynamicSGenCodeNodeArray_Find().

◆ s_DynamicSGenCodeNodeArray_IsSorted()

static Boolean s_DynamicSGenCodeNodeArray_IsSorted ( const SDynamicSGenCodeNodeArray arr)
static

Determine if the array is sorted.

Parameters
arrarray to examine [in]

Definition at line 295 of file blast_dynarray.c.

References arr, FALSE, and TRUE.

Referenced by s_DynamicSGenCodeNodeArray_Sort().

◆ s_DynamicSGenCodeNodeArray_ReallocIfNecessary()

static Int2 s_DynamicSGenCodeNodeArray_ReallocIfNecessary ( SDynamicSGenCodeNodeArray arr)
static

Grow a dynamic array of SGenCodeNode elements.

Parameters
arrStructure of array data [in][out]
Returns
zero on success

Definition at line 274 of file blast_dynarray.c.

References arr, ASSERT, BLASTERR_MEMORY, and kResizeFactor.

Referenced by DynamicSGenCodeNodeArray_Append().

◆ s_DynamicSGenCodeNodeArray_Sort()

static void s_DynamicSGenCodeNodeArray_Sort ( SDynamicSGenCodeNodeArray arr)
static

Sort the dynamic array structure.

Note
this function should be called prior to invoking DynamicSGenCodeNodeArray_Find
Parameters
arrdata structure to manipulate [in]

Definition at line 329 of file blast_dynarray.c.

References arr, s_DynamicSGenCodeNodeArray_IsSorted(), and s_SGenCodeNodeCompare().

Referenced by DynamicSGenCodeNodeArray_Append().

◆ s_DynamicUint4Array_ReallocIfNecessary()

static Int2 s_DynamicUint4Array_ReallocIfNecessary ( SDynamicUint4Array arr)
static

Grow a dynamic array of Uint4 elements.

Parameters
arrStructure of array data [in][out]
Returns
zero on success

Definition at line 80 of file blast_dynarray.c.

References arr, ASSERT, BLASTERR_MEMORY, and kResizeFactor.

Referenced by DynamicUint4Array_Append().

◆ s_SGenCodeNodeCompare()

static int s_SGenCodeNodeCompare ( const void *  a,
const void *  b 
)
static

Compare function for sorting SGenCodeNode elements.

Parameters
afirst element to compare [in]
bsecond element to compare [in]

Definition at line 316 of file blast_dynarray.c.

References a, b, BLAST_CMP, and SGenCodeNode::gc_id.

Referenced by s_DynamicSGenCodeNodeArray_Sort().

Variable Documentation

◆ kResizeFactor

const size_t kResizeFactor = 2
Modified on Sun May 19 04:43:21 2024 by modify_doxy.py rev. 669887