vendor/libgit2/src/oidmap.h in rugged-0.28.4 vs vendor/libgit2/src/oidmap.h in rugged-0.28.4.1

- old
+ new

@@ -9,120 +9,40 @@ #include "common.h" #include "git2/oid.h" -/** A map with `git_oid`s as key. */ typedef struct kh_oid_s git_oidmap; -/** - * Allocate a new OID map. - * - * @param out Pointer to the map that shall be allocated. - * @return 0 on success, an error code if allocation has failed. - */ -int git_oidmap_new(git_oidmap **out); - -/** - * Free memory associated with the map. - * - * Note that this function will _not_ free values added to this - * map. - * - * @param map Pointer to the map that is to be free'd. May be - * `NULL`. - */ +git_oidmap *git_oidmap_alloc(void); void git_oidmap_free(git_oidmap *map); - -/** - * Clear all entries from the map. - * - * This function will remove all entries from the associated map. - * Memory associated with it will not be released, though. - * - * @param map Pointer to the map that shall be cleared. May be - * `NULL`. - */ void git_oidmap_clear(git_oidmap *map); -/** - * Return the number of elements in the map. - * - * @parameter map map containing the elements - * @return number of elements in the map - */ size_t git_oidmap_size(git_oidmap *map); -/** - * Return value associated with the given key. - * - * @param map map to search key in - * @param key key to search for - * @return value associated with the given key or NULL if the key was not found - */ -void *git_oidmap_get(git_oidmap *map, const git_oid *key); +size_t git_oidmap_lookup_index(git_oidmap *map, const git_oid *key); +int git_oidmap_valid_index(git_oidmap *map, size_t idx); -/** - * 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_oidmap_set(git_oidmap *map, const git_oid *key, void *value); +int git_oidmap_exists(git_oidmap *map, const git_oid *key); +int git_oidmap_has_data(git_oidmap *map, size_t idx); -/** - * Delete an entry from the map. - * - * Delete the given key and its value from the map. If no such - * key exists, this will do nothing. - * - * @param map map to delete key in - * @param key key to delete - * @return `0` if the key has been deleted, GIT_ENOTFOUND if no - * such key was found, a negative code in case of an - * error - */ -int git_oidmap_delete(git_oidmap *map, const git_oid *key); +const git_oid *git_oidmap_key(git_oidmap *map, size_t idx); +void git_oidmap_set_key_at(git_oidmap *map, size_t idx, git_oid *key); +void *git_oidmap_value_at(git_oidmap *map, size_t idx); +void git_oidmap_set_value_at(git_oidmap *map, size_t idx, void *value); +void git_oidmap_delete_at(git_oidmap *map, size_t idx); -/** - * Check whether a key exists in the given map. - * - * @param map map to query for the key - * @param key key to search for - * @return 0 if the key has not been found, 1 otherwise - */ -int git_oidmap_exists(git_oidmap *map, const git_oid *key); +int git_oidmap_put(git_oidmap *map, const git_oid *key, int *err); +void git_oidmap_insert(git_oidmap *map, const git_oid *key, void *value, int *rval); +void git_oidmap_delete(git_oidmap *map, const git_oid *key); -/** - * Iterate over entries of the map. - * - * This functions allows to iterate over all key-value entries of - * the map. The current position is stored in the `iter` variable - * and should be initialized to `0` before the first call to this - * function. - * - * @param map map to iterate over - * @param value pointer to the variable where to store the current - * value. May be NULL. - * @param iter iterator storing the current position. Initialize - * with zero previous to the first call. - * @param key pointer to the variable where to store the current - * key. May be NULL. - * @return `0` if the next entry was correctly retrieved. - * GIT_ITEROVER if no entries are left. A negative error - * code otherwise. - */ -int git_oidmap_iterate(void **value, git_oidmap *map, size_t *iter, const git_oid **key); +size_t git_oidmap_begin(git_oidmap *map); +size_t git_oidmap_end(git_oidmap *map); -#define git_oidmap_foreach_value(h, vvar, code) { size_t __i = 0; \ - while (git_oidmap_iterate((void **) &(vvar), h, &__i, NULL) == 0) { \ +#define git_oidmap_foreach_value(h, vvar, code) { size_t __i; \ + for (__i = git_oidmap_begin(h); __i != git_oidmap_end(h); ++__i) { \ + if (!git_oidmap_has_data(h,__i)) continue; \ + (vvar) = git_oidmap_value_at(h,__i); \ code; \ } } #endif