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
cf6124d6
Commit
cf6124d6
authored
Feb 02, 2017
by
Patrick Steinhardt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
offmap: convert to use functions instead of macros
parent
0d716905
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
97 additions
and
23 deletions
+97
-23
src/offmap.c
+83
-0
src/offmap.h
+14
-23
No files found.
src/offmap.c
0 → 100644
View file @
cf6124d6
/*
* 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 "offmap.h"
GIT__USE_OFFMAP
git_offmap
*
git_offmap_alloc
(
void
)
{
return
kh_init
(
off
);
}
void
git_offmap__free
(
git_offmap
*
map
)
{
kh_destroy
(
off
,
map
);
}
void
git_offmap_clear
(
git_offmap
*
map
)
{
kh_clear
(
off
,
map
);
}
size_t
git_offmap_num_entries
(
git_offmap
*
map
)
{
return
kh_size
(
map
);
}
size_t
git_offmap_lookup_index
(
git_offmap
*
map
,
const
git_off_t
key
)
{
return
kh_get
(
off
,
map
,
key
);
}
int
git_offmap_valid_index
(
git_offmap
*
map
,
size_t
idx
)
{
return
idx
!=
kh_end
(
map
);
}
int
git_offmap_exists
(
git_offmap
*
map
,
const
git_off_t
key
)
{
return
kh_get
(
off
,
map
,
key
)
!=
kh_end
(
map
);
}
void
*
git_offmap_value_at
(
git_offmap
*
map
,
size_t
idx
)
{
return
kh_val
(
map
,
idx
);
}
void
git_offmap_set_value_at
(
git_offmap
*
map
,
size_t
idx
,
void
*
value
)
{
kh_val
(
map
,
idx
)
=
value
;
}
void
git_offmap_delete_at
(
git_offmap
*
map
,
size_t
idx
)
{
kh_del
(
off
,
map
,
idx
);
}
int
git_offmap_put
(
git_offmap
*
map
,
const
git_off_t
key
,
int
*
err
)
{
return
kh_put
(
off
,
map
,
key
,
err
);
}
void
git_offmap_insert
(
git_offmap
*
map
,
const
git_off_t
key
,
void
*
value
,
int
*
rval
)
{
khiter_t
idx
=
kh_put
(
off
,
map
,
key
,
rval
);
if
((
*
rval
)
>=
0
)
{
if
((
*
rval
)
==
0
)
kh_key
(
map
,
idx
)
=
key
;
kh_val
(
map
,
idx
)
=
value
;
}
}
void
git_offmap_delete
(
git_offmap
*
map
,
const
git_off_t
key
)
{
khiter_t
idx
=
git_offmap_lookup_index
(
map
,
key
);
if
(
git_offmap_valid_index
(
map
,
idx
))
git_offmap_delete_at
(
map
,
idx
);
}
src/offmap.h
View file @
cf6124d6
...
...
@@ -23,34 +23,25 @@ typedef khash_t(off) git_offmap;
#define GIT__USE_OFFMAP \
__KHASH_IMPL(off, static kh_inline, git_off_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal)
#define git_offmap_alloc() kh_init(off)
#define git_offmap_free(h) kh_destroy(off, h), h = NULL
#define git_offmap_clear(h) kh_clear(off, h)
git_offmap
*
git_offmap_alloc
(
void
);
#define git_offmap_free(h) git_offmap__free(h); (h) = NULL
void
git_offmap__free
(
git_offmap
*
map
);
void
git_offmap_clear
(
git_offmap
*
map
);
#define git_offmap_num_entries(h) kh_size(h)
size_t
git_offmap_num_entries
(
git_offmap
*
map
);
#define git_offmap_lookup_index(h, k) kh_get(off, h, k)
#define git_offmap_valid_index(h, idx) (idx != kh_end(h))
size_t
git_offmap_lookup_index
(
git_offmap
*
map
,
const
git_off_t
key
);
int
git_offmap_valid_index
(
git_offmap
*
map
,
size_t
idx
);
#define git_offmap_exists(h, k) (kh_get(off, h, k) != kh_end(h))
int
git_offmap_exists
(
git_offmap
*
map
,
const
git_off_t
key
);
#define git_offmap_value_at(h, idx) kh_val(h, idx)
#define git_offmap_set_value_at(h, idx, v) kh_val(h, idx) = v
#define git_offmap_delete_at(h, idx) kh_del(off, h, idx)
void
*
git_offmap_value_at
(
git_offmap
*
map
,
size_t
idx
);
void
git_offmap_set_value_at
(
git_offmap
*
map
,
size_t
idx
,
void
*
value
);
void
git_offmap_delete_at
(
git_offmap
*
map
,
size_t
idx
);
#define git_offmap_put(h, k, err) kh_put(off, h, k, err)
#define git_offmap_insert(h, key, val, rval) do { \
khiter_t __pos = kh_put(off, h, key, rval); \
if ((*rval) >= 0) { \
if ((*rval) == 0) kh_key(h, __pos) = key; \
kh_val(h, __pos) = val; \
} } while (0)
#define git_offmap_delete(h, key) do { \
khiter_t __pos = git_offmap_lookup_index(h, key); \
if (git_offmap_valid_index(h, __pos)) \
git_offmap_delete_at(h, __pos); } while (0)
int
git_offmap_put
(
git_offmap
*
map
,
const
git_off_t
key
,
int
*
err
);
void
git_offmap_insert
(
git_offmap
*
map
,
const
git_off_t
key
,
void
*
value
,
int
*
rval
);
void
git_offmap_delete
(
git_offmap
*
map
,
const
git_off_t
key
);
#define git_offmap_foreach kh_foreach
#define git_offmap_foreach_value kh_foreach_value
...
...
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