Looks Good.

On Fri, Mar 25, 2011 at 10:35 AM, Ben Pfaff <b...@nicira.com> wrote:
> ---
>  lib/list.c        |   16 +++++++++++++++-
>  lib/list.h        |    2 ++
>  tests/test-list.c |    4 +++-
>  3 files changed, 20 insertions(+), 2 deletions(-)
>
> diff --git a/lib/list.c b/list.c
> index 0f4f2f8..b5fa389 100644
> --- a/lib/list.c
> +++ b/lib/list.c
> @@ -1,5 +1,5 @@
>  /*
> - * Copyright (c) 2008, 2009, 2010 Nicira Networks.
> + * Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks.
>  *
>  * Licensed under the Apache License, Version 2.0 (the "License");
>  * you may not use this file except in compliance with the License.
> @@ -168,3 +168,17 @@ list_is_empty(const struct list *list)
>  {
>     return list->next == list;
>  }
> +
> +/* Returns true if 'list' has exactly 1 element, false otherwise. */
> +bool
> +list_is_singleton(const struct list *list)
> +{
> +    return list_is_short(list) && !list_is_empty(list);
> +}
> +
> +/* Returns true if 'list' has 0 or 1 elements, false otherwise. */
> +bool
> +list_is_short(const struct list *list)
> +{
> +    return list->next == list->prev;
> +}
> diff --git a/lib/list.h b/lib/list.h
> index 915ee85..91c3966 100644
> --- a/lib/list.h
> +++ b/lib/list.h
> @@ -53,6 +53,8 @@ struct list *list_back(const struct list *);
>  /* List properties. */
>  size_t list_size(const struct list *);
>  bool list_is_empty(const struct list *);
> +bool list_is_singleton(const struct list *);
> +bool list_is_short(const struct list *);
>
>  #define LIST_FOR_EACH(ITER, MEMBER, LIST)                               \
>     for (ASSIGN_CONTAINER(ITER, (LIST)->next, MEMBER);                  \
> diff --git a/tests/test-list.c b/tests/test-list.c
> index 5e62e0c..b4ddd02 100644
> --- a/tests/test-list.c
> +++ b/tests/test-list.c
> @@ -1,5 +1,5 @@
>  /*
> - * Copyright (c) 2008, 2009, 2010 Nicira Networks.
> + * Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks.
>  *
>  * Licensed under the Apache License, Version 2.0 (the "License");
>  * you may not use this file except in compliance with the License.
> @@ -73,6 +73,8 @@ check_list(struct list *list, const int values[], size_t n)
>     assert(i == n);
>
>     assert(list_is_empty(list) == !n);
> +    assert(list_is_singleton(list) == (n == 1));
> +    assert(list_is_short(list) == (n < 2));
>     assert(list_size(list) == n);
>  }
>
> --
> 1.7.1
>
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev
>
_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to