[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH V11 1/7] Implement virHashRemoveAll function



On Tue, Apr 17, 2012 at 10:44:02AM -0400, Stefan Berger wrote:
> Implement function to remove all entries of a hash table.
> 
> ---
>  src/libvirt_private.syms |    1 +
>  src/util/virhash.c       |   25 +++++++++++++++++++++++++
>  src/util/virhash.h       |    5 +++++
>  3 files changed, 31 insertions(+)
> 
> Index: libvirt-acl/src/libvirt_private.syms
> ===================================================================
> --- libvirt-acl.orig/src/libvirt_private.syms
> +++ libvirt-acl/src/libvirt_private.syms
> @@ -578,6 +578,7 @@ virHashForEach;
>  virHashFree;
>  virHashGetItems;
>  virHashLookup;
> +virHashRemoveAll;
>  virHashRemoveEntry;
>  virHashRemoveSet;
>  virHashSearch;
> Index: libvirt-acl/src/util/virhash.c
> ===================================================================
> --- libvirt-acl.orig/src/util/virhash.c
> +++ libvirt-acl/src/util/virhash.c
> @@ -575,6 +575,31 @@ virHashRemoveSet(virHashTablePtr table,
>      return count;
>  }
>  
> +static int
> +_virHashRemoveAllIter(const void *payload ATTRIBUTE_UNUSED,
> +                      const void *name ATTRIBUTE_UNUSED,
> +                      const void *data ATTRIBUTE_UNUSED)
> +{
> +    return 1;
> +}
> +
> +/**
> + * virHashRemoveAll
> + * @table: the hash table to clear
> + *
> + * Free the hash @table's contents. The userdata is
> + * deallocated with the function provided at creation time.
> + *
> + * Returns the number of items removed on success, -1 on failure
> + */
> +ssize_t
> +virHashRemoveAll(virHashTablePtr table)
> +{
> +    return virHashRemoveSet(table,
> +                            _virHashRemoveAllIter,
> +                            NULL);
> +}
> +
>  /**
>   * virHashSearch:
>   * @table: the hash table to search
> Index: libvirt-acl/src/util/virhash.h
> ===================================================================
> --- libvirt-acl.orig/src/util/virhash.h
> +++ libvirt-acl/src/util/virhash.h
> @@ -127,6 +127,11 @@ int virHashRemoveEntry(virHashTablePtr t
>                         const void *name);
>  
>  /*
> + * Remove all entries from the hash table.
> + */
> +ssize_t virHashRemoveAll(virHashTablePtr table);
> +
> +/*
>   * Retrieve the userdata.
>   */
>  void *virHashLookup(virHashTablePtr table, const void *name);
> 

  There is certainly a way to implement this in a more efficient fashion
but that's fine :-)

  ACK,

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel veillard com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]