From patchwork Thu Aug 15 19:31:16 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: 1147803 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="EAYtYoOT"; 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 468c953Tl1z9sML for ; Fri, 16 Aug 2019 05:34:49 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id B61B510F1; Thu, 15 Aug 2019 19:31:50 +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 144D310F1 for ; Thu, 15 Aug 2019 19:31:49 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id C05B367F for ; Thu, 15 Aug 2019 19:31:48 +0000 (UTC) Received: by mail-pl1-f181.google.com with SMTP id a93so1438999pla.7 for ; Thu, 15 Aug 2019 12:31:48 -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=EAYtYoOTlPiJibcRhmbPnnwEOW4I/y1FtyTgk+StoFtehxH7EkojNMPt52IdlSEQ/k BChOTUVPBC0bTHRkXbWaM1Mib7iER89pAesXYLZeq07txn9rLQeW4WbgQMD1MnqWg6Qh O9PIyuOpaR46d6zD9dWRBL/4ojkdPRrhmfFpLzaJiycnG3Oo0KGk8K0Y3msgovk/niZv 68SBE7NcwAxIu+C16dczfT53Wc/6IukawICdW+yGEnzkdlhKoOPOiMBCrOhi5+RScQE8 STu+65Bfnv8KD883CkjHckQldYWorVc1uvKx34ECUvTr/Vu8/6sDo+Zg0S8vHZjPd5qW eqvg== 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=A7v77uuWlgFCXsTHDsslDejyIQ39GqVA0sqzV4xXxennZkqvtuJtn4vVJuBHrqpkg+ yLx15nBSj/3RogbFTxSXwRbuqxmX48N6atkcPP9CnlxsBxwrd2pNP1oHmrja5VlM9QDt +SzzcofwE3hfnjrz+7QAa1lafMP92I3yYPpKEw2Ddu2ak1iJUrK9ZLUUVf67D/v4/qg6 J2K2CrK8QQ8lbXs7QHOORa4McKcGyqm2n4KtrdSN0jJM6/cRMrq6qwniD39liLQUAZi4 f3KWkcRPlGo+LBNukm1QVcZRmNpS06hSjHg2kjYpFX7CORQDmgHuPMCuyV7A/dwvQxWl Qw/g== X-Gm-Message-State: APjAAAXMYocfNqQL/0BQ7kaFSFmnjg18Xg1F4OmNir4gPQlzmkIELopV yoDYHjLJhGup20CH0ewxRc6hmIBZ X-Google-Smtp-Source: APXvYqxHPwIxO21iGR7Pj6EeU8ph5jNQQqJHmaLeROKSbFoSwf/pntkysul+U2iEBCT/didL3Hbk6g== X-Received: by 2002:a17:902:7288:: with SMTP id d8mr5762723pll.133.1565897507934; Thu, 15 Aug 2019 12:31:47 -0700 (PDT) Received: from vm-main.eng.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id ce7sm1925232pjb.16.2019.08.15.12.31.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 15 Aug 2019 12:31:47 -0700 (PDT) From: Yi-Hung Wei To: dev@openvswitch.org Date: Thu, 15 Aug 2019 12:31:16 -0700 Message-Id: <1565897480-120133-6-git-send-email-yihung.wei@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1565897480-120133-1-git-send-email-yihung.wei@gmail.com> References: <1565897480-120133-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 v4 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 }