Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp322265pxv; Thu, 8 Jul 2021 22:24:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyj3H86crxDrzhO3vEh2pOKnQbip5FiCYx4K69KCUOrvrEHCgRwNR2r7PPuM32mC+SCdrxK X-Received: by 2002:a02:cc73:: with SMTP id j19mr30068220jaq.121.1625808257776; Thu, 08 Jul 2021 22:24:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625808257; cv=none; d=google.com; s=arc-20160816; b=yIemgNHH0qoKK5OaHMWmaTaIDZj6nVRbArAVDn9Sl/rkULS2Oy6nvBOHuv5iRvLkEy jboeE/dffSKPOCZUt/jgQdZJToJzjuPP8in7LU6dEjfeeuK+d7NrZPYjVu+HVXM4I0Fq ObXIcai8yS4iVooY3tiKXy4cfutthTmYLWRr97getWdiRJ0WDp5zVFt6nGXgUwDhOk9B CBcapeSuvZmA02AmHcrlB3n1nGm1oZl0nMWqMNNhcVC1Gi2BTNP9QtXAavbm0vF6oWtc 8o7RDhCrnd/DiW+0Oy1PqZvzfodH1lzmUeMjehOw9OsLAZhhxbUNEBslgYDnl8hw4W+w yFmw== 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=7glaz09LYK1wgJStu1fhPymyoFrPcqtPcZcOpaCWbGE=; b=ONufCgrh9u5mJSp5kGvNOtw5jvUMlEsNUyJtmLGNeLQo3fyhTBTwYSnpODdvDm/rFQ drgKpdxzf3TedpGTvhc8QU/k9zuiguklAXVD1s73QH48ISbpvo6BxL5Je4AFcgKGbCP2 7XorWu7orzUJQoQL4t0gXNaI5OPDqZnWQP+vEyG4x7gjf/G+zYlMi3xgU8kD66pWztUz kXEPI8XfOlVDDFg/289OE9cu6onMWhkLkM56PJqo2MwGxKsL43cH5cbRROPjLAvCbKAj RZEIqLjZuvVN8wJCPEmBIy3mcUEBpnzdvB+NXFbiibTV4vpGPWSVyFJIr2T+OtFmCsUV ienQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=lSQLveN6; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m13si4611970iln.153.2021.07.08.22.23.46; Thu, 08 Jul 2021 22:24:17 -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=@gmail.com header.s=20161025 header.b=lSQLveN6; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229618AbhGIFX7 (ORCPT + 99 others); Fri, 9 Jul 2021 01:23:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229583AbhGIFX7 (ORCPT ); Fri, 9 Jul 2021 01:23:59 -0400 Received: from mail-yb1-xb29.google.com (mail-yb1-xb29.google.com [IPv6:2607:f8b0:4864:20::b29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEEF8C061574 for ; Thu, 8 Jul 2021 22:21:15 -0700 (PDT) Received: by mail-yb1-xb29.google.com with SMTP id o139so12719044ybg.9 for ; Thu, 08 Jul 2021 22:21:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=7glaz09LYK1wgJStu1fhPymyoFrPcqtPcZcOpaCWbGE=; b=lSQLveN6qOBiYywViZLOtei7SSgIciQqrbVMcJWZK9uYXBfSYcwj5ivEmMqXohVc05 X2q+6Z+b/Bd5zDo3sT5toZ9kaMZEjPS3QOCEbUf5PQq7NSISUETS1pkxayC/13jSyVNS /inLuvulmcPiTO9ozcztiFTMxzKK+Luj75HHLz9pzuoEYmMr9UXlxNK4m/d41KA7bT7I J4XPaNtZC8KTDUvTJwBn3XAvkmUa6E2GABcT9p7f9+f7SK9hHUNurT9MVKtDMhYqdUos 8j2OPJZqLZGfCL3VZkZIOTPa7Lx4JoidKB4MtvNw0o4g9ZfFASURPMFxV0zBpq0A15EH bxjA== 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=7glaz09LYK1wgJStu1fhPymyoFrPcqtPcZcOpaCWbGE=; b=jC1FV1AY8WcLL7ZQTAYbW+Bol010mtaL27qQg25Vz+0+GFl/RLPs/Xom9MAK/ulNnf bTXqP425wRreN9yW6O3VVtOFYb8jnsoaOH2Ee2SB+pACHZDUKn8FExtmhiGJOs3BFT1K ZbN3iDFgDRbC5I1TGqI4nghbIiANyPH2n/hhGO+V+p/QxD7It/N9+AofN+xZ6F3JDHha OVb0DYHy62xmvimFf8mV+1HootdI+X2ps/yCLmPcoNt9K/kS4wEv0aMZpA3W6aWo0hxD nscBlOhi4gsGmodR5e5RoFDwnGP0weaLX3DIFRsJ8vYKgJ7phBSWd2vcsv7Dqav+F/Th g6mA== X-Gm-Message-State: AOAM531Ou71uHand2WFWbrqEkThAakvksS/Mpj5oKeVu0y/Q4Nk/VfgA IGQk4EF+z/B5Xpai5o+w2ZQrLUICsqQOZ5QH47I= X-Received: by 2002:a25:b741:: with SMTP id e1mr45646724ybm.347.1625808075135; Thu, 08 Jul 2021 22:21:15 -0700 (PDT) MIME-Version: 1.0 References: <20210708062314.245754-1-howardchung@google.com> <20210708142059.Bluez.v1.1.I69278fab3bf86adb578c5cba0a39e5bcf7f9581e@changeid> In-Reply-To: <20210708142059.Bluez.v1.1.I69278fab3bf86adb578c5cba0a39e5bcf7f9581e@changeid> From: Luiz Augusto von Dentz Date: Thu, 8 Jul 2021 22:21:04 -0700 Message-ID: Subject: Re: [Bluez PATCH v1 01/14] lib: add hash functions for bt_uuid_t To: Howard Chung 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 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