Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp170163pxv; Wed, 7 Jul 2021 23:25:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyHy4dyG00aj0lHx3cfEwzobLt0I7g9lBoppIBwPYRgaBsi6yQQ39BVPtMswQnqvAp/tH+6 X-Received: by 2002:a05:6402:2317:: with SMTP id l23mr36145222eda.265.1625725550231; Wed, 07 Jul 2021 23:25:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625725550; cv=none; d=google.com; s=arc-20160816; b=0GP8d1ut57ZJfEvDru3JHqmHkLj4QUgpfKeGFGU9bpWFXNfwHVYt9DaJS0ILXFrE/8 GWTUMgjEhMxyTeBED4PxWwEQfVBmyjI9i9jhKEwQBH2iEJw6EjZ3aGV96kgr4x1P5Das 8lmW16lhtCdGa7T2TtpkN1mxwxPtgCaDiFhx5vL0JzJ6/hwUtA+gxdizW/cCqATRMg3k oRQhJXtsErwihjaYwLo1oDE5x7ubeuKwh7dfeSWhguMKDZfbhiP+MZSHl+mMeKWcTwFK +KVO6Npu2nlHxc5W2KH7hOqFDji+a/wkglQzJBFwneis79HsAbDaeIqInyKNqZGvEjha QmtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=4YlKuUBAVCzUya4qwzfjFYw41CES3ee8lmcRt7kpXbI=; b=lCVA+fpN+cmMbxLioCwhuyBxexg61JBshyQqzdTFwCbUDuJhTaQSmpbgubHmvqpt0L mEVl7vAKW747cBXcBGFhVZyhCsF8uIKEIzapTvFeT9YCo5bY213fU6ugh+AD/r3c75x/ Nb83k3VNGSLger5h8xqrvbJanWpnl8qkMtV/R4arbzQOzV+W/s12tmIBEGpYaBY2jyML dyfovcvN6lrtR2GUFqOkSRRHhUguWJPVMRp+YAursyM1x9Hf7UO0fglvza4kPKms86Tf YMk4Vpv7PXC1sq3ghEC83NkJxnB/vGGtxgT/VS064EUIP30nZ56T2VDLiV9Z9q/uuXLT 8ndQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=YjpgoJ++; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hb14si1851310ejb.644.2021.07.07.23.24.51; Wed, 07 Jul 2021 23:25:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=YjpgoJ++; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229735AbhGHG0K (ORCPT + 99 others); Thu, 8 Jul 2021 02:26:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229608AbhGHG0K (ORCPT ); Thu, 8 Jul 2021 02:26:10 -0400 Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A8D9C061574 for ; Wed, 7 Jul 2021 23:23:28 -0700 (PDT) Received: by mail-qk1-x74a.google.com with SMTP id a6-20020a37b1060000b02903b488f9d348so3196250qkf.20 for ; Wed, 07 Jul 2021 23:23:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=4YlKuUBAVCzUya4qwzfjFYw41CES3ee8lmcRt7kpXbI=; b=YjpgoJ++8h/jrhemV9NdBxNEswKo0ShewItkHTOHerfRpB4zqK5pZmUaa1m/j4vVY9 +CnakWFM4MsxevmVOZDL4PUl7ugBS02g3KtIBml08PsU8Dvlf+amAN2JyPDQCq1mHVzG g3aJtF7CzYsn0dzHqmu9PWpnK0et60TJb2EZPZJo0PzdgfaLv9SDXTxJB1ozxJ/cdcMd PR+PdP7CU5sMK3RnUPbmFfUfFrH40kaBmKEv+4D0VUrdOQ9ViWr0Ck1R4nn0Ww4KdeF/ DoBlCOZOMcfQFfZPh/aQ8JhDRpE0DHt4R2hdYCewGrddsrA9Uk9XKF8WQnZV0S8knWrK aqFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=4YlKuUBAVCzUya4qwzfjFYw41CES3ee8lmcRt7kpXbI=; b=Doh7CNYtRJBbZrBl0a+H3RGBf0ayEZrqf/qtKsbqAXslu35bVSu5zZ8NXZ22glfNu/ 6sln9z/gidHrAKQgqSEIlSG271FlDh5QpAo9DZtLAyfXB6XMwXoS5kJMN49XAWLvER2M VCgAx3Z+4vaIcj8M4Qa/lqkspU7+RBcq88KUNkxt5HB5lzNOj4NGzbowjOnzFb1X/Rmy G65EcNdul+iiuMmn+dJBAQGKaPiCk12khJ5JkINYnzr+4poUZygTJTFpZzTZz94wrT+5 efWNj+DkQIonvvJt20fl3y8H8qLDt86TbDh3hve1kMJtrYoUkwgoldHMugAQPFKhWfVi 4Tmg== X-Gm-Message-State: AOAM5301EPoomY4XH0ZenY8Rz3mczPYgiOuiOD4NSvcBOgZxnPA8ny8Y ZxgHdFdGLWbYVGn3+3km7dUeTrUbn2I1oB1DfqLJlj6F07yd4SGfVTFYOra81xe0yuhG7nMUoVt C3OXBRbDY4eWOeNYOLdXmrFL64NrURaejEZwLxN8lw7DZ6pg6IRZZYIHIKWVblNX2bAGlHLp1QF p8HZyUDS8pNW4= X-Received: from howardchung-p920.tpe.corp.google.com ([2401:fa00:1:10:de70:7033:67f7:8d0b]) (user=howardchung job=sendgmr) by 2002:a05:6214:15d0:: with SMTP id p16mr28088061qvz.21.1625725407489; Wed, 07 Jul 2021 23:23:27 -0700 (PDT) Date: Thu, 8 Jul 2021 14:23:01 +0800 In-Reply-To: <20210708062314.245754-1-howardchung@google.com> Message-Id: <20210708142059.Bluez.v1.1.I69278fab3bf86adb578c5cba0a39e5bcf7f9581e@changeid> Mime-Version: 1.0 References: <20210708062314.245754-1-howardchung@google.com> X-Mailer: git-send-email 2.32.0.93.g670b81a890-goog Subject: [Bluez PATCH v1 01/14] lib: add hash functions for bt_uuid_t From: Howard Chung To: linux-bluetooth@vger.kernel.org, luiz.dentz@gmail.com Cc: Howard Chung , Miao-chen Chou Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This adds function GHashFunc and GEqualFunc for bt_uuid_t. With these functions, we can add uuids into a GHashTable with bt_uuid_t format. Reviewed-by: Miao-chen Chou --- lib/uuid.c | 27 +++++++++++++++++++++++++++ lib/uuid.h | 3 +++ 2 files changed, 30 insertions(+) diff --git a/lib/uuid.c b/lib/uuid.c index 3d97dc8359c7..a09f5c428b87 100644 --- a/lib/uuid.c +++ b/lib/uuid.c @@ -16,6 +16,7 @@ #include #include #include +#include #include "lib/bluetooth.h" #include "uuid.h" @@ -120,6 +121,32 @@ int bt_uuid_cmp(const bt_uuid_t *uuid1, const bt_uuid_t *uuid2) return bt_uuid128_cmp(&u1, &u2); } +guint bt_uuid_hash(gconstpointer key) +{ + const bt_uuid_t *uuid = key; + bt_uuid_t uuid_128; + uint64_t *val; + + if (!uuid) + return 0; + + bt_uuid_to_uuid128(uuid, &uuid_128); + val = (uint64_t *)&uuid_128.value.u128; + + return g_int64_hash(val) ^ g_int64_hash(val+1); +} + +gboolean bt_uuid_equal(gconstpointer v1, gconstpointer v2) +{ + const bt_uuid_t *uuid1 = v1; + const bt_uuid_t *uuid2 = v2; + + if (!uuid1 || !uuid2) + return !uuid1 && !uuid2; + + return bt_uuid_cmp(uuid1, uuid2) == 0; +} + /* * convert the UUID to string, copying a maximum of n characters. */ diff --git a/lib/uuid.h b/lib/uuid.h index 1a4029b68730..e47ccccb9fd2 100644 --- a/lib/uuid.h +++ b/lib/uuid.h @@ -17,6 +17,7 @@ extern "C" { #endif #include +#include #define GENERIC_AUDIO_UUID "00001203-0000-1000-8000-00805f9b34fb" @@ -167,6 +168,8 @@ int bt_uuid128_create(bt_uuid_t *btuuid, uint128_t value); int bt_uuid_cmp(const bt_uuid_t *uuid1, const bt_uuid_t *uuid2); void bt_uuid_to_uuid128(const bt_uuid_t *src, bt_uuid_t *dst); +guint bt_uuid_hash(gconstpointer key); +gboolean bt_uuid_equal(gconstpointer v1, gconstpointer v2); #define MAX_LEN_UUID_STR 37 -- 2.32.0.93.g670b81a890-goog