1 #ifndef __CMPH_COMPRESSED_SEQ_H__
2 #define __CMPH_COMPRESSED_SEQ_H__
3
4 #include"select.h"
5
6 struct _compressed_seq_t
7 {
8 cmph_uint32 n; // number of values stored in store_table
9 // The length in bits of each value is decomposed into two compnents: the lg(n) MSBs are stored in rank_select data structure
10 // the remaining LSBs are stored in a table of n cells, each one of rem_r bits.
11 cmph_uint32 rem_r;
12 cmph_uint32 total_length; // total length in bits of stored_table
13 select_t sel;
14 cmph_uint32 * length_rems;
15 cmph_uint32 * store_table;
16 };
17
18 typedef struct _compressed_seq_t compressed_seq_t;
19
20 /** \fn void compressed_seq_init(compressed_seq_t * cs);
21 * \brief Initialize a compressed sequence structure.
22 * \param cs points to the compressed sequence structure to be initialized
23 */
24 void compressed_seq_init(compressed_seq_t * cs);
25
26 /** \fn void compressed_seq_destroy(compressed_seq_t * cs);
27 * \brief Destroy a compressed sequence given as input.
28 * \param cs points to the compressed sequence structure to be destroyed
29 */
30 void compressed_seq_destroy(compressed_seq_t * cs);
31
32 /** \fn void compressed_seq_generate(compressed_seq_t * cs, cmph_uint32 * vals_table, cmph_uint32 n);
33 * \brief Generate a compressed sequence from an input array with n values.
34 * \param cs points to the compressed sequence structure
35 * \param vals_table poiter to the array given as input
36 * \param n number of values in @see vals_table
37 */
38 void compressed_seq_generate(compressed_seq_t * cs, cmph_uint32 * vals_table, cmph_uint32 n);
39
40
41 /** \fn cmph_uint32 compressed_seq_query(compressed_seq_t * cs, cmph_uint32 idx);
42 * \brief Returns the value stored at index @see idx of the compressed sequence structure.
43 * \param cs points to the compressed sequence structure
44 * \param idx index to retrieve the value from
45 * \return the value stored at index @see idx of the compressed sequence structure
46 */
47 cmph_uint32 compressed_seq_query(compressed_seq_t * cs, cmph_uint32 idx);
48
49
50 /** \fn cmph_uint32 compressed_seq_get_space_usage(compressed_seq_t * cs);
51 * \brief Returns amount of space (in bits) to store the compressed sequence.
52 * \param cs points to the compressed sequence structure
53 * \return the amount of space (in bits) to store @see cs
54 */
55 cmph_uint32 compressed_seq_get_space_usage(compressed_seq_t * cs);
56
57 void compressed_seq_dump(compressed_seq_t * cs, char ** buf, cmph_uint32 * buflen);
58
59 void compressed_seq_load(compressed_seq_t * cs, const char * buf, cmph_uint32 buflen);
60
61
62 /** \fn void compressed_seq_pack(compressed_seq_t *cs, void *cs_packed);
63 * \brief Support the ability to pack a compressed sequence structure into a preallocated contiguous memory space pointed by cs_packed.
64 * \param cs points to the compressed sequence structure
65 * \param cs_packed pointer to the contiguous memory area used to store the compressed sequence structure. The size of cs_packed must be at least @see compressed_seq_packed_size
66 */
67 void compressed_seq_pack(compressed_seq_t *cs, void *cs_packed);
68
69 /** \fn cmph_uint32 compressed_seq_packed_size(compressed_seq_t *cs);
70 * \brief Return the amount of space needed to pack a compressed sequence structure.
71 * \return the size of the packed compressed sequence structure or zero for failures
72 */
73 cmph_uint32 compressed_seq_packed_size(compressed_seq_t *cs);
74
75
76 /** \fn cmph_uint32 compressed_seq_query_packed(void * cs_packed, cmph_uint32 idx);
77 * \brief Returns the value stored at index @see idx of the packed compressed sequence structure.
78 * \param cs_packed is a pointer to a contiguous memory area
79 * \param idx is the index to retrieve the value from
80 * \return the value stored at index @see idx of the packed compressed sequence structure
81 */
82 cmph_uint32 compressed_seq_query_packed(void * cs_packed, cmph_uint32 idx);
83
84 #endif