2 * Copyright (C) the libgit2 contributors. All rights reserved.
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_idxmap_h__
8 #define INCLUDE_idxmap_h__
12 #include "git2/index.h"
14 /** A map with `git_index_entry`s as key. */
15 typedef struct kh_idx_s git_idxmap
;
16 /** A map with case-insensitive `git_index_entry`s as key */
17 typedef struct kh_idxicase_s git_idxmap_icase
;
20 * Allocate a new index entry map.
22 * @param out Pointer to the map that shall be allocated.
23 * @return 0 on success, an error code if allocation has failed.
25 int git_idxmap_new(git_idxmap
**out
);
28 * Allocate a new case-insensitive index entry map.
30 * @param out Pointer to the map that shall be allocated.
31 * @return 0 on success, an error code if allocation has failed.
33 int git_idxmap_icase_new(git_idxmap_icase
**out
);
36 * Free memory associated with the map.
38 * Note that this function will _not_ free values added to this
41 * @param map Pointer to the map that is to be free'd. May be
44 void git_idxmap_free(git_idxmap
*map
);
47 * Free memory associated with the map.
49 * Note that this function will _not_ free values added to this
52 * @param map Pointer to the map that is to be free'd. May be
55 void git_idxmap_icase_free(git_idxmap_icase
*map
);
58 * Clear all entries from the map.
60 * This function will remove all entries from the associated map.
61 * Memory associated with it will not be released, though.
63 * @param map Pointer to the map that shall be cleared. May be
66 void git_idxmap_clear(git_idxmap
*map
);
69 * Clear all entries from the map.
71 * This function will remove all entries from the associated map.
72 * Memory associated with it will not be released, though.
74 * @param map Pointer to the map that shall be cleared. May be
77 void git_idxmap_icase_clear(git_idxmap_icase
*map
);
80 * Resize the map by allocating more memory.
82 * @param map map that shall be resized
83 * @param size count of entries that the map shall hold
84 * @return `0` if the map was successfully resized, a negative
85 * error code otherwise
87 int git_idxmap_resize(git_idxmap
*map
, size_t size
);
90 * Resize the map by allocating more memory.
92 * @param map map that shall be resized
93 * @param size count of entries that the map shall hold
94 * @return `0` if the map was successfully resized, a negative
95 * error code otherwise
97 int git_idxmap_icase_resize(git_idxmap_icase
*map
, size_t size
);
100 * Return value associated with the given key.
102 * @param map map to search key in
103 * @param key key to search for; the index entry will be searched
104 * for by its case-sensitive path
105 * @return value associated with the given key or NULL if the key was not found
107 void *git_idxmap_get(git_idxmap
*map
, const git_index_entry
*key
);
110 * Return value associated with the given key.
112 * @param map map to search key in
113 * @param key key to search for; the index entry will be searched
114 * for by its case-insensitive path
115 * @return value associated with the given key or NULL if the key was not found
117 void *git_idxmap_icase_get(git_idxmap_icase
*map
, const git_index_entry
*key
);
120 * Set the entry for key to value.
122 * If the map has no corresponding entry for the given key, a new
123 * entry will be created with the given value. If an entry exists
124 * already, its value will be updated to match the given value.
126 * @param map map to create new entry in
127 * @param key key to set
128 * @param value value to associate the key with; may be NULL
129 * @return zero if the key was successfully set, a negative error
132 int git_idxmap_set(git_idxmap
*map
, const git_index_entry
*key
, void *value
);
135 * Set the entry for key to value.
137 * If the map has no corresponding entry for the given key, a new
138 * entry will be created with the given value. If an entry exists
139 * already, its value will be updated to match the given value.
141 * @param map map to create new entry in
142 * @param key key to set
143 * @param value value to associate the key with; may be NULL
144 * @return zero if the key was successfully set, a negative error
147 int git_idxmap_icase_set(git_idxmap_icase
*map
, const git_index_entry
*key
, void *value
);
150 * Delete an entry from the map.
152 * Delete the given key and its value from the map. If no such
153 * key exists, this will do nothing.
155 * @param map map to delete key in
156 * @param key key to delete
157 * @return `0` if the key has been deleted, GIT_ENOTFOUND if no
158 * such key was found, a negative code in case of an
161 int git_idxmap_delete(git_idxmap
*map
, const git_index_entry
*key
);
164 * Delete an entry from the map.
166 * Delete the given key and its value from the map. If no such
167 * key exists, this will do nothing.
169 * @param map map to delete key in
170 * @param key key to delete
171 * @return `0` if the key has been deleted, GIT_ENOTFOUND if no
172 * such key was found, a negative code in case of an
175 int git_idxmap_icase_delete(git_idxmap_icase
*map
, const git_index_entry
*key
);