Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c24243f2 authored by Zach Johnson's avatar Zach Johnson Committed by Andre Eisenbach
Browse files

Add a hash function for bluetooth addresses

Also includes simple tests for it + disambiguates
including hash_function.h throughout the stack.
parent 9b084791
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -34,9 +34,9 @@

#include "fixed_queue.h"
#include "gki.h"
#include "hash_functions.h"
#include "hash_map.h"
#include "osi.h"
#include "osi/include/hash_functions.h"
#include "osi/include/log.h"
#include "thread.h"
#if( defined BTA_AR_INCLUDED ) && (BTA_AR_INCLUDED == TRUE)
+1 −0
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ LOCAL_C_INCLUDES := \
    $(LOCAL_PATH)/..

LOCAL_SRC_FILES := \
    ./test/bdaddr_test.cpp \
    ./test/counter_test.cpp \
    ../osi/test/AllocationTestHarness.cpp

+5 −0
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@
#include <stdbool.h>
#include <stddef.h>

#include "osi/include/hash_map.h"

// Note: the string representation of a bdaddr is expected to have the format
// xx:xx:xx:xx:xx:xx
// where each 'x' is a hex digit. The API presented in this header will accept
@@ -49,3 +51,6 @@ bool string_is_bdaddr(const char *string);
// represent a Bluetooth address, |addr| is not modified and this function returns
// false. Otherwise, it returns true. Neither |string| nor |addr| may be NULL.
bool string_to_bdaddr(const char *string, bt_bdaddr_t *addr);

// A hash function tailored for bdaddrs.
hash_index_t hash_function_bdaddr(const void *key);
+8 −0
Original line number Diff line number Diff line
@@ -84,3 +84,11 @@ bool string_to_bdaddr(const char *string, bt_bdaddr_t *addr) {

  return ret;
}

hash_index_t hash_function_bdaddr(const void *key) {
  hash_index_t hash = 5381;
  const char *bytes = (const char *)key;
  for (size_t i = 0; i < sizeof(bt_bdaddr_t); ++i)
    hash = ((hash << 5) + hash) + bytes[i];
  return hash;
}
+1 −1
Original line number Diff line number Diff line
@@ -27,11 +27,11 @@
#include "allocator.h"
#include "atomic.h"
#include "counter.h"
#include "hash_functions.h"
#include "hash_map.h"
#include "list.h"
#include "module.h"
#include "osi.h"
#include "osi/include/hash_functions.h"
#include "osi/include/log.h"
#include "socket.h"
#include "thread.h"
Loading