[ovs-dev] [PATCH 5/7] ovsdb-data: New function ovsdb_datum_from_shash().
Justin Pettit
jpettit at nicira.com
Wed Sep 22 23:24:28 PDT 2010
Ah, now I see. This is turning out to be much more interesting than watching "Weeds", which was my original plan for the evening.
--Justin
On Sep 22, 2010, at 4:45 PM, Ben Pfaff wrote:
> ---
> lib/ovsdb-data.c | 25 +++++++++++++++++++++++++
> lib/ovsdb-data.h | 3 +++
> 2 files changed, 28 insertions(+), 0 deletions(-)
>
> diff --git a/lib/ovsdb-data.c b/lib/ovsdb-data.c
> index 9c54fe8..451e673 100644
> --- a/lib/ovsdb-data.c
> +++ b/lib/ovsdb-data.c
> @@ -1444,6 +1444,31 @@ ovsdb_datum_to_string(const struct ovsdb_datum *datum,
> }
> }
>
> +/* Initializes 'datum' as a string-to-string map whose contents are taken from
> + * 'shash'. Destroys 'shash'. */
> +void
> +ovsdb_datum_from_shash(struct ovsdb_datum *datum, struct shash *sh)
> +{
> + struct shash_node *node, *next;
> + size_t i;
> +
> + datum->n = shash_count(sh);
> + datum->keys = xmalloc(datum->n * sizeof *datum->keys);
> + datum->values = xmalloc(datum->n * sizeof *datum->values);
> +
> + i = 0;
> + SHASH_FOR_EACH_SAFE (node, next, sh) {
> + datum->keys[i].string = node->name;
> + datum->values[i].string = node->data;
> + shash_steal(sh, node);
> + i++;
> + }
> + assert(i == datum->n);
> +
> + shash_destroy(sh);
> + ovsdb_datum_sort_unique(datum, OVSDB_TYPE_STRING, OVSDB_TYPE_STRING);
> +}
> +
> static uint32_t
> hash_atoms(enum ovsdb_atomic_type type, const union ovsdb_atom *atoms,
> unsigned int n, uint32_t basis)
> diff --git a/lib/ovsdb-data.h b/lib/ovsdb-data.h
> index ae0faa2..f7e98a8 100644
> --- a/lib/ovsdb-data.h
> +++ b/lib/ovsdb-data.h
> @@ -22,6 +22,7 @@
>
> struct ds;
> struct ovsdb_symbol_table;
> +struct shash;
>
> /* One value of an atomic type (given by enum ovs_atomic_type). */
> union ovsdb_atom {
> @@ -167,6 +168,8 @@ char *ovsdb_datum_from_string(struct ovsdb_datum *,
> void ovsdb_datum_to_string(const struct ovsdb_datum *,
> const struct ovsdb_type *, struct ds *);
>
> +void ovsdb_datum_from_shash(struct ovsdb_datum *, struct shash *);
> +
> /* Comparison. */
> uint32_t ovsdb_datum_hash(const struct ovsdb_datum *,
> const struct ovsdb_type *, uint32_t basis);
> --
> 1.7.1
>
>
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev_openvswitch.org
More information about the dev
mailing list