Re: [Bluez PATCH v1 01/14] lib: add hash functions for bt_uuid_t

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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
<luiz.dentz@xxxxxxxxx> wrote:
>
> Hi Howard,
>
> On Wed, Jul 7, 2021 at 11:23 PM Howard Chung <howardchung@xxxxxxxxxx> 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 <mcchou@xxxxxxxxxxxx>
> > ---
> >
> >  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 <string.h>
> >  #include <stdlib.h>
> >  #include <errno.h>
> > +#include <glib.h>
> >
> >  #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 <stdint.h>
> > +#include <glib.h>
> >
> >  #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



[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux