obiblob_indexer.h 5.43 KB
Newer Older
Celine Mercier committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/****************************************************************************
 * Blob indexer header file	                                                    *
 ****************************************************************************/

/**
 * @file obiblob_indexer.h
 * @author Celine Mercier
 * @date April 12th 2016
 * @brief Header file for the functions handling the indexing of values.
 */


#ifndef OBIBLOB_INDEXER_H_
#define OBIBLOB_INDEXER_H_


#include <stdlib.h>
#include <stdio.h>

#include "obidms.h"
#include "obiavl.h"
#include "obitypes.h"
#include "obiblob.h"


#define INDEXER_MAX_NAME AVL_MAX_NAME 			/**< Macro to refer to the maximum size of the name of an indexer structure.
 	 	 	 	 	 	 	 	 	 	 	 	 */


30 31 32
typedef struct OBIDMS_avl_group Obi_indexer;	/**< Typedef to refer to the used indexer structure.
 	 	 	 	 	 	 	 	 	 	 	 	 */
typedef OBIDMS_avl_group_p Obi_indexer_p; 		/**< Typedef to refer to the pointer of the used indexer structure.
Celine Mercier committed
33 34 35
 	 	 	 	 	 	 	 	 	 	 	 	 */


36 37 38 39 40 41 42 43 44 45 46 47 48 49
/**
 * @brief Checks if an indexer already exists or not.
 *
 * @param dms The OBIDMS to which the indexer belongs.
 * @param name The name of the indexer.
 *
 * @returns A value indicating whether the indexer exists or not.
 * @retval 1 if the indexer exists.
 * @retval 0 if the indexer does not exist.
 * @retval -1 if an error occurred.
 *
 * @since April 2016
 * @author Celine Mercier (celine.mercier@metabarcoding.org)
 */
50
static inline int obi_indexer_exists(OBIDMS_p dms, const char* name)
Celine Mercier committed
51 52 53 54 55
{
	return obi_avl_exists(dms, name);
}


56 57 58 59 60 61 62 63 64 65 66 67
/**
 * @brief Opens an indexer and creates it if it does not already exist.
 *
 * @param dms The OBIDMS to which the indexer belongs.
 * @param name The name of the indexer.
 *
 * @returns A pointer to the indexer structure.
 * @retval NULL if an error occurred.
 *
 * @since April 2016
 * @author Celine Mercier (celine.mercier@metabarcoding.org)
 */
68
static inline Obi_indexer_p obi_indexer(OBIDMS_p dms, const char* name)
Celine Mercier committed
69 70 71 72 73
{
	return obi_avl_group(dms, name);
}


74 75 76 77 78 79 80 81 82 83 84 85
/**
 * @brief Creates an indexer.
 *
 * @param dms The OBIDMS to which the indexer belongs.
 * @param name The name of the indexer.
 *
 * @returns A pointer to the AVL tree group structure.
 * @retval NULL if an error occurred.
 *
 * @since April 2016
 * @author Celine Mercier (celine.mercier@metabarcoding.org)
 */
86
static inline Obi_indexer_p obi_create_indexer(OBIDMS_p dms, const char* name)
Celine Mercier committed
87 88 89 90 91
{
	return obi_create_avl_group(dms, name);
}


92 93 94 95 96 97 98 99 100 101 102 103
/**
 * @brief Opens an indexer.
 *
 * @param dms The OBIDMS to which the indexer belongs.
 * @param name The name of the indexer.
 *
 * @returns A pointer to the indexer structure.
 * @retval NULL if an error occurred.
 *
 * @since April 2016
 * @author Celine Mercier (celine.mercier@metabarcoding.org)
 */
104
static inline Obi_indexer_p obi_open_indexer(OBIDMS_p dms, const char* name)
Celine Mercier committed
105 106 107 108 109
{
	return obi_open_avl_group(dms, name);
}


110 111 112 113 114 115 116 117 118 119 120 121
/**
 * @brief Clones an indexer.
 *
 * @param indexer The indexer to clone.
 * @param name The name of the new indexer.
 *
 * @returns A pointer on the new indexer structure.
 * @retval NULL if an error occurred.
 *
 * @since May 2016
 * @author Celine Mercier (celine.mercier@metabarcoding.org)
 */
122
static inline Obi_indexer_p obi_clone_indexer(Obi_indexer_p indexer, const char* name)
123 124 125 126 127
{
	return obi_clone_avl_group(indexer, name);
}


128 129 130 131 132 133 134 135 136 137 138
/**
 * @brief Closes an indexer.
 *
 * @param indexer A pointer to the indexer structure to close and free.
 *
 * @retval 0 if the operation was successfully completed.
 * @retval -1 if an error occurred.
 *
 * @since April 2016
 * @author Celine Mercier (celine.mercier@metabarcoding.org)
 */
139
static inline int obi_close_indexer(Obi_indexer_p indexer)
Celine Mercier committed
140 141 142 143 144
{
	return obi_close_avl_group(indexer);
}


145 146 147 148 149 150 151 152 153 154 155 156
/**
 * @brief Indexes a blob in an indexer and returns the index referring to the blob.
 *
 * @param indexer A pointer to the indexer.
 * @param value The blob to index.
 *
 * @returns The index of the blob newly added in the indexer.
 * @retval -1 if an error occurred.
 *
 * @since April 2016
 * @author Celine Mercier (celine.mercier@metabarcoding.org)
 */
157
static inline index_t obi_indexer_add(Obi_indexer_p indexer, Obi_blob_p value)
Celine Mercier committed
158 159 160 161 162
{
	return obi_avl_group_add(indexer, value);
}


163 164 165 166 167 168 169 170 171 172 173
/**
 * @brief Recovers a blob from an indexer.
 *
 * @param indexer A pointer to the indexer.
 * @param index The index of the blob in the indexer.
 *
 * @returns A pointer to the blob recovered.
 *
 * @since April 2016
 * @author Celine Mercier (celine.mercier@metabarcoding.org)
 */
174
static inline Obi_blob_p obi_indexer_get(Obi_indexer_p indexer, index_t idx)
Celine Mercier committed
175 176 177 178 179
{
	return obi_avl_group_get(indexer, idx);
}


180 181 182 183 184 185 186 187 188 189
/**
 * @brief Recovers the name of an indexer.
 *
 * @param indexer A pointer on the indexer.
 *
 * @returns A pointer on the name of the indexer.
 *
 * @since April 2016
 * @author Celine Mercier (celine.mercier@metabarcoding.org)
 */
190
static inline const char* obi_indexer_get_name(Obi_indexer_p indexer)
191 192 193 194 195
{
	return obi_avl_group_get_name(indexer);
}


196 197 198
/**
 * @brief Builds an indexer name in the form columnname_columnversion_indexer.
 *
199 200
 * @warning The returned pointer has to be freed by the caller.
 *
201 202 203 204 205 206 207 208 209
 * @param column_name The name of the column associated with the indexer.
 * @param column_version The version of the column associated with the indexer.
 *
 * @returns A pointer on the indexer name built.
 * @retval NULL if an error occurred.
 *
 * @since April 2016
 * @author Celine Mercier (celine.mercier@metabarcoding.org)
 */
210
char* obi_build_indexer_name(const char* column_name, obiversion_t column_version);
211 212


Celine Mercier committed
213 214
#endif /* OBIBLOB_INDEXER_H_ */