|
Packit Service |
20376f |
/*
|
|
Packit Service |
20376f |
* Copyright (C) the libgit2 contributors. All rights reserved.
|
|
Packit Service |
20376f |
*
|
|
Packit Service |
20376f |
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
|
Packit Service |
20376f |
* a Linking Exception. For full terms see the included COPYING file.
|
|
Packit Service |
20376f |
*/
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
#include "oidmap.h"
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
GIT_INLINE(khint_t) git_oidmap_hash(const git_oid *oid)
|
|
Packit Service |
20376f |
{
|
|
Packit Service |
20376f |
khint_t h;
|
|
Packit Service |
20376f |
memcpy(&h, oid, sizeof(khint_t));
|
|
Packit Service |
20376f |
return h;
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
__KHASH_IMPL(oid, static kh_inline, const git_oid *, void *, 1, git_oidmap_hash, git_oid_equal)
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
git_oidmap *git_oidmap_alloc()
|
|
Packit Service |
20376f |
{
|
|
Packit Service |
20376f |
return kh_init(oid);
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
void git_oidmap_free(git_oidmap *map)
|
|
Packit Service |
20376f |
{
|
|
Packit Service |
20376f |
kh_destroy(oid, map);
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
void git_oidmap_clear(git_oidmap *map)
|
|
Packit Service |
20376f |
{
|
|
Packit Service |
20376f |
kh_clear(oid, map);
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
size_t git_oidmap_size(git_oidmap *map)
|
|
Packit Service |
20376f |
{
|
|
Packit Service |
20376f |
return kh_size(map);
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
size_t git_oidmap_lookup_index(git_oidmap *map, const git_oid *key)
|
|
Packit Service |
20376f |
{
|
|
Packit Service |
20376f |
return kh_get(oid, map, key);
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
int git_oidmap_valid_index(git_oidmap *map, size_t idx)
|
|
Packit Service |
20376f |
{
|
|
Packit Service |
20376f |
return idx != kh_end(map);
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
int git_oidmap_exists(git_oidmap *map, const git_oid *key)
|
|
Packit Service |
20376f |
{
|
|
Packit Service |
20376f |
return kh_get(oid, map, key) != kh_end(map);
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
int git_oidmap_has_data(git_oidmap *map, size_t idx)
|
|
Packit Service |
20376f |
{
|
|
Packit Service |
20376f |
return kh_exist(map, idx);
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
const git_oid *git_oidmap_key(git_oidmap *map, size_t idx)
|
|
Packit Service |
20376f |
{
|
|
Packit Service |
20376f |
return kh_key(map, idx);
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
void git_oidmap_set_key_at(git_oidmap *map, size_t idx, git_oid *key)
|
|
Packit Service |
20376f |
{
|
|
Packit Service |
20376f |
kh_key(map, idx) = key;
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
void *git_oidmap_value_at(git_oidmap *map, size_t idx)
|
|
Packit Service |
20376f |
{
|
|
Packit Service |
20376f |
return kh_val(map, idx);
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
void git_oidmap_set_value_at(git_oidmap *map, size_t idx, void *value)
|
|
Packit Service |
20376f |
{
|
|
Packit Service |
20376f |
kh_val(map, idx) = value;
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
void git_oidmap_delete_at(git_oidmap *map, size_t idx)
|
|
Packit Service |
20376f |
{
|
|
Packit Service |
20376f |
kh_del(oid, map, idx);
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
int git_oidmap_put(git_oidmap *map, const git_oid *key, int *err)
|
|
Packit Service |
20376f |
{
|
|
Packit Service |
20376f |
return kh_put(oid, map, key, err);
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
void git_oidmap_insert(git_oidmap *map, const git_oid *key, void *value, int *rval)
|
|
Packit Service |
20376f |
{
|
|
Packit Service |
20376f |
khiter_t idx = kh_put(oid, map, key, rval);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
if ((*rval) >= 0) {
|
|
Packit Service |
20376f |
if ((*rval) == 0)
|
|
Packit Service |
20376f |
kh_key(map, idx) = key;
|
|
Packit Service |
20376f |
kh_val(map, idx) = value;
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
void git_oidmap_delete(git_oidmap *map, const git_oid *key)
|
|
Packit Service |
20376f |
{
|
|
Packit Service |
20376f |
khiter_t idx = git_oidmap_lookup_index(map, key);
|
|
Packit Service |
20376f |
if (git_oidmap_valid_index(map, idx))
|
|
Packit Service |
20376f |
git_oidmap_delete_at(map, idx);
|
|
Packit Service |
20376f |
}
|