Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
fb92682e
Commit
fb92682e
authored
Jun 06, 2016
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
htable: htable_type add htable_copy.
Signed-off-by:
Rusty Russell
<
rusty@rustcorp.com.au
>
parent
f359fde1
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
5 deletions
+16
-5
ccan/htable/htable_type.h
ccan/htable/htable_type.h
+9
-3
ccan/htable/test/run-type.c
ccan/htable/test/run-type.c
+7
-2
No files found.
ccan/htable/htable_type.h
View file @
fb92682e
...
@@ -21,8 +21,9 @@
...
@@ -21,8 +21,9 @@
*
*
* It also defines initialization and freeing functions:
* It also defines initialization and freeing functions:
* void <name>_init(struct <name> *);
* void <name>_init(struct <name> *);
*
void
<name>_init_sized(struct <name> *, size_t);
*
bool
<name>_init_sized(struct <name> *, size_t);
* void <name>_clear(struct <name> *);
* void <name>_clear(struct <name> *);
* bool <name>_copy(struct <name> *dst, const struct <name> *src);
*
*
* Add function only fails if we run out of memory:
* Add function only fails if we run out of memory:
* bool <name>_add(struct <name> *ht, const <type> *e);
* bool <name>_add(struct <name> *ht, const <type> *e);
...
@@ -63,15 +64,20 @@
...
@@ -63,15 +64,20 @@
{ \
{ \
htable_init(&ht->raw, name##_hash, NULL); \
htable_init(&ht->raw, name##_hash, NULL); \
} \
} \
static inline UNNEEDED
void
name##_init_sized(struct name *ht, \
static inline UNNEEDED
bool
name##_init_sized(struct name *ht, \
size_t s) \
size_t s) \
{ \
{ \
htable_init_sized(&ht->raw, name##_hash, NULL, s);
\
return htable_init_sized(&ht->raw, name##_hash, NULL, s);
\
} \
} \
static inline UNNEEDED void name##_clear(struct name *ht) \
static inline UNNEEDED void name##_clear(struct name *ht) \
{ \
{ \
htable_clear(&ht->raw); \
htable_clear(&ht->raw); \
} \
} \
static inline UNNEEDED bool name##_copy(struct name *dst, \
const struct name *src) \
{ \
return htable_copy(&dst->raw, &src->raw); \
} \
static inline bool name##_add(struct name *ht, const type *elem) \
static inline bool name##_add(struct name *ht, const type *elem) \
{ \
{ \
return htable_add(&ht->raw, hashfn(keyof(elem)), elem); \
return htable_add(&ht->raw, hashfn(keyof(elem)), elem); \
...
...
ccan/htable/test/run-type.c
View file @
fb92682e
...
@@ -110,13 +110,13 @@ static bool check_mask(struct htable *ht, const struct obj val[], unsigned num)
...
@@ -110,13 +110,13 @@ static bool check_mask(struct htable *ht, const struct obj val[], unsigned num)
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
unsigned
int
i
;
unsigned
int
i
;
struct
htable_obj
ht
;
struct
htable_obj
ht
,
ht2
;
struct
obj
val
[
NUM_VALS
],
*
result
;
struct
obj
val
[
NUM_VALS
],
*
result
;
unsigned
int
dne
;
unsigned
int
dne
;
void
*
p
;
void
*
p
;
struct
htable_obj_iter
iter
;
struct
htable_obj_iter
iter
;
plan_tests
(
2
7
);
plan_tests
(
2
9
);
for
(
i
=
0
;
i
<
NUM_VALS
;
i
++
)
for
(
i
=
0
;
i
<
NUM_VALS
;
i
++
)
val
[
i
].
key
=
i
;
val
[
i
].
key
=
i
;
dne
=
i
;
dne
=
i
;
...
@@ -171,8 +171,12 @@ int main(int argc, char *argv[])
...
@@ -171,8 +171,12 @@ int main(int argc, char *argv[])
find_vals
(
&
ht
,
val
,
NUM_VALS
);
find_vals
(
&
ht
,
val
,
NUM_VALS
);
ok1
(
!
htable_obj_get
(
&
ht
,
&
dne
));
ok1
(
!
htable_obj_get
(
&
ht
,
&
dne
));
/* Check copy. */
ok1
(
htable_obj_copy
(
&
ht2
,
&
ht
));
/* Delete them all by key. */
/* Delete them all by key. */
del_vals_bykey
(
&
ht
,
val
,
NUM_VALS
);
del_vals_bykey
(
&
ht
,
val
,
NUM_VALS
);
del_vals_bykey
(
&
ht2
,
val
,
NUM_VALS
);
/* Write two of the same value. */
/* Write two of the same value. */
val
[
1
]
=
val
[
0
];
val
[
1
]
=
val
[
0
];
...
@@ -201,5 +205,6 @@ int main(int argc, char *argv[])
...
@@ -201,5 +205,6 @@ int main(int argc, char *argv[])
}
}
htable_obj_clear
(
&
ht
);
htable_obj_clear
(
&
ht
);
htable_obj_clear
(
&
ht2
);
return
exit_status
();
return
exit_status
();
}
}
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