From patchwork Tue Aug 13 00:51:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi-Hung Wei X-Patchwork-Id: 1145967 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="IpJGryUf"; dkim-atps=neutral Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 466vPB5hHxz9sND for ; Tue, 13 Aug 2019 10:54:22 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 37679C6C; Tue, 13 Aug 2019 00:51:52 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 3BB6BBE7 for ; Tue, 13 Aug 2019 00:51:51 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pf1-f195.google.com (mail-pf1-f195.google.com [209.85.210.195]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id E9E14CF for ; Tue, 13 Aug 2019 00:51:50 +0000 (UTC) Received: by mail-pf1-f195.google.com with SMTP id f17so46581259pfn.6 for ; Mon, 12 Aug 2019 17:51:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/ZeV+Wut2btzSdkAuaK8sgNT43pYVbic9Z6fDLqSTlE=; b=IpJGryUfmYYFq7GzuHxYOOFDOktvgNxuyCyTRHX6b1gcUS5gYHs6N+UsxCpg0RqIZe vcSycJoBIz0A02VUrdlIxD0dvVAnl7Ns0oId4bImhEmR2L9vvUy7dfO7QkXmKmYNhQbx 1B1wcyRw9Igu1HA5eUipbVIa5GMAVGYAPqobwDvT4eq0zyAc/y374xInWob1QeAxx+sQ 27TkeaWZmM2MPGDid5IjhjYcW8n5jssgDm1eJIdBev45xNn7HDKKXV/3nx8zd09Rm+OU z6EpfD5b/B4EozqmQbLKTvJX5dReI59uMqL9PS4ypbW/NRA5SkfwdurpEAKMz/8+DeIv 0vGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/ZeV+Wut2btzSdkAuaK8sgNT43pYVbic9Z6fDLqSTlE=; b=YVinUz5giPvc2hxAh73UJkM1W2Yl057NQip8uJPRBCrrKJUFgPyT3bRJogpf+6566I t45sOvni3sJpTdJnWzDxjrdqyUkbdhrbxVfvDNWF8xk2YCjDSB/VGYl7WaRJ3lU3BnUX y9IU7gY13IopoDgX3VZNKm9JnfcnsQayt+hvh9cfr/VFEpX42aR1nVV8OSZw6V2A0l5m vxDBpcof3wwcE6l7O+s/dUkDQzUY6ogjOfeU0GdFP3bdDq6nzhW06qTeSETrL4w+Wbjf 9TiXzXTEB6rEjZsZSnwRDURtnFn4Apso3srQx/m4YiBVqPn9K9nlvkb499sBw7zAmob4 TNKw== X-Gm-Message-State: APjAAAXaemD3/pI8y9smr68YzLLHAnHsvPPYn/khGoakRfYczwWinY8e YmOlqlXOzSXnnRt+FMhuvnOIPczR X-Google-Smtp-Source: APXvYqy1aW0OYiq870d/IFT1yQv1jZVSNE01TESmPXaF43HcW2HAotPnV7xB6N5PHWy8T3EY8n3vBQ== X-Received: by 2002:a17:90a:358a:: with SMTP id r10mr1870333pjb.30.1565657510078; Mon, 12 Aug 2019 17:51:50 -0700 (PDT) Received: from vm-main.eng.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id z4sm163581700pfg.166.2019.08.12.17.51.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 12 Aug 2019 17:51:49 -0700 (PDT) From: Yi-Hung Wei To: dev@openvswitch.org Date: Mon, 12 Aug 2019 17:51:34 -0700 Message-Id: <1565657498-62682-6-git-send-email-yihung.wei@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1565657498-62682-1-git-send-email-yihung.wei@gmail.com> References: <1565657498-62682-1-git-send-email-yihung.wei@gmail.com> X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH v3 5/9] simap: Add utility function to help compare two simaps. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org From: Ben Pfaff Signed-off-by: Ben Pfaff --- lib/simap.c | 15 ++++++++++++++- lib/simap.h | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/simap.c b/lib/simap.c index d634f8ed9eea..f404ece67703 100644 --- a/lib/simap.c +++ b/lib/simap.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2009, 2010, 2011, 2012, 2017 Nicira, Inc. + * Copyright (c) 2009, 2010, 2011, 2012, 2017, 2019 Nicira, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -242,6 +242,19 @@ simap_equal(const struct simap *a, const struct simap *b) return true; } +uint32_t +simap_hash(const struct simap *simap) +{ + uint32_t hash = 0; + + const struct simap_node *node; + SIMAP_FOR_EACH (node, simap) { + hash ^= hash_int(node->data, + hash_name(node->name, strlen(node->name))); + } + return hash; +} + static size_t hash_name(const char *name, size_t length) { diff --git a/lib/simap.h b/lib/simap.h index 5b4a2f39dca3..5e646e660782 100644 --- a/lib/simap.h +++ b/lib/simap.h @@ -70,6 +70,7 @@ bool simap_find_and_delete(struct simap *, const char *); const struct simap_node **simap_sort(const struct simap *); bool simap_equal(const struct simap *, const struct simap *); +uint32_t simap_hash(const struct simap *); #ifdef __cplusplus }