[ovs-dev] [bug 10184 3/5] hmap: New function hmap_contains().
Ethan Jackson
ethan at nicira.com
Tue Mar 20 22:48:23 UTC 2012
Looks good.
Ethan
On Tue, Mar 20, 2012 at 15:44, Ben Pfaff <blp at nicira.com> wrote:
> This is useful in a situation where one knows that an hmap_node is in some
> hmap, but it's not certain which one, and one needs to know whether it is
> in a particular one. This is not a very common case; I don't see any
> potential users in the current tree, although an upcoming commit will add
> one.
>
> Signed-off-by: Ben Pfaff <blp at nicira.com>
> ---
> lib/hmap.c | 17 ++++++++++++++++-
> lib/hmap.h | 4 +++-
> 2 files changed, 19 insertions(+), 2 deletions(-)
>
> diff --git a/lib/hmap.c b/lib/hmap.c
> index 9f27744..5862b62 100644
> --- a/lib/hmap.c
> +++ b/lib/hmap.c
> @@ -1,5 +1,5 @@
> /*
> - * Copyright (c) 2008, 2009, 2010 Nicira Networks.
> + * Copyright (c) 2008, 2009, 2010, 2012 Nicira Networks.
> *
> * Licensed under the Apache License, Version 2.0 (the "License");
> * you may not use this file except in compliance with the License.
> @@ -261,3 +261,18 @@ hmap_at_position(const struct hmap *hmap,
> *offsetp = 0;
> return NULL;
> }
> +
> +/* Returns true if 'node' is in 'hmap', false otherwise. */
> +bool
> +hmap_contains(const struct hmap *hmap, const struct hmap_node *node)
> +{
> + struct hmap_node *p;
> +
> + for (p = hmap_first_in_bucket(hmap, node->hash); p; p = p->next) {
> + if (p == node) {
> + return true;
> + }
> + }
> +
> + return false;
> +}
> diff --git a/lib/hmap.h b/lib/hmap.h
> index ed2d78d..246fba2 100644
> --- a/lib/hmap.h
> +++ b/lib/hmap.h
> @@ -1,5 +1,5 @@
> /*
> - * Copyright (c) 2008, 2009, 2010 Nicira Networks.
> + * Copyright (c) 2008, 2009, 2010, 2012 Nicira Networks.
> *
> * Licensed under the Apache License, Version 2.0 (the "License");
> * you may not use this file except in compliance with the License.
> @@ -130,6 +130,8 @@ static inline struct hmap_node *hmap_first_in_bucket(const struct hmap *,
> size_t hash);
> static inline struct hmap_node *hmap_next_in_bucket(const struct hmap_node *);
>
> +bool hmap_contains(const struct hmap *, const struct hmap_node *);
> +
> /* Iteration. */
>
> /* Iterates through every node in HMAP. */
> --
> 1.7.2.5
>
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev
More information about the dev
mailing list