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
a13cfd2a
Commit
a13cfd2a
authored
Jan 27, 2017
by
Patrick Steinhardt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
strmap: convert macros to functions
parent
f14f75d4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
112 additions
and
27 deletions
+112
-27
src/strmap.c
+95
-0
src/strmap.h
+17
-27
No files found.
src/strmap.c
View file @
a13cfd2a
...
...
@@ -7,6 +7,101 @@
#include "strmap.h"
GIT__USE_STRMAP
int
git_strmap_alloc
(
git_strmap
**
map
)
{
if
((
*
map
=
kh_init
(
str
))
==
NULL
)
{
giterr_set_oom
();
return
-
1
;
}
return
0
;
}
void
git_strmap__free
(
git_strmap
*
map
)
{
kh_destroy
(
str
,
map
);
}
void
git_strmap_clear
(
git_strmap
*
map
)
{
kh_clear
(
str
,
map
);
}
size_t
git_strmap_num_entries
(
git_strmap
*
map
)
{
return
kh_size
(
map
);
}
size_t
git_strmap_lookup_index
(
git_strmap
*
map
,
const
char
*
key
)
{
return
kh_get
(
str
,
map
,
key
);
}
int
git_strmap_valid_index
(
git_strmap
*
map
,
size_t
idx
)
{
return
idx
!=
kh_end
(
map
);
}
int
git_strmap_exists
(
git_strmap
*
map
,
const
char
*
key
)
{
return
kh_get
(
str
,
map
,
key
)
!=
kh_end
(
map
);
}
int
git_strmap_has_data
(
git_strmap
*
map
,
size_t
idx
)
{
return
kh_exist
(
map
,
idx
);
}
const
char
*
git_strmap_key
(
git_strmap
*
map
,
size_t
idx
)
{
return
kh_key
(
map
,
idx
);
}
void
git_strmap_set_key_at
(
git_strmap
*
map
,
size_t
idx
,
char
*
key
)
{
kh_val
(
map
,
idx
)
=
key
;
}
void
*
git_strmap_value_at
(
git_strmap
*
map
,
size_t
idx
)
{
return
kh_val
(
map
,
idx
);
}
void
git_strmap_set_value_at
(
git_strmap
*
map
,
size_t
idx
,
void
*
value
)
{
kh_val
(
map
,
idx
)
=
value
;
}
void
git_strmap_delete_at
(
git_strmap
*
map
,
size_t
idx
)
{
kh_del
(
str
,
map
,
idx
);
}
int
git_strmap_put
(
git_strmap
*
map
,
const
char
*
key
,
int
*
err
)
{
return
kh_put
(
str
,
map
,
key
,
err
);
}
void
git_strmap_insert
(
git_strmap
*
map
,
const
char
*
key
,
void
*
value
,
int
*
rval
)
{
khiter_t
idx
=
kh_put
(
str
,
map
,
key
,
rval
);
if
((
*
rval
)
>=
0
)
{
if
((
*
rval
)
==
0
)
kh_key
(
map
,
idx
)
=
key
;
kh_val
(
map
,
idx
)
=
value
;
}
}
void
git_strmap_delete
(
git_strmap
*
map
,
const
char
*
key
)
{
khiter_t
idx
=
git_strmap_lookup_index
(
map
,
key
);
if
(
git_strmap_valid_index
(
map
,
idx
))
git_strmap_delete_at
(
map
,
idx
);
}
int
git_strmap_next
(
void
**
data
,
git_strmap_iter
*
iter
,
...
...
src/strmap.h
View file @
a13cfd2a
...
...
@@ -23,39 +23,29 @@ typedef khiter_t git_strmap_iter;
#define GIT__USE_STRMAP \
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal)
#define git_strmap_alloc(hp) \
((*(hp) = kh_init(str)) == NULL) ? giterr_set_oom(), -1 : 0
int
git_strmap_alloc
(
git_strmap
**
map
);
#define git_strmap_free(h) kh_destroy(str, h), h = NULL
#define git_strmap_clear(h) kh_clear(str, h)
#define git_strmap_free(h) git_strmap__free(h); (h) = NULL
void
git_strmap__free
(
git_strmap
*
map
);
void
git_strmap_clear
(
git_strmap
*
map
);
#define git_strmap_num_entries(h) kh_size(h)
size_t
git_strmap_num_entries
(
git_strmap
*
map
);
#define git_strmap_lookup_index(h, k) kh_get(str, h, k)
#define git_strmap_valid_index(h, idx) (idx != kh_end(h))
size_t
git_strmap_lookup_index
(
git_strmap
*
map
,
const
char
*
key
);
int
git_strmap_valid_index
(
git_strmap
*
map
,
size_t
idx
);
#define git_strmap_exists(h, k) (kh_get(str, h, k) != kh_end(h))
#define git_strmap_has_data(h, idx) kh_exist(h, idx)
int
git_strmap_exists
(
git_strmap
*
map
,
const
char
*
key
);
int
git_strmap_has_data
(
git_strmap
*
map
,
size_t
idx
);
#define git_strmap_key(h, idx) kh_key(h, idx)
#define git_strmap_set_key_at(h, idx, k) kh_val(h, idx) = k
#define git_strmap_value_at(h, idx) kh_val(h, idx)
#define git_strmap_set_value_at(h, idx, v) kh_val(h, idx) = v
#define git_strmap_delete_at(h, idx) kh_del(str, h, idx)
const
char
*
git_strmap_key
(
git_strmap
*
map
,
size_t
idx
);
void
git_strmap_set_key_at
(
git_strmap
*
map
,
size_t
idx
,
char
*
key
);
void
*
git_strmap_value_at
(
git_strmap
*
map
,
size_t
idx
);
void
git_strmap_set_value_at
(
git_strmap
*
map
,
size_t
idx
,
void
*
value
);
void
git_strmap_delete_at
(
git_strmap
*
map
,
size_t
idx
);
#define git_strmap_put(h, k, err) kh_put(str, h, k, err)
#define git_strmap_insert(h, key, val, rval) do { \
khiter_t __pos = kh_put(str, h, key, rval); \
if ((*rval) >= 0) { \
if ((*rval) == 0) kh_key(h, __pos) = key; \
kh_val(h, __pos) = val; \
} } while (0)
#define git_strmap_delete(h, key) do { \
khiter_t __pos = git_strmap_lookup_index(h, key); \
if (git_strmap_valid_index(h, __pos)) \
git_strmap_delete_at(h, __pos); } while (0)
int
git_strmap_put
(
git_strmap
*
map
,
const
char
*
key
,
int
*
err
);
void
git_strmap_insert
(
git_strmap
*
map
,
const
char
*
key
,
void
*
value
,
int
*
rval
);
void
git_strmap_delete
(
git_strmap
*
map
,
const
char
*
key
);
#define git_strmap_foreach kh_foreach
#define git_strmap_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