mirror of
https://git.proxmox.com/git/libgit2
synced 2026-01-18 02:24:57 +00:00
This updates khash.h with some extra features (like error checking on allocations, ability to use wrapped malloc, foreach calls, etc), creates two high-level wrappers around khash: `git_khash_str` and `git_khash_oid` for string-to-void-ptr and oid-to-void-ptr tables, then converts all of the old usage of `git_hashtable` over to use these new hashtables. For `git_khash_str`, I've tried to create a set of macros that yield an API not too unlike the old `git_hashtable` API. Since the oid hashtable is only used in one file, I haven't bother to set up all those macros and just use the khash APIs directly for now.
43 lines
1.0 KiB
C
43 lines
1.0 KiB
C
/*
|
|
* Copyright (C) 2012 the libgit2 contributors
|
|
*
|
|
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
|
* a Linking Exception. For full terms see the included COPYING file.
|
|
*/
|
|
#ifndef INCLUDE_khash_oid_h__
|
|
#define INCLUDE_khash_oid_h__
|
|
|
|
#include "common.h"
|
|
#include "git2/oid.h"
|
|
|
|
#define kmalloc git__malloc
|
|
#define kcalloc git__calloc
|
|
#define krealloc git__realloc
|
|
#define kfree git__free
|
|
#include "khash.h"
|
|
|
|
__KHASH_TYPE(oid, const git_oid *, void *);
|
|
typedef khash_t(oid) git_khash_oid;
|
|
|
|
GIT_INLINE(khint_t) hash_git_oid(const git_oid *oid)
|
|
{
|
|
int i;
|
|
khint_t h = 0;
|
|
for (i = 0; i < 20; ++i)
|
|
h = (h << 5) - h + oid->id[i];
|
|
return h;
|
|
}
|
|
|
|
GIT_INLINE(int) hash_git_oid_equal(const git_oid *a, const git_oid *b)
|
|
{
|
|
return (memcmp(a->id, b->id, sizeof(a->id)) == 0);
|
|
}
|
|
|
|
#define GIT_KHASH_OID__IMPLEMENTATION \
|
|
__KHASH_IMPL(oid, static inline, const git_oid *, void *, 1, hash_git_oid, hash_git_oid_equal)
|
|
|
|
#define git_khash_oid_alloc() kh_init(oid)
|
|
#define git_khash_oid_free(h) kh_destroy(oid,h), h = NULL
|
|
|
|
#endif
|