Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
cee9ca66
Commit
cee9ca66
authored
Feb 02, 2017
by
Patrick Steinhardt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
idxmap: convert to use functions instead of macros
parent
8f5fe903
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
143 additions
and
43 deletions
+143
-43
src/idxmap.c
+121
-0
src/idxmap.h
+22
-43
No files found.
src/idxmap.c
0 → 100644
View file @
cee9ca66
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#include "idxmap.h"
GIT__USE_IDXMAP
GIT__USE_IDXMAP_ICASE
int
git_idxmap_alloc
(
git_idxmap
**
map
)
{
if
((
*
map
=
kh_init
(
idx
))
==
NULL
)
{
giterr_set_oom
();
return
-
1
;
}
return
0
;
}
int
git_idxmap_icase_alloc
(
git_idxmap_icase
**
map
)
{
if
((
*
map
=
kh_init
(
idxicase
))
==
NULL
)
{
giterr_set_oom
();
return
-
1
;
}
return
0
;
}
void
git_idxmap_insert
(
git_idxmap
*
map
,
const
git_index_entry
*
key
,
void
*
value
,
int
*
rval
)
{
khiter_t
idx
=
kh_put
(
idx
,
map
,
key
,
rval
);
if
((
*
rval
)
>=
0
)
{
if
((
*
rval
)
==
0
)
kh_key
(
map
,
idx
)
=
key
;
kh_val
(
map
,
idx
)
=
value
;
}
}
void
git_idxmap_icase_insert
(
git_idxmap_icase
*
map
,
const
git_index_entry
*
key
,
void
*
value
,
int
*
rval
)
{
khiter_t
idx
=
kh_put
(
idxicase
,
map
,
key
,
rval
);
if
((
*
rval
)
>=
0
)
{
if
((
*
rval
)
==
0
)
kh_key
(
map
,
idx
)
=
key
;
kh_val
(
map
,
idx
)
=
value
;
}
}
size_t
git_idxmap_lookup_index
(
git_idxmap
*
map
,
const
git_index_entry
*
key
)
{
return
kh_get
(
idx
,
map
,
key
);
}
size_t
git_idxmap_icase_lookup_index
(
git_idxmap_icase
*
map
,
const
git_index_entry
*
key
)
{
return
kh_get
(
idxicase
,
map
,
key
);
}
void
*
git_idxmap_value_at
(
git_idxmap
*
map
,
size_t
idx
)
{
return
kh_val
(
map
,
idx
);
}
int
git_idxmap_valid_index
(
git_idxmap
*
map
,
size_t
idx
)
{
return
idx
!=
kh_end
(
map
);
}
int
git_idxmap_has_data
(
git_idxmap
*
map
,
size_t
idx
)
{
return
kh_exist
(
map
,
idx
);
}
void
git_idxmap_resize
(
git_idxmap
*
map
,
size_t
size
)
{
kh_resize
(
idx
,
map
,
size
);
}
void
git_idxmap_icase_resize
(
git_idxmap_icase
*
map
,
size_t
size
)
{
kh_resize
(
idxicase
,
map
,
size
);
}
void
git_idxmap__free
(
git_idxmap
*
map
)
{
kh_destroy
(
idx
,
map
);
}
void
git_idxmap_clear
(
git_idxmap
*
map
)
{
kh_clear
(
idx
,
map
);
}
void
git_idxmap_delete_at
(
git_idxmap
*
map
,
size_t
idx
)
{
kh_del
(
idx
,
map
,
idx
);
}
void
git_idxmap_icase_delete_at
(
git_idxmap_icase
*
map
,
size_t
idx
)
{
kh_del
(
idxicase
,
map
,
idx
);
}
void
git_idxmap_delete
(
git_idxmap
*
map
,
const
git_index_entry
*
key
)
{
khiter_t
idx
=
git_idxmap_lookup_index
(
map
,
key
);
if
(
git_idxmap_valid_index
(
map
,
idx
))
git_idxmap_delete_at
(
map
,
idx
);
}
void
git_idxmap_icase_delete
(
git_idxmap_icase
*
map
,
const
git_index_entry
*
key
)
{
khiter_t
idx
=
git_idxmap_icase_lookup_index
(
map
,
key
);
if
(
git_idxmap_valid_index
((
git_idxmap
*
)
map
,
idx
))
git_idxmap_icase_delete_at
(
map
,
idx
);
}
src/idxmap.h
View file @
cee9ca66
...
...
@@ -44,49 +44,28 @@ static kh_inline khint_t idxentry_hash(const git_index_entry *e)
#define GIT__USE_IDXMAP_ICASE \
__KHASH_IMPL(idxicase, static kh_inline, const git_index_entry *, git_index_entry *, 1, idxentry_hash, idxentry_icase_equal)
#define git_idxmap_alloc(hp) \
((*(hp) = kh_init(idx)) == NULL) ? giterr_set_oom(), -1 : 0
#define git_idxmap_icase_alloc(hp) \
((*(hp) = kh_init(idxicase)) == NULL) ? giterr_set_oom(), -1 : 0
#define git_idxmap_insert(h, key, val, rval) do { \
khiter_t __pos = kh_put(idx, h, key, rval); \
if ((*rval) >= 0) { \
if ((*rval) == 0) kh_key(h, __pos) = key; \
kh_val(h, __pos) = val; \
} } while (0)
#define git_idxmap_icase_insert(h, key, val, rval) do { \
khiter_t __pos = kh_put(idxicase, h, key, rval); \
if ((*rval) >= 0) { \
if ((*rval) == 0) kh_key(h, __pos) = key; \
kh_val(h, __pos) = val; \
} } while (0)
#define git_idxmap_lookup_index(h, k) kh_get(idx, h, k)
#define git_idxmap_icase_lookup_index(h, k) kh_get(idxicase, h, k)
#define git_idxmap_value_at(h, idx) kh_val(h, idx)
#define git_idxmap_valid_index(h, idx) (idx != kh_end(h))
#define git_idxmap_has_data(h, idx) kh_exist(h, idx)
#define git_idxmap_resize(h,s) kh_resize(idx, h, s)
#define git_idxmap_icase_resize(h,s) kh_resize(idxicase, h, s)
#define git_idxmap_free(h) kh_destroy(idx, h), h = NULL
#define git_idxmap_clear(h) kh_clear(idx, h)
#define git_idxmap_delete_at(h, id) kh_del(idx, h, id)
#define git_idxmap_icase_delete_at(h, id) kh_del(idxicase, h, id)
#define git_idxmap_delete(h, key) do { \
khiter_t __pos = git_idxmap_lookup_index(h, key); \
if (git_idxmap_valid_index(h, __pos)) \
git_idxmap_delete_at(h, __pos); } while (0)
#define git_idxmap_icase_delete(h, key) do { \
khiter_t __pos = git_idxmap_icase_lookup_index(h, key); \
if (git_idxmap_valid_index(h, __pos)) \
git_idxmap_icase_delete_at(h, __pos); } while (0)
int
git_idxmap_alloc
(
git_idxmap
**
map
);
int
git_idxmap_icase_alloc
(
git_idxmap_icase
**
map
);
void
git_idxmap_insert
(
git_idxmap
*
map
,
const
git_index_entry
*
key
,
void
*
value
,
int
*
rval
);
void
git_idxmap_icase_insert
(
git_idxmap_icase
*
map
,
const
git_index_entry
*
key
,
void
*
value
,
int
*
rval
);
size_t
git_idxmap_lookup_index
(
git_idxmap
*
map
,
const
git_index_entry
*
key
);
size_t
git_idxmap_icase_lookup_index
(
git_idxmap_icase
*
map
,
const
git_index_entry
*
key
);
void
*
git_idxmap_value_at
(
git_idxmap
*
map
,
size_t
idx
);
int
git_idxmap_valid_index
(
git_idxmap
*
map
,
size_t
idx
);
int
git_idxmap_has_data
(
git_idxmap
*
map
,
size_t
idx
);
void
git_idxmap_resize
(
git_idxmap
*
map
,
size_t
size
);
void
git_idxmap_icase_resize
(
git_idxmap_icase
*
map
,
size_t
size
);
#define git_idxmap_free(h) git_idxmap__free(h); (h) = NULL
void
git_idxmap__free
(
git_idxmap
*
map
);
void
git_idxmap_clear
(
git_idxmap
*
map
);
void
git_idxmap_delete_at
(
git_idxmap
*
map
,
size_t
idx
);
void
git_idxmap_icase_delete_at
(
git_idxmap_icase
*
map
,
size_t
idx
);
void
git_idxmap_delete
(
git_idxmap
*
map
,
const
git_index_entry
*
key
);
void
git_idxmap_icase_delete
(
git_idxmap_icase
*
map
,
const
git_index_entry
*
key
);
#define git_idxmap_begin kh_begin
#define git_idxmap_end kh_end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment