Line | Count | Source (jump to first uncovered line) |
1 | | #ifndef OIDMAP_H |
2 | | #define OIDMAP_H |
3 | | |
4 | | #include "hash.h" |
5 | | #include "hashmap.h" |
6 | | |
7 | | /* |
8 | | * struct oidmap_entry is a structure representing an entry in the hash table, |
9 | | * which must be used as first member of user data structures. |
10 | | * |
11 | | * Users should set the oid field. oidmap_put() will populate the |
12 | | * internal_entry field. |
13 | | */ |
14 | | struct oidmap_entry { |
15 | | /* For internal use only */ |
16 | | struct hashmap_entry internal_entry; |
17 | | |
18 | | struct object_id oid; |
19 | | }; |
20 | | |
21 | | struct oidmap { |
22 | | struct hashmap map; |
23 | | }; |
24 | | |
25 | 0 | #define OIDMAP_INIT { { NULL } } |
26 | | |
27 | | /* |
28 | | * Initializes an oidmap structure. |
29 | | * |
30 | | * `map` is the oidmap to initialize. |
31 | | * |
32 | | * If the total number of entries is known in advance, the `initial_size` |
33 | | * parameter may be used to preallocate a sufficiently large table and thus |
34 | | * prevent expensive resizing. If 0, the table is dynamically resized. |
35 | | */ |
36 | | void oidmap_init(struct oidmap *map, size_t initial_size); |
37 | | |
38 | | /* |
39 | | * Frees an oidmap structure and allocated memory. |
40 | | * |
41 | | * If `free_entries` is true, each oidmap_entry in the map is freed as well |
42 | | * using stdlibs free(). |
43 | | */ |
44 | | void oidmap_free(struct oidmap *map, int free_entries); |
45 | | |
46 | | /* |
47 | | * Returns the oidmap entry for the specified oid, or NULL if not found. |
48 | | */ |
49 | | void *oidmap_get(const struct oidmap *map, |
50 | | const struct object_id *key); |
51 | | |
52 | | /* |
53 | | * Adds or replaces an oidmap entry. |
54 | | * |
55 | | * ((struct oidmap_entry *) entry)->internal_entry will be populated by this |
56 | | * function. |
57 | | * |
58 | | * Returns the replaced entry, or NULL if not found (i.e. the entry was added). |
59 | | */ |
60 | | void *oidmap_put(struct oidmap *map, void *entry); |
61 | | |
62 | | /* |
63 | | * Removes an oidmap entry matching the specified oid. |
64 | | * |
65 | | * Returns the removed entry, or NULL if not found. |
66 | | */ |
67 | | void *oidmap_remove(struct oidmap *map, const struct object_id *key); |
68 | | |
69 | | |
70 | | struct oidmap_iter { |
71 | | struct hashmap_iter h_iter; |
72 | | }; |
73 | | |
74 | | static inline void oidmap_iter_init(struct oidmap *map, struct oidmap_iter *iter) |
75 | 0 | { |
76 | 0 | hashmap_iter_init(&map->map, &iter->h_iter); |
77 | 0 | } Unexecuted instantiation: cat-file.c:oidmap_iter_init Unexecuted instantiation: commit-graph.c:oidmap_iter_init Unexecuted instantiation: fsck.c:oidmap_iter_init Unexecuted instantiation: index-pack.c:oidmap_iter_init Unexecuted instantiation: mktag.c:oidmap_iter_init Unexecuted instantiation: multi-pack-index.c:oidmap_iter_init Unexecuted instantiation: pack-objects.c:oidmap_iter_init Unexecuted instantiation: prune.c:oidmap_iter_init Unexecuted instantiation: replace.c:oidmap_iter_init Unexecuted instantiation: unpack-objects.c:oidmap_iter_init Unexecuted instantiation: upload-pack.c:oidmap_iter_init Unexecuted instantiation: git.c:oidmap_iter_init Unexecuted instantiation: cache-tree.c:oidmap_iter_init Unexecuted instantiation: environment.c:oidmap_iter_init Unexecuted instantiation: log-tree.c:oidmap_iter_init Unexecuted instantiation: object-file.c:oidmap_iter_init Unexecuted instantiation: object.c:oidmap_iter_init Unexecuted instantiation: oidmap.c:oidmap_iter_init Unexecuted instantiation: replace-object.c:oidmap_iter_init Unexecuted instantiation: sequencer.c:oidmap_iter_init Unexecuted instantiation: streaming.c:oidmap_iter_init Unexecuted instantiation: list-objects-filter.c:oidmap_iter_init |
78 | | |
79 | | static inline void *oidmap_iter_next(struct oidmap_iter *iter) |
80 | 0 | { |
81 | 0 | /* TODO: this API could be reworked to do compile-time type checks */ |
82 | 0 | return (void *)hashmap_iter_next(&iter->h_iter); |
83 | 0 | } Unexecuted instantiation: cat-file.c:oidmap_iter_next Unexecuted instantiation: commit-graph.c:oidmap_iter_next Unexecuted instantiation: fsck.c:oidmap_iter_next Unexecuted instantiation: index-pack.c:oidmap_iter_next Unexecuted instantiation: mktag.c:oidmap_iter_next Unexecuted instantiation: multi-pack-index.c:oidmap_iter_next Unexecuted instantiation: pack-objects.c:oidmap_iter_next Unexecuted instantiation: prune.c:oidmap_iter_next Unexecuted instantiation: replace.c:oidmap_iter_next Unexecuted instantiation: unpack-objects.c:oidmap_iter_next Unexecuted instantiation: upload-pack.c:oidmap_iter_next Unexecuted instantiation: git.c:oidmap_iter_next Unexecuted instantiation: cache-tree.c:oidmap_iter_next Unexecuted instantiation: environment.c:oidmap_iter_next Unexecuted instantiation: log-tree.c:oidmap_iter_next Unexecuted instantiation: object-file.c:oidmap_iter_next Unexecuted instantiation: object.c:oidmap_iter_next Unexecuted instantiation: oidmap.c:oidmap_iter_next Unexecuted instantiation: replace-object.c:oidmap_iter_next Unexecuted instantiation: sequencer.c:oidmap_iter_next Unexecuted instantiation: streaming.c:oidmap_iter_next Unexecuted instantiation: list-objects-filter.c:oidmap_iter_next |
84 | | |
85 | | static inline void *oidmap_iter_first(struct oidmap *map, |
86 | | struct oidmap_iter *iter) |
87 | 0 | { |
88 | 0 | oidmap_iter_init(map, iter); |
89 | 0 | /* TODO: this API could be reworked to do compile-time type checks */ |
90 | 0 | return (void *)oidmap_iter_next(iter); |
91 | 0 | } Unexecuted instantiation: cat-file.c:oidmap_iter_first Unexecuted instantiation: commit-graph.c:oidmap_iter_first Unexecuted instantiation: fsck.c:oidmap_iter_first Unexecuted instantiation: index-pack.c:oidmap_iter_first Unexecuted instantiation: mktag.c:oidmap_iter_first Unexecuted instantiation: multi-pack-index.c:oidmap_iter_first Unexecuted instantiation: pack-objects.c:oidmap_iter_first Unexecuted instantiation: prune.c:oidmap_iter_first Unexecuted instantiation: replace.c:oidmap_iter_first Unexecuted instantiation: unpack-objects.c:oidmap_iter_first Unexecuted instantiation: upload-pack.c:oidmap_iter_first Unexecuted instantiation: git.c:oidmap_iter_first Unexecuted instantiation: cache-tree.c:oidmap_iter_first Unexecuted instantiation: environment.c:oidmap_iter_first Unexecuted instantiation: log-tree.c:oidmap_iter_first Unexecuted instantiation: object-file.c:oidmap_iter_first Unexecuted instantiation: object.c:oidmap_iter_first Unexecuted instantiation: oidmap.c:oidmap_iter_first Unexecuted instantiation: replace-object.c:oidmap_iter_first Unexecuted instantiation: sequencer.c:oidmap_iter_first Unexecuted instantiation: streaming.c:oidmap_iter_first Unexecuted instantiation: list-objects-filter.c:oidmap_iter_first |
92 | | |
93 | | #endif |