]>
git.proxmox.com Git - libgit2.git/blob - src/offmap.h
2 * Copyright (C) 2012 the libgit2 contributors
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
7 #ifndef INCLUDE_offmap_h__
8 #define INCLUDE_offmap_h__
12 #include "git2/types.h"
14 /** A map with `off64_t`s as key. */
15 typedef struct kh_off_s git_offmap
;
18 * Allocate a new `off64_t` map.
20 * @param out Pointer to the map that shall be allocated.
21 * @return 0 on success, an error code if allocation has failed.
23 int git_offmap_new(git_offmap
**out
);
26 * Free memory associated with the map.
28 * Note that this function will _not_ free values added to this
31 * @param map Pointer to the map that is to be free'd. May be
34 void git_offmap_free(git_offmap
*map
);
37 * Clear all entries from the map.
39 * This function will remove all entries from the associated map.
40 * Memory associated with it will not be released, though.
42 * @param map Pointer to the map that shall be cleared. May be
45 void git_offmap_clear(git_offmap
*map
);
48 * Return the number of elements in the map.
50 * @parameter map map containing the elements
51 * @return number of elements in the map
53 size_t git_offmap_size(git_offmap
*map
);
56 * Return value associated with the given key.
58 * @param map map to search key in
59 * @param key key to search for
60 * @return value associated with the given key or NULL if the key was not found
62 void *git_offmap_get(git_offmap
*map
, const off64_t key
);
65 * Set the entry for key to value.
67 * If the map has no corresponding entry for the given key, a new
68 * entry will be created with the given value. If an entry exists
69 * already, its value will be updated to match the given value.
71 * @param map map to create new entry in
72 * @param key key to set
73 * @param value value to associate the key with; may be NULL
74 * @return zero if the key was successfully set, a negative error
77 int git_offmap_set(git_offmap
*map
, const off64_t key
, void *value
);
80 * Delete an entry from the map.
82 * Delete the given key and its value from the map. If no such
83 * key exists, this will do nothing.
85 * @param map map to delete key in
86 * @param key key to delete
87 * @return `0` if the key has been deleted, GIT_ENOTFOUND if no
88 * such key was found, a negative code in case of an
91 int git_offmap_delete(git_offmap
*map
, const off64_t key
);
94 * Check whether a key exists in the given map.
96 * @param map map to query for the key
97 * @param key key to search for
98 * @return 0 if the key has not been found, 1 otherwise
100 int git_offmap_exists(git_offmap
*map
, const off64_t key
);
103 * Iterate over entries of the map.
105 * This functions allows to iterate over all key-value entries of
106 * the map. The current position is stored in the `iter` variable
107 * and should be initialized to `0` before the first call to this
110 * @param map map to iterate over
111 * @param value pointer to the variable where to store the current
112 * value. May be NULL.
113 * @param iter iterator storing the current position. Initialize
114 * with zero previous to the first call.
115 * @param key pointer to the variable where to store the current
117 * @return `0` if the next entry was correctly retrieved.
118 * GIT_ITEROVER if no entries are left. A negative error
121 int git_offmap_iterate(void **value
, git_offmap
*map
, size_t *iter
, off64_t
*key
);
123 #define git_offmap_foreach(h, kvar, vvar, code) { size_t __i = 0; \
124 while (git_offmap_iterate((void **) &(vvar), h, &__i, &(kvar)) == 0) { \
128 #define git_offmap_foreach_value(h, vvar, code) { size_t __i = 0; \
129 while (git_offmap_iterate((void **) &(vvar), h, &__i, NULL) == 0) { \