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

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

Add key equality function option for hash_map

This will allow us to do deeper equality on things like
bluetooth addresses where the actual pointers are different
but the values of the bluetooth addresses are the same.
parent a0c474ae
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -179,7 +179,7 @@ void bta_sys_init(void)
    pthread_mutex_init(&bta_alarm_lock, NULL);
    pthread_mutex_init(&bta_alarm_lock, NULL);


    bta_alarm_hash_map = hash_map_new(BTA_ALARM_HASH_MAP_SIZE,
    bta_alarm_hash_map = hash_map_new(BTA_ALARM_HASH_MAP_SIZE,
            hash_function_pointer, NULL, (data_free_fn)alarm_free);
            hash_function_pointer, NULL, (data_free_fn)alarm_free, NULL);
    btu_bta_alarm_queue = fixed_queue_new(SIZE_MAX);
    btu_bta_alarm_queue = fixed_queue_new(SIZE_MAX);


    fixed_queue_register_dequeue(btu_bta_alarm_queue,
    fixed_queue_register_dequeue(btu_bta_alarm_queue,
+1 −1
Original line number Original line Diff line number Diff line
@@ -121,7 +121,7 @@ static future_t *counter_init(void) {
  assert(hash_map_counter_ == NULL);
  assert(hash_map_counter_ == NULL);
  pthread_mutex_init(&hash_map_lock_, NULL);
  pthread_mutex_init(&hash_map_lock_, NULL);
  hash_map_counter_ = hash_map_new(COUNTER_NUM_BUCKETS, hash_function_string,
  hash_map_counter_ = hash_map_new(COUNTER_NUM_BUCKETS, hash_function_string,
      NULL, hash_element_free_);
      NULL, hash_element_free_, NULL);
  if (hash_map_counter_ == NULL) {
  if (hash_map_counter_ == NULL) {
    LOG_ERROR("%s unable to allocate resources", __func__);
    LOG_ERROR("%s unable to allocate resources", __func__);
    return future_new_immediate(FUTURE_FAIL);
    return future_new_immediate(FUTURE_FAIL);
+2 −1
Original line number Original line Diff line number Diff line
@@ -49,7 +49,8 @@ void module_management_start(void) {
    number_of_metadata_buckets,
    number_of_metadata_buckets,
    hash_function_pointer,
    hash_function_pointer,
    NULL,
    NULL,
    osi_free
    osi_free,
    NULL
  );
  );


  pthread_mutex_init(&metadata_lock, NULL);
  pthread_mutex_init(&metadata_lock, NULL);
+1 −1
Original line number Original line Diff line number Diff line
@@ -53,7 +53,7 @@ static hash_map_t *partial_packets;


static void init(const packet_fragmenter_callbacks_t *result_callbacks) {
static void init(const packet_fragmenter_callbacks_t *result_callbacks) {
  callbacks = result_callbacks;
  callbacks = result_callbacks;
  partial_packets = hash_map_new(NUMBER_OF_BUCKETS, hash_function_naive, NULL, NULL);
  partial_packets = hash_map_new(NUMBER_OF_BUCKETS, hash_function_naive, NULL, NULL, NULL);
}
}


static void cleanup() {
static void cleanup() {
+5 −1
Original line number Original line Diff line number Diff line
@@ -36,6 +36,8 @@ typedef size_t hash_index_t;
typedef hash_index_t (*hash_index_fn)(const void *key);
typedef hash_index_t (*hash_index_fn)(const void *key);
typedef bool (*hash_map_iter_cb)(hash_map_entry_t *hash_entry, void *context);
typedef bool (*hash_map_iter_cb)(hash_map_entry_t *hash_entry, void *context);


typedef bool (*key_equality_fn)(const void *x, const void *y);

typedef void (*key_free_fn)(void *data);
typedef void (*key_free_fn)(void *data);
typedef void (*data_free_fn)(void *data);
typedef void (*data_free_fn)(void *data);


@@ -44,7 +46,9 @@ hash_map_t *hash_map_new(
    size_t size,
    size_t size,
    hash_index_fn hash_fn,
    hash_index_fn hash_fn,
    key_free_fn key_fn,
    key_free_fn key_fn,
    data_free_fn);
    data_free_fn data_fn,
    key_equality_fn equality_fn);

void hash_map_free(hash_map_t *hash_map);
void hash_map_free(hash_map_t *hash_map);


// Accessors.
// Accessors.
Loading