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
2e60b652
Commit
2e60b652
authored
Feb 27, 2011
by
Vicent Marti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add extra methods to the new Hashtable implementation
Signed-off-by: Vicent Marti <tanoku@gmail.com>
parent
ccef1c9d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
2 deletions
+26
-2
src/hashtable.c
+13
-1
src/hashtable.h
+13
-1
No files found.
src/hashtable.c
View file @
2e60b652
...
...
@@ -179,11 +179,13 @@ void git_hashtable_free(git_hashtable *self)
}
int
git_hashtable_insert
(
git_hashtable
*
self
,
const
void
*
key
,
void
*
value
)
int
git_hashtable_insert
2
(
git_hashtable
*
self
,
const
void
*
key
,
void
*
value
,
void
**
old_
value
)
{
int
hash_id
;
git_hashtable_node
*
node
;
*
old_value
=
NULL
;
for
(
hash_id
=
0
;
hash_id
<
GIT_HASHTABLE_HASHES
;
++
hash_id
)
{
node
=
node_with_hash
(
self
,
key
,
hash_id
);
...
...
@@ -195,6 +197,8 @@ int git_hashtable_insert(git_hashtable *self, const void *key, void *value)
}
if
(
key
==
node
->
key
||
self
->
key_equal
(
key
,
node
->
key
)
==
0
)
{
*
old_value
=
node
->
value
;
node
->
key
=
key
;
node
->
value
=
value
;
return
GIT_SUCCESS
;
}
...
...
@@ -241,3 +245,11 @@ int git_hashtable_remove(git_hashtable *self, const void *key)
return
GIT_ENOTFOUND
;
}
int
git_hashtable_merge
(
git_hashtable
*
self
,
git_hashtable
*
other
)
{
if
(
resize_to
(
self
,
(
self
->
size
+
other
->
size
)
*
2
)
<
GIT_SUCCESS
)
return
GIT_ENOMEM
;
return
insert_nodes
(
self
,
other
->
nodes
,
other
->
key_count
);
}
src/hashtable.h
View file @
2e60b652
...
...
@@ -34,11 +34,19 @@ typedef struct git_hashtable git_hashtable;
git_hashtable
*
git_hashtable_alloc
(
size_t
min_size
,
git_hash_ptr
hash
,
git_hash_keyeq_ptr
key_eq
);
int
git_hashtable_insert
(
git_hashtable
*
h
,
const
void
*
key
,
void
*
value
);
void
*
git_hashtable_lookup
(
git_hashtable
*
h
,
const
void
*
key
);
int
git_hashtable_remove
(
git_hashtable
*
table
,
const
void
*
key
);
void
git_hashtable_free
(
git_hashtable
*
h
);
void
git_hashtable_clear
(
git_hashtable
*
h
);
int
git_hashtable_merge
(
git_hashtable
*
self
,
git_hashtable
*
other
);
int
git_hashtable_insert2
(
git_hashtable
*
h
,
const
void
*
key
,
void
*
value
,
void
**
old_value
);
GIT_INLINE
(
int
)
git_hashtable_insert
(
git_hashtable
*
h
,
const
void
*
key
,
void
*
value
)
{
void
*
_unused
;
return
git_hashtable_insert2
(
h
,
key
,
value
,
&
_unused
);
}
#define git_hashtable_node_at(nodes, pos) ((git_hashtable_node *)(&nodes[pos]))
...
...
@@ -57,5 +65,9 @@ void git_hashtable_clear(git_hashtable *h);
}\
}
#define GIT_HASHTABLE_FOREACH_DELETE() {\
_node->key = NULL; _node->value = NULL; _self->key_count--;\
}
#endif
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