Skip to content

Commit

Permalink
Move the hash_table impl structs to their own .h file (#295)
Browse files Browse the repository at this point in the history
* move the hash_table impl structs to their own .h file
  • Loading branch information
danielsn authored and justinboswell committed Apr 1, 2019
1 parent 806156f commit fbe9359
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 22 deletions.
42 changes: 42 additions & 0 deletions include/aws/common/private/hash_table_impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#ifndef AWS_COMMON_PRIVATE_HASH_TABLE_IMPL_H
#define AWS_COMMON_PRIVATE_HASH_TABLE_IMPL_H

/*
* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

#include <aws/common/hash_table.h>

struct hash_table_entry {
struct aws_hash_element element;
uint64_t hash_code; /* hash code (0 signals empty) */
};

struct hash_table_state {
aws_hash_fn *hash_fn;
aws_hash_callback_eq_fn *equals_fn;
aws_hash_callback_destroy_fn *destroy_key_fn;
aws_hash_callback_destroy_fn *destroy_value_fn;
struct aws_allocator *alloc;

size_t size, entry_count;
size_t max_load;
/* We AND a hash value with mask to get the slot index */
size_t mask;
double max_load_factor;
/* actually variable length */
struct hash_table_entry slots[1];
};

#endif /* AWS_COMMON_PRIVATE_HASH_TABLE_IMPL_H */
23 changes: 1 addition & 22 deletions source/hash_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
*/

#include <aws/common/hash_table.h>

#include <aws/common/math.h>
#include <aws/common/private/hash_table_impl.h>
#include <aws/common/string.h>

#include <limits.h>
Expand All @@ -41,27 +41,6 @@ static void s_suppress_unused_lookup3_func_warnings(void) {
(void)hashbig;
}

struct hash_table_entry {
struct aws_hash_element element;
uint64_t hash_code; /* hash code (0 signals empty) */
};

struct hash_table_state {
aws_hash_fn *hash_fn;
aws_hash_callback_eq_fn *equals_fn;
aws_hash_callback_destroy_fn *destroy_key_fn;
aws_hash_callback_destroy_fn *destroy_value_fn;
struct aws_allocator *alloc;

size_t size, entry_count;
size_t max_load;
/* We AND a hash value with mask to get the slot index */
size_t mask;
double max_load_factor;
/* actually variable length */
struct hash_table_entry slots[1];
};

static uint64_t s_hash_for(struct hash_table_state *state, const void *key) {
s_suppress_unused_lookup3_func_warnings();

Expand Down

0 comments on commit fbe9359

Please sign in to comment.