Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp2620743pxv; Sun, 11 Jul 2021 20:23:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxljf2/XuVQBn/4DJAXSoPZAiGruNQHw0ijK8lRB+qlTC5OujJH6WSAbueU6PPOC2uEy7wB X-Received: by 2002:a5d:91cc:: with SMTP id k12mr37774673ior.103.1626060183912; Sun, 11 Jul 2021 20:23:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626060183; cv=none; d=google.com; s=arc-20160816; b=xFIoLiE9gz2ZSZN78dYm2VYB1wcSZlV1OCjK2KikStcvSox2FqGxcL7Y3Ymw2D+Iuu Z3bwcv4ZHT2162JMh6oeR58G3HaN3ZiCDvZBBVEp8qP1pd0ehazZUgptuS+6nqiA8u9Q X/F7LcDW9NGBrBZnmEX2C2fjifYZrRSzsw/vhOFzkl9bqmIhu6FAQYMoMU2SqiX+PHRg OWTumG9HBqBwt+o6LxzkvdsJGhImdC72oY9uxY26wXXX8ay35WqPJmVF/+hn+ud0wmyv gxrgPHOUpqqq5wOfKoOoIlVf3KhRsKipxVaYeAMkO1ZadTsCQpU/DkZlLiFEw9O+D3xD F/KA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=mBGwT55KZMW6nT6ccK0tHsaonJzQURHuXC6ZcLj6PCA=; b=FLrtjBZU2Fn22OPzdpt/UgDFXYZIxsUL+kHKbGwf6DuWok632cMIm3NaWx+x5aX6HH F5kOFU4PRCGQrCO+6phBMaYC4P2qmqt7q/d0lqt2CKlwoFSKA1W/um1ktIZtYWfL7jkg WqCG6hpRLuId6ygs/J90J2PDNAfQQmSrAvXhTqES8kf8rBTYWm//JLNvMIabp5ne926K nM+pe0hKhApnVZvNC3XGXGGqOJGPmtCas7gpUmjMNXxojPEw0fU2dhFy48nSG3TYiSpp d7nIi0IExVE7GClppEvaOx7W9xZxPHoH06HzgPHjVMU6oGTG5UsjL64RooO9Euu25lCz d2kA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Z9DbHsHu; 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 x9si16164153jaf.48.2021.07.11.20.22.33; Sun, 11 Jul 2021 20:23:03 -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=Z9DbHsHu; 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 S233036AbhGLDXH (ORCPT + 99 others); Sun, 11 Jul 2021 23:23:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229891AbhGLDXH (ORCPT ); Sun, 11 Jul 2021 23:23:07 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CCA4C0613DD for ; Sun, 11 Jul 2021 20:20:19 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id bu12so31679090ejb.0 for ; Sun, 11 Jul 2021 20:20:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=mBGwT55KZMW6nT6ccK0tHsaonJzQURHuXC6ZcLj6PCA=; b=Z9DbHsHuRGEdkHa29KGQbj3lpHcyAR6M+3BjpEqj3wGErxHcgK5RHg5ABPnoQmcIiT 6tdTkJcwMVlCCim5KLEgpMgwDrDPf2sua83bI/ddo6oswksgX8PIzOGvQIBDfP3fGEwf ZXeqhHIJ8UztlqznJnc8gK/aQpTgwk90fgtuEUe6jscprQlwa7SKogSCmc4Ex7dZTgkP i4yK3XW559zX9F4lbQvkMzcNGW/gfzTbn5CZy1R5xEBLgfVqDIJifg4XCEXxl0ClOJxJ retBWaMcyo8OWH+tyFWMBlrx2M0HNxLpQx5srIvsBJp1C6moJIlgWHg+ehXKrtQ+0gi0 pcFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=mBGwT55KZMW6nT6ccK0tHsaonJzQURHuXC6ZcLj6PCA=; b=aGcZ5C10c6oDFtQ1l6KMDJWv9/hy3u+ZeZr3kpQKh8hDWLClBKzXpr4hyFkbeZOJf9 CAc5KfKVtEsx0oLyUNKb9pPaOBGeD5r/iSfDeZZYCUtzdZik18gXZluCrsCnPsXj0LBK yGe25CinbEnkGndHvynidQnuzZTDsjNyzDsXFe7bQb/Efz3gPyIZzVDnWZyPrMUTOcBy jML0l9x0XMsASCevMQAOH+o+q8ksvMnlcrXHCUN19+890UA0bfZlEyAm/NO95h/rnOC5 fh5vfShnqS750AZn4PFXrr4ci19Emr21bHM5pGPy9z2K0GCFEOItEVJoM3RL5l3I0laH rRqw== X-Gm-Message-State: AOAM532W8Lc5vpqacu+FdatLxHHGm3q5KiJ9XKvQYBqC8LB8BFpQGqW1 s/vv9uUfLo7z6A8P6Cv9peueN7m0jl56mHw/4n5llA== X-Received: by 2002:a17:906:c302:: with SMTP id s2mr49799717ejz.151.1626060017895; Sun, 11 Jul 2021 20:20:17 -0700 (PDT) MIME-Version: 1.0 References: <20210708062314.245754-1-howardchung@google.com> <20210708142059.Bluez.v1.1.I69278fab3bf86adb578c5cba0a39e5bcf7f9581e@changeid> In-Reply-To: From: Yun-hao Chung Date: Mon, 12 Jul 2021 11:20:06 +0800 Message-ID: Subject: Re: [Bluez PATCH v1 01/14] lib: add hash functions for bt_uuid_t To: Luiz Augusto von Dentz Cc: "linux-bluetooth@vger.kernel.org" , Miao-chen Chou Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Got it. Will move bt_uuid_hash and bt_uuid_equal to src/adapter.c On Fri, Jul 9, 2021 at 1:21 PM Luiz Augusto von Dentz wrote: > > Hi Howard, > > On Wed, Jul 7, 2021 at 11:23 PM Howard Chung wrote: > > > > 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. > > We will likely move away from GLib dependency so I wouldn't want to > introduce a dependency to it specially as part of libbluetooth. > > > 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 > > > > > -- > Luiz Augusto von Dentz