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
b98c6847
Commit
b98c6847
authored
Aug 13, 2019
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
htable: add htable_count().
Signed-off-by:
Rusty Russell
<
rusty@rustcorp.com.au
>
parent
e16aa40b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
5 deletions
+27
-5
ccan/htable/htable.h
ccan/htable/htable.h
+9
-0
ccan/htable/htable_type.h
ccan/htable/htable_type.h
+7
-0
ccan/htable/test/run-type.c
ccan/htable/test/run-type.c
+5
-2
ccan/htable/test/run.c
ccan/htable/test/run.c
+6
-3
No files found.
ccan/htable/htable.h
View file @
b98c6847
...
...
@@ -75,6 +75,15 @@ bool htable_init_sized(struct htable *ht,
size_t
(
*
rehash
)(
const
void
*
elem
,
void
*
priv
),
void
*
priv
,
size_t
size
);
/**
* htable_count - count number of entries in a hash table.
* @ht: the hash table
*/
static
inline
size_t
htable_count
(
const
struct
htable
*
ht
)
{
return
ht
->
elems
;
}
/**
* htable_clear - empty a hash table.
* @ht: the hash table to clear
...
...
ccan/htable/htable_type.h
View file @
b98c6847
...
...
@@ -25,6 +25,9 @@
* void <name>_clear(struct <name> *);
* bool <name>_copy(struct <name> *dst, const struct <name> *src);
*
* Count entries:
* size_t <name>_count(const struct <name> *ht);
*
* Add function only fails if we run out of memory:
* bool <name>_add(struct <name> *ht, const <type> *e);
*
...
...
@@ -69,6 +72,10 @@
{ \
return htable_init_sized(&ht->raw, name##_hash, NULL, s); \
} \
static inline UNNEEDED size_t name##_count(const struct name *ht) \
{ \
return htable_count(&ht->raw); \
} \
static inline UNNEEDED void name##_clear(struct name *ht) \
{ \
htable_clear(&ht->raw); \
...
...
ccan/htable/test/run-type.c
View file @
b98c6847
...
...
@@ -65,7 +65,7 @@ static void find_vals(const struct htable_obj *ht,
return
;
}
}
pass
(
"Found %u numbers in hash"
,
i
);
ok1
(
htable_obj_count
(
ht
)
==
i
);
}
static
void
del_vals
(
struct
htable_obj
*
ht
,
...
...
@@ -116,12 +116,13 @@ int main(void)
void
*
p
;
struct
htable_obj_iter
iter
;
plan_tests
(
29
);
plan_tests
(
32
);
for
(
i
=
0
;
i
<
NUM_VALS
;
i
++
)
val
[
i
].
key
=
i
;
dne
=
i
;
htable_obj_init
(
&
ht
);
ok1
(
htable_obj_count
(
&
ht
)
==
0
);
ok1
(
ht_max
(
&
ht
.
raw
)
==
0
);
ok1
(
ht
.
raw
.
bits
==
0
);
...
...
@@ -205,6 +206,8 @@ int main(void)
}
htable_obj_clear
(
&
ht
);
ok1
(
htable_obj_count
(
&
ht
)
==
0
);
htable_obj_clear
(
&
ht2
);
ok1
(
htable_obj_count
(
&
ht2
)
==
0
);
return
exit_status
();
}
ccan/htable/test/run.c
View file @
b98c6847
...
...
@@ -67,7 +67,7 @@ static void find_vals(struct htable *ht,
return
;
}
}
pass
(
"Found %llu numbers in hash"
,
(
long
long
)
i
);
ok1
(
htable_count
(
ht
)
==
i
);
}
static
void
del_vals
(
struct
htable
*
ht
,
...
...
@@ -105,12 +105,13 @@ int main(void)
void
*
p
;
struct
htable_iter
iter
;
plan_tests
(
3
6
);
plan_tests
(
3
8
);
for
(
i
=
0
;
i
<
NUM_VALS
;
i
++
)
val
[
i
]
=
i
;
dne
=
i
;
htable_init
(
&
ht
,
hash
,
NULL
);
ok1
(
htable_count
(
&
ht
)
==
0
);
ok1
(
ht_max
(
&
ht
)
==
0
);
ok1
(
ht
.
bits
==
0
);
...
...
@@ -207,6 +208,8 @@ int main(void)
ok1
(
htable_init_sized
(
&
ht
,
hash
,
NULL
,
1025
));
ok1
(
ht_max
(
&
ht
)
>=
1025
);
htable_clear
(
&
ht
);
ok1
(
htable_count
(
&
ht
)
==
0
);
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