[ovs-dev] [PATCH v3 01/10] lib: Add smap_equal().

Ben Pfaff blp at nicira.com
Tue Jul 28 18:13:46 UTC 2015


On Tue, Jul 21, 2015 at 12:59:11PM -0400, Russell Bryant wrote:
> Add a method to determine of two smaps are equal (have the exact same
> set of key-value pairs).
> 
> Signed-off-by: Russell Bryant <rbryant at redhat.com>

Can't this be done in O(n) instead of O(n log n)?

bool
smap_equal(const struct smap *smap1, const struct smap *smap2)
{
    if (smap_count(smap1) != smap_count(smap2)) {
        return false;
    }

    const struct smap_node *node;
    SMAP_FOR_EACH (node, smap1) {
        const char *value2 = smap_get(smap2, node->key);
        if (!value2 || strcmp(node->value, value2)) {
            return false;
        }
    }
    return true;
}



More information about the dev mailing list