github.com/jlmucb/cloudproxy@v0.0.0-20170830161738-b5aa0b619bc4/cpvmm/vmm/utils/hash64.h (about) 1 /* 2 * Copyright (c) 2013 Intel Corporation 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * Unless required by applicable law or agreed to in writing, software 9 * distributed under the License is distributed on an "AS IS" BASIS, 10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 * See the License for the specific language governing permissions and 12 * limitations under the License. 13 */ 14 15 #ifndef _HASH64_H_ 16 #define _HASH64_H_ 17 18 #include <vmm_defs.h> 19 #include <hash64_api.h> 20 21 22 typedef struct HASH64_NODE_S 23 { 24 struct HASH64_NODE_S *next; 25 UINT64 key; 26 UINT64 value; 27 } HASH64_NODE; 28 29 INLINE HASH64_NODE* hash64_node_get_next(HASH64_NODE* cell) { 30 return cell->next; 31 } 32 33 INLINE void hash64_node_set_next(HASH64_NODE* cell, HASH64_NODE* next) { 34 cell->next = next; 35 } 36 37 INLINE UINT64 hash64_node_get_key(HASH64_NODE* cell) { 38 return cell->key; 39 } 40 41 INLINE void hash64_node_set_key(HASH64_NODE* cell, UINT64 key) { 42 cell->key = key; 43 } 44 45 INLINE UINT64 hash64_node_get_value(HASH64_NODE* cell) { 46 return cell->value; 47 } 48 49 INLINE void hash64_node_set_value(HASH64_NODE* cell, UINT64 value) { 50 cell->value = value; 51 } 52 53 typedef struct HASH64_TABLE_S { 54 HASH64_NODE** array; 55 HASH64_FUNC hash_func; 56 HASH64_INTERNAL_MEM_ALLOCATION_FUNC mem_alloc_func; 57 HASH64_INTERNAL_MEM_DEALLOCATION_FUNC mem_dealloc_func; 58 HASH64_NODE_ALLOCATION_FUNC node_alloc_func; 59 HASH64_NODE_DEALLOCATION_FUNC node_dealloc_func; 60 void* node_allocation_deallocation_context; 61 UINT32 size; 62 UINT32 element_count; 63 BOOLEAN is_multiple_values_hash; 64 UINT32 padding; // not in use 65 } HASH64_TABLE; 66 67 INLINE UINT32 hash64_get_hash_size(HASH64_TABLE* hash) { 68 return hash->size; 69 } 70 71 INLINE void hash64_set_hash_size(HASH64_TABLE* hash, UINT32 size) { 72 hash->size = size; 73 } 74 75 INLINE HASH64_NODE** hash64_get_array(HASH64_TABLE* hash) { 76 return hash->array; 77 } 78 79 INLINE void hash64_set_array(HASH64_TABLE* hash, HASH64_NODE** array) { 80 hash->array = array; 81 } 82 83 INLINE HASH64_FUNC hash64_get_hash_func(HASH64_TABLE* hash) { 84 return hash->hash_func; 85 } 86 87 INLINE void hash64_set_hash_func(HASH64_TABLE* hash, HASH64_FUNC hash_func) { 88 hash->hash_func = hash_func; 89 } 90 91 INLINE HASH64_INTERNAL_MEM_ALLOCATION_FUNC hash64_get_mem_alloc_func(HASH64_TABLE* hash) { 92 return hash->mem_alloc_func; 93 } 94 95 INLINE void hash64_set_mem_alloc_func(HASH64_TABLE* hash, HASH64_INTERNAL_MEM_ALLOCATION_FUNC mem_alloc_func) { 96 hash->mem_alloc_func = mem_alloc_func; 97 } 98 99 INLINE HASH64_INTERNAL_MEM_DEALLOCATION_FUNC hash64_get_mem_dealloc_func(HASH64_TABLE* hash) { 100 return hash->mem_dealloc_func; 101 } 102 103 INLINE void hash64_set_mem_dealloc_func(HASH64_TABLE* hash, 104 HASH64_INTERNAL_MEM_DEALLOCATION_FUNC mem_dealloc_func) { 105 hash->mem_dealloc_func = mem_dealloc_func; 106 } 107 108 INLINE HASH64_NODE_ALLOCATION_FUNC hash64_get_node_alloc_func(HASH64_TABLE* hash) { 109 return hash->node_alloc_func; 110 } 111 112 INLINE void hash64_set_node_alloc_func(HASH64_TABLE* hash, 113 HASH64_NODE_ALLOCATION_FUNC node_alloc_func) { 114 hash->node_alloc_func = node_alloc_func; 115 } 116 117 INLINE HASH64_NODE_DEALLOCATION_FUNC hash64_get_node_dealloc_func(HASH64_TABLE* hash) { 118 return hash->node_dealloc_func; 119 } 120 121 INLINE void hash64_set_node_dealloc_func(HASH64_TABLE* hash, 122 HASH64_NODE_DEALLOCATION_FUNC node_dealloc_func) { 123 hash->node_dealloc_func = node_dealloc_func; 124 } 125 126 INLINE void* hash64_get_allocation_deallocation_context(HASH64_TABLE* hash) { 127 return hash->node_allocation_deallocation_context; 128 } 129 130 INLINE void hash64_set_allocation_deallocation_context(HASH64_TABLE* hash, 131 void* context) { 132 hash->node_allocation_deallocation_context = context; 133 } 134 135 136 INLINE UINT32 hash64_get_element_count(HASH64_TABLE* hash) { 137 return hash->element_count; 138 } 139 140 INLINE void hash64_clear_element_count(HASH64_TABLE* hash) { 141 hash->element_count = 0; 142 } 143 144 INLINE void hash64_inc_element_count(HASH64_TABLE* hash) { 145 hash->element_count += 1; 146 } 147 148 INLINE void hash64_dec_element_count(HASH64_TABLE* hash) { 149 hash->element_count -= 1; 150 } 151 152 INLINE BOOLEAN hash64_is_multiple_values_hash(HASH64_TABLE* hash) { 153 return hash->is_multiple_values_hash; 154 } 155 156 INLINE void hash64_set_multiple_values_hash(HASH64_TABLE* hash) { 157 hash->is_multiple_values_hash = TRUE; 158 } 159 160 INLINE void hash64_set_single_value_hash(HASH64_TABLE* hash) { 161 hash->is_multiple_values_hash = FALSE; 162 } 163 164 #endif