Statistics
| Branch: | Revision:

grapes / include / chunkidset.h @ b9e0d721

History | View | Annotate | Download (3.76 KB)

1
/** @file chunkidset.h
2
 *
3
 * @brief Structure containing a set of chunk IDs.
4
 *
5
 * The Chunk ID Set is an abstract data structure that can contain a set of
6
 * (chunk ID, priority) couples. Few simple operations for adding chunk IDs
7
 * in a set, for getting the chunk IDs present in a set, for allocating a
8
 * set, and for clearing a set are provided.
9
 */
10
 
11
#ifndef CHUNKIDSET_H
12
#define CHUNKIDSET_H
13

    
14
#define CIST_BITMAP 1
15
#define CIST_PRIORITY 2
16

    
17
typedef struct chunkID_set ChunkIDSet;
18

    
19
 /**
20
  * Allocate a chunk ID set.
21
  * 
22
  * Create an empty chunk ID set, and return a pointer to it.
23
  * 
24
  * @parameter config a configuration string containing tags which describe
25
  *                   the chunk ID set. For example, the "size" tag indicates
26
  *                   the expected number of chunk IDs that will be stored
27
  *                   in the set; 0 or not present if such a number is not
28
  *                   known.
29
  * @return the pointer to the new set on success, NULL on error
30
  */
31
struct chunkID_set *chunkID_set_init(const char *config);
32

    
33
 /**
34
  * Add a chunk ID to the set.
35
  * 
36
  * Insert a chunk ID, and its associated priority (the priority is assumed
37
  * to depend on the insertion order), to the set. If the chunk
38
  * ID is already in the set, nothing happens.
39
  *
40
  * @parameter h a pointer to the set where the chunk ID has to be added
41
  * @parameter chunk_id the ID of the chunk to be inserted in the set
42
  * @return > 0 if the chunk ID is correctly inserted in the set, 0 if chunk_id
43
  *         is already in the set, < 0 on error
44
  */
45
int chunkID_set_add_chunk(struct chunkID_set *h, int chunk_id);
46

    
47
 /**
48
  * Get the set size
49
  * 
50
  * Return the number of chunk IDs present in a set.
51
  *
52
  * @parameter h a pointer to the set
53
  * @return the number of chunk IDs in the set, or < 0 on error
54
  */
55
int chunkID_set_size(const struct chunkID_set *h);
56

    
57
 /**
58
  * Get a chunk ID from a set
59
  * 
60
  * Return the i^th chunk ID from the set. The chunk's priority is
61
  * assumed to depend on i.
62
  *
63
  * @parameter h a pointer to the set
64
  * @parameter i the index of the chunk ID to be returned
65
  * @return the i^th chunk ID in the set in case of success, or < 0 on error
66
  *         (in case of error, priority is not meaningful)
67
  */
68
int chunkID_set_get_chunk(const struct chunkID_set *h, int i);
69

    
70
 /**
71
  * Check if a chunk ID is in a set
72
  * 
73
  * @parameter h a pointer to the set
74
  * @parameter chunk_id the chunk ID we are searching for
75
  * @return the priority of the chunk ID if it is present in the set,
76
  *         < 0 on error or if the chunk ID is not in the set
77
  */
78
int chunkID_set_check(const struct chunkID_set *h, int chunk_id);
79

    
80
 /**
81
  * Add chunks from a chunk ID set to another one
82
  * 
83
  * Insert all chunk from a chunk ID set into another one. Priority is
84
  * kept in the old one. New chunks from the added one are added with
85
  * lower priorities, but keeping their order.
86
  *
87
  * @parameter h a pointer to the set where the chunk ID has to be added
88
  * @parameter a a pointer to the set which has to be added
89
  * @return > 0 if the chunk ID is correctly inserted in the set, 0 if chunk_id
90
  *         is already in the set, < 0 on error
91
  */
92
int chunkID_set_union(struct chunkID_set *h, struct chunkID_set *a);
93

    
94
 /**
95
  * Clear a set
96
  * 
97
  * Remove all the chunk IDs from a set.
98
  *
99
  * @parameter h a pointer to the set
100
  * @parameter size the expected number of chunk IDs that will be stored
101
  *                 in the set; 0 if such a number is not known.
102
  */
103
void chunkID_set_clear(struct chunkID_set *h, int size);
104

    
105
 /**
106
  * Clear a set and free all associated memory.
107
  *
108
  * @parameter h a pointer to the set
109
  */
110
void chunkID_set_free(struct chunkID_set *h);
111

    
112
int chunkID_set_get_earliest(const struct chunkID_set *h);
113

    
114
int chunkID_set_get_latest(const struct chunkID_set *h);
115

    
116
#endif        /* CHUNKIDSET_H */