Statistics
| Branch: | Revision:

grapes / include / chunkidset.h @ f3480090

History | View | Annotate | Download (3.22 KB)

1
/** @file chunkidset.h
2
 *
3
 * Chunk ID Set
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
typedef struct chunkID_set ChunkIDSet;
15

    
16
 /**
17
  * Allocate a chunk ID set.
18
  * 
19
  * Create an empty chunk ID set, and return a pointer to it.
20
  * 
21
  * @parameter size the expected number of chunk IDs that will be stored
22
  *                 in the set; 0 if such a number is not known.
23
  * @return the pointer to the new set on success, NULL on error
24
  */
25
struct chunkID_set *chunkID_set_init(int size);
26

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

    
41
 /**
42
  * Get the set size
43
  * 
44
  * Return the number of chunk IDs present in a set.
45
  *
46
  * @parameter h a pointer to the set
47
  * @return the number of chunk IDs in the set, or < 0 on error
48
  */
49
int chunkID_set_size(const struct chunkID_set *h);
50

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

    
64
 /**
65
  * Check if a chunk ID is in a set
66
  * 
67
  * @parameter h a pointer to the set
68
  * @parameter chunk_id the chunk ID we are searching for
69
  * @return the priority of the chunk ID if it is present in the set,
70
  *         < 0 on error or if the chunk ID is not in the set
71
  */
72
int chunkID_set_check(const struct chunkID_set *h, int chunk_id);
73

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

    
88
 /**
89
  * Clear a set
90
  * 
91
  * Remove all the chunk IDs from a set.
92
  *
93
  * @parameter h a pointer to the set
94
  * @parameter size the expected number of chunk IDs that will be stored
95
  *                 in the set; 0 if such a number is not known.
96
  */
97
void chunkID_set_clear(struct chunkID_set *h, int size);
98

    
99
#endif        /* CHUNKIDSET_H */