Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp373643pxf; Thu, 1 Apr 2021 03:32:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyf38M4h/Ju+i7LCrDX8jOfgyosvfBf4YxmbdkUqkx85C3ZXwA6RRiTjY1s4jtFiBbOWA9C X-Received: by 2002:a17:906:f8d5:: with SMTP id lh21mr8372782ejb.64.1617273158133; Thu, 01 Apr 2021 03:32:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617273158; cv=none; d=google.com; s=arc-20160816; b=E3iRRGwue5Nqjmqelx+NxrKDw6OlHjEx2uKSIiXdUjKIXdgIDxai6ArbookCdXwgcH tvJM7Qrz9vqB8ly0N1iZzvL2ExjdTcOsLODnDmPqks1WJnxwbL0Btf5SEbnidRQXjxTI SYdk9ocd+4HfqoBk+o5661HwzbNSM0QSzZ6Arqv4ZL9G0HZnKbx36iJQzTmg4qM6mW/U sDHwAc1FuncDH4aroJfHFYwAq2z0VNmpwlZ8vpOAv+mxy5/ol+Eh2uoMBeSaz1ljtGG7 2pzR1lxCVjWm0figf3cohhySx99u3yIUmCNA71K4UYITCfp1rW0o6vxbdefxbawwkXfJ JrjQ== 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=cO4AVl4n279ebsWSUVFtNX9Qx+EUeBMaQw67JXUvSvY=; b=yVRAWAEiieV0d6WEIMtB3AkHWtKqhhwZy8uJ2y+FJFv5582PESqmLpvkhh+04U7dQ0 BgQKUf7mhSn0c55i6oh1w9HNzHW4HNCxI40F5LlsP5O3jHBQJSIvHwXxnAsAkmL0wgSN 0+7NUj9kwJNQTey4qIj+qAQbkcF4e9yHpPKiNjqNFWCFujj8J8tVLFegK9uX1tciqJLj 9OBnh/i1zKSuC8eKg24BM9YNl7tjDMcZQPvyI22jS76Xt8322+Np/VViMI0iaWZGn7id 1t8tSfiskzLX5lHSy02aKbwOWfKpvX82uVbLTl5mIQ+icYACjiLodC+UAALnAjIgU9Mx 7PxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="OCei/5zV"; 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 t10si3683944ejf.297.2021.04.01.03.31.56; Thu, 01 Apr 2021 03:32:38 -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="OCei/5zV"; 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 S234358AbhDAK2M (ORCPT + 99 others); Thu, 1 Apr 2021 06:28:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50580 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234238AbhDAK1u (ORCPT ); Thu, 1 Apr 2021 06:27:50 -0400 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5FFC5C061793 for ; Thu, 1 Apr 2021 03:25:24 -0700 (PDT) Received: by mail-pl1-x649.google.com with SMTP id y19so2804379pll.8 for ; Thu, 01 Apr 2021 03:25:24 -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=cO4AVl4n279ebsWSUVFtNX9Qx+EUeBMaQw67JXUvSvY=; b=OCei/5zVNsnGKUZw/jxr29YLvkaNFnXaGn9oEn8VZeExRh/oEitNruJq0TT/H6TMVP CSdFhCApRUSTeUeRho4mWiRZnS4LNz8Fa/XrU3K0tLtPl8PC+9KVyBm/al/LpK2mBkiM ipleuFc1WT4I2xh23BNAfXrYLgRUpsx4ntoRuppC4UjuhJzKEgKprH0Pl1bbh1g2mLKV 7PMM8KIRLXFAZx77k/zYWGGfqKW/BA7vqexli+EWxvHTS2LRExUarCWsK5jsjjgleRpt Q4g5EtoUf7DpgfEr5GZ/Qr2wphwSA8gmae+Tb/aP2f5iRCljdPXjVAteFAPHGiJNqZqB LeeQ== 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=cO4AVl4n279ebsWSUVFtNX9Qx+EUeBMaQw67JXUvSvY=; b=FAXaMYoY7kRqKC891n1W7r+HoB3wzN+r/V/++867GndhefHMiR8eQ9qycjtO+dZ27n 8epB0D0zfdtHlYULDscpho4zECeTBwKq6lXiOF/f/l2QGuqUcGUUi1NHfkPN7Cmsj5kr Y5bC/ns2z4EULaSYjXh2gNsm4tu7I4W8Vn7WTv7oKlMK7v0mNxYr21XsAtNrcJl6RqPD ZNWxFkov3x/lBoJwFlqg+t0gzbiKAa2przNnJG9C1pLe3NGCCASgGlIrF46PJmRLv91w vl2aF+CInUSNCtNVJsspVgKwECewLPZS+T4VXQS93qTh7ymlY4Bkz8ACfwbmHhf1Tq/E 8W2A== X-Gm-Message-State: AOAM5303C0tMxFXM13L6GlONTHfFQFnhD6QpY0ebp6SwgXryhwVs9fcE nbYt1G/Rn5Tjv2lItzuKbP2eSw6ueYzq9Ne4iGwCjB8bxoia4we9HrwglSB6fTPPQxuGKKsa/Z0 NGl7w4TDV6EURQlu7yxl4fbv2rriq/Y6Z0HJOCb8WV5mAQ6ZtpSd9nyWQVIc9kdR1jER9cxD63W D2jwV7B09/SEk= X-Received: from howardchung-p920.tpe.corp.google.com ([2401:fa00:1:10:ad88:abe:9fd5:a5fc]) (user=howardchung job=sendgmr) by 2002:a62:7f86:0:b029:20a:a195:bb36 with SMTP id a128-20020a627f860000b029020aa195bb36mr6976280pfd.4.1617272723719; Thu, 01 Apr 2021 03:25:23 -0700 (PDT) Date: Thu, 1 Apr 2021 18:24:41 +0800 In-Reply-To: <20210401102447.3958224-1-howardchung@google.com> Message-Id: <20210401182328.Bluez.2.I2d1b00997951634dac9ea09da39fc9340ba7256b@changeid> Mime-Version: 1.0 References: <20210401102447.3958224-1-howardchung@google.com> X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog Subject: [Bluez PATCH 2/8] 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 | 21 +++++++++++++++++++++ lib/uuid.h | 3 +++ 2 files changed, 24 insertions(+) diff --git a/lib/uuid.c b/lib/uuid.c index a09321dc6ed1..0b0ddb3fc9d2 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,26 @@ 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; + + 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; + + 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.31.0.291.g576ba9dcdaf-goog