forked from EddyRivasLab/easel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds esl_arr2, esl_arr3, deprecating esl_Free2D(), esl_Free3D().
Adds esl_free(), which allows ptr to be NULL. This is actually unnecessary. C99 free() accepts NULL as a no-op. Adds esl_msa_Sizeof(), which I intend to use to pull some alirecsize capability into esl-alistat. Also, utest_Sizeof() unit test for it. [SRE:H4/146]
- Loading branch information
1 parent
2dffa62
commit f8e929c
Showing
19 changed files
with
434 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#include "esl_config.h" | ||
|
||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include "easel.h" | ||
|
||
|
||
|
||
/* Function: esl_arr2_SSizeof() | ||
* Synopsis: Returns size of a 2D array of \0-terminated strings, in bytes | ||
* Incept: SRE, Fri Nov 3 15:15:56 2017 | ||
*/ | ||
size_t | ||
esl_arr2_SSizeof(char **s, int dim1) | ||
{ | ||
size_t n = 0; | ||
int i; | ||
|
||
if (s) | ||
{ | ||
n += sizeof(char *) * dim1; | ||
for (i = 0; i < dim1; i++) | ||
if (s[i]) | ||
n += sizeof(char) * (1 + strlen(s[i])); | ||
} | ||
return n; | ||
} | ||
|
||
/* Function: esl_arr2_Destroy() | ||
* Synopsis: Free a 2D array. | ||
* Incept: SRE, Fri Nov 3 15:32:21 2017 | ||
* | ||
* Purpose: Free a 2D pointer array <p>, where first dimension is | ||
* <dim1>. (That is, the array is <p[0..dim1-1][]>.) | ||
* Tolerates any of the pointers being NULL, to allow | ||
* sparse arrays. | ||
* | ||
* Returns: (void) | ||
* | ||
* Throws: (no abnormal error conditions) | ||
* | ||
* Xref: Was <esl_Free2D()>. | ||
*/ | ||
void | ||
esl_arr2_Destroy(void **p, int dim1) | ||
{ | ||
int i; | ||
|
||
if (p) | ||
{ | ||
for (i = 0; i < dim1; i++) | ||
if (p[i]) | ||
free(p[i]); | ||
free(p); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#ifndef eslARR2_INCLUDED | ||
#define eslARR2_INCLUDED | ||
|
||
#include <stdlib.h> | ||
|
||
extern size_t esl_arr2_SSizeof(char **s, int dim1); | ||
extern void esl_arr2_Destroy(void **p, int dim1); | ||
|
||
#endif // eslARR2_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include "esl_config.h" | ||
|
||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include "easel.h" | ||
|
||
/* Function: esl_arr3_SSizeof() | ||
* Synopsis: Returns size of 3D array of \0-terminated strings, in bytes | ||
* Incept: SRE, Fri Nov 3 15:19:53 2017 | ||
*/ | ||
size_t | ||
esl_arr3_SSizeof(char ***s, int dim1, int dim2) | ||
{ | ||
size_t n = 0; | ||
int i,j; | ||
|
||
if (s) | ||
{ | ||
n += sizeof(char **) * dim1; | ||
for (i = 0; i < dim1; i++) | ||
if (s[i]) | ||
{ | ||
n += sizeof(char *) * dim2; | ||
for (j = 0; j < dim2; j++) | ||
{ | ||
if (s[i][j]) | ||
n += sizeof(char) * (1 + strlen(s[i][j])); | ||
} | ||
} | ||
} | ||
return n; | ||
} | ||
|
||
|
||
|
||
/* Function: esl_arr3_Destroy() | ||
* Synopsis: Free a 3D array. | ||
* Incept: SRE, Fri Nov 3 15:38:39 2017 | ||
* | ||
* Purpose: Free a 3D pointer array <p>, where first and second | ||
* dimensions are <dim1>,<dim2>. (That is, the array is | ||
* <p[0..dim1-1][0..dim2-1][]>.) Tolerates any of the | ||
* pointers being NULL, to allow sparse arrays. | ||
* | ||
* Returns: (void) | ||
* | ||
* Throws: (no abnormal error conditions) | ||
* | ||
* Xref: Was <esl_Free3D()>. | ||
*/ | ||
void | ||
esl_arr3_Destroy(void ***p, int dim1, int dim2) | ||
{ | ||
int i, j; | ||
|
||
if (p) | ||
{ | ||
for (i = 0; i < dim1; i++) | ||
if (p[i]) | ||
{ | ||
for (j = 0; j < dim2; j++) | ||
if (p[i][j]) | ||
free(p[i][j]); | ||
free(p[i]); | ||
} | ||
free(p); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#ifndef eslARR3_INCLUDED | ||
#define eslARR3_INCLUDED | ||
|
||
#include <stdlib.h> | ||
|
||
extern size_t esl_arr3_SSizeof(char ***s, int dim1, int dim2); | ||
extern void esl_arr3_Destroy(void ***p, int dim1, int dim2); | ||
|
||
#endif // eslARR3_INCLUDED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.