diff options
| author | Patrick Steinhardt <ps@pks.im> | 2018-12-17 09:10:53 +0100 |
|---|---|---|
| committer | Patrick Steinhardt <ps@pks.im> | 2019-02-15 13:16:48 +0100 |
| commit | b9d0b664071fed96e690a70ee4472facf554eb70 (patch) | |
| tree | 2507c85e58c49d378a028c7b571d98fe3809f4f3 /src/offmap.h | |
| parent | aa2456239b4644c43d3cc9e002ed718e5078e7cc (diff) | |
| download | libgit2-b9d0b664071fed96e690a70ee4472facf554eb70.tar.gz | |
offmap: introduce high-level setter for key/value pairs
Currently, there is only one caller that adds entries into an offset map, and
this caller first uses `git_offmap_put` to add a key and then set the value at
the returned index by using `git_offmap_set_value_at`. This is just too tighlty
coupled with implementation details of the map as it exposes the index of
inserted entries, which we really do not care about at all.
Introduce a new function `git_offmap_set`, which takes as parameters the map,
key and value and directly returns an error code. Convert the caller to make use
of it instead.
Diffstat (limited to 'src/offmap.h')
| -rw-r--r-- | src/offmap.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/offmap.h b/src/offmap.h index 5491ba76b..bf2ef7fbb 100644 --- a/src/offmap.h +++ b/src/offmap.h @@ -61,6 +61,21 @@ size_t git_offmap_size(git_offmap *map); */ void *git_offmap_get(git_offmap *map, const git_off_t key); +/** + * Set the entry for key to value. + * + * If the map has no corresponding entry for the given key, a new + * entry will be created with the given value. If an entry exists + * already, its value will be updated to match the given value. + * + * @param map map to create new entry in + * @param key key to set + * @param value value to associate the key with; may be NULL + * @return zero if the key was successfully set, a negative error + * code otherwise + */ +int git_offmap_set(git_offmap *map, const git_off_t key, void *value); + size_t git_offmap_lookup_index(git_offmap *map, const git_off_t key); int git_offmap_valid_index(git_offmap *map, size_t idx); |
