biomcmc-lib  0.1
low level library for phylogenetic analysis
char_vector.h
Go to the documentation of this file.
1 /*
2  *This file is part of biomcmc-lib, a low-level library for phylogenomic analysis.
3  * Copyright (C) 2019-today Leonardo de Oliveira Martins [ leomrtns at gmail.com; http://www.leomartins.org ]
4  *
5  * biomcmc is free software; you can redistribute it and/or modify it under the terms of the GNU General Public
6  * License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later
7  * version.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
10  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11  * details (file "COPYING" or http://www.gnu.org/copyleft/gpl.html).
12  */
13 
18 #ifndef _biomcmc_char_vector_h_
19 #define _biomcmc_char_vector_h_
20 
21 #include "lowlevel.h"
22 #include "prob_distribution.h"
23 
24 typedef struct char_vector_struct* char_vector;
25 
28 {
29  char **string;
30  int nstrings;
31  size_t *alloc;
32  size_t *nchars;
35  int next_avail;
36 };
37 
39 char_vector new_char_vector (int nstrings);
41 char_vector new_char_vector_big (int nstrings);
43 char_vector new_char_vector_from_valid_strings_char_vector (char_vector vec, int *valid, int n_valid);
45 char_vector new_char_vector_fixed_length (int nstrings, int nchars);
46 
48 void del_char_vector (char_vector vec);
49 
51 void char_vector_link_string_at_position (char_vector vec, const char *string, int position);
52 
54 void char_vector_add_string_at_position (char_vector vec, const char *string, int position);
55 
57 void char_vector_add_string (char_vector vec, const char *string);
58 
60 void char_vector_append_string_at_position (char_vector vec, const char *string, int position);
62 void char_vector_append_string (char_vector vec, const char *string);
63 
65 void char_vector_append_string_big_at_position (char_vector vec, const char *string, int position);
66 void char_vector_append_string_big (char_vector vec, const char *string);
67 void char_vector_finalise_big (char_vector vec);
68 
70 void char_vector_expand_nstrings (char_vector vec, int new_size);
71 
73 void char_vector_reorder_strings_from_external_order (char_vector vec, int *order);
74 
76 int char_vector_remove_empty_strings (char_vector vec);
78 int char_vector_remove_duplicate_strings (char_vector vec);
80 void char_vector_reduce_to_valid_strings (char_vector vec, int *valid, int n_valid);
81 
85 void char_vector_reorder_by_size_or_lexicographically (char_vector vec, bool lexico, int *order);
87 bool char_vector_link_address_if_identical (char_vector *v1, char_vector *v2);
93 void index_species_gene_char_vectors (char_vector species, char_vector gene, int *sp_idx_in_gene, int *order_external);
94 void update_species_count_from_gene_char_vector (char_vector species, char_vector gene, int *sp_count);
95 
96 #endif
Probability distribution functions and auxiliary mathematical functions from statistical package R...
char_vector new_char_vector_from_valid_strings_char_vector(char_vector vec, int *valid, int n_valid)
Create a vector of strings from subset of strings of another char_vector.
Definition: char_vector.c:80
void char_vector_add_string_at_position(char_vector vec, const char *string, int position)
Add a new string (vector of characters) at specific location.
Definition: char_vector.c:142
char_vector new_char_vector_big(int nstrings)
Create vector of strings, and preparing it to realloc() fewer times; used in conjunction with 'append...
Definition: char_vector.c:71
void del_char_vector(char_vector vec)
Delete vector of strings only after nobody is using it.
Definition: char_vector.c:114
vector of strings (char vectors) of variable length
Definition: char_vector.h:27
char_vector new_char_vector(int nstrings)
Create a vector of strings with initial size for each string of zero.
Definition: char_vector.c:46
char_vector new_char_vector_fixed_length(int nstrings, int nchars)
Create a vector of strings where each string is assigned an initial value of nchars.
Definition: char_vector.c:89
void char_vector_reorder_strings_from_external_order(char_vector vec, int *order)
update order of strings in vector based on a vector of new positions
Definition: char_vector.c:258
bool char_vector_link_address_if_identical(char_vector *v1, char_vector *v2)
If the two char_vectors are identical (same strings in same order), then delete one and make it point...
Definition: char_vector.c:389
void char_vector_reduce_to_valid_strings(char_vector vec, int *valid, int n_valid)
reduce char_string_struct to only those elements indexed by valid[]
Definition: char_vector.c:350
Lowest level header file. Header file for lowlevel.c.
void char_vector_append_string_big_at_position(char_vector vec, const char *string, int position)
Append strings like before, but doubling allocation space if insufficient (reduces calls to realloc()...
Definition: char_vector.c:193
int next_avail
how many times this char_vector_struct is being used
Definition: char_vector.h:35
void char_vector_reorder_by_size_or_lexicographically(char_vector vec, bool lexico, int *order)
Order char_vector_struct elements from longer string to smaller, or lexicographically; can be used af...
Definition: char_vector.c:365
void char_vector_link_string_at_position(char_vector vec, const char *string, int position)
Link a previously allocated string (to avoid copying all characters)
Definition: char_vector.c:129
void index_species_gene_char_vectors(char_vector species, char_vector gene, int *sp_idx_in_gene, int *order_external)
find occurences of species->string[] inside gene->string[] filling indexes in sp_idx_in_gene.
Definition: char_vector.c:408
size_t * alloc
how many strings
Definition: char_vector.h:31
size_t * nchars
in some cases (e.g. huge fasta files) we need to reduce calls to realloc()
Definition: char_vector.h:32
void char_vector_append_string(char_vector vec, const char *string)
Append string at the end of existing string at most recently used location.
Definition: char_vector.c:186
void char_vector_append_string_at_position(char_vector vec, const char *string, int position)
Append string at the end of existing string at location.
Definition: char_vector.c:166
int nstrings
vector of strings
Definition: char_vector.h:30
int char_vector_remove_duplicate_strings(char_vector vec)
Remove identical strings and resizes char_vector_struct.
Definition: char_vector.c:317
int ref_counter
length of allocated memory for each string excluding the ending '\0' (the actual size in use needs st...
Definition: char_vector.h:34
int char_vector_remove_empty_strings(char_vector vec)
Reduce size of vector of strings by removing empty strings (returns number of empty strings) ...
Definition: char_vector.c:283
void char_vector_expand_nstrings(char_vector vec, int new_size)
Increase size of vector of strings (called automatically by other functions)
Definition: char_vector.c:235
void char_vector_add_string(char_vector vec, const char *string)
Add a new string (vector of characters) at next available location.
Definition: char_vector.c:160