github.com/jlmucb/cloudproxy@v0.0.0-20170830161738-b5aa0b619bc4/cpvmm/vmm/include/hash64_api.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_INTERFACE_H
    16  #define HASH64_INTERFACE_H
    17  
    18  #include <vmm_defs.h>
    19  
    20  typedef UINT32 (*HASH64_FUNC)(UINT64 key, UINT32 size);
    21  typedef void*  (*HASH64_INTERNAL_MEM_ALLOCATION_FUNC)(UINT32 size);
    22  typedef void   (*HASH64_INTERNAL_MEM_DEALLOCATION_FUNC)(void* data);
    23  typedef void*  (*HASH64_NODE_ALLOCATION_FUNC)(void* context);
    24  typedef void   (*HASH64_NODE_DEALLOCATION_FUNC)(void* context, void* data);
    25  
    26  typedef void* HASH64_HANDLE;
    27  typedef void* HASH64_MULTIPLE_VALUES_HASH_ITERATOR;
    28  #define HASH64_INVALID_HANDLE ((HASH64_HANDLE)NULL)
    29  #define HASH64_NULL_ITERATOR  ((HASH64_MULTIPLE_VALUES_HASH_ITERATOR)NULL)
    30  
    31  
    32  /* Function: hash64_get_node_size
    33  *  Description: This function returns the size of hash node.
    34  *
    35  *  Output: Size
    36  */
    37  UINT32 hash64_get_node_size(void);
    38  
    39  HASH64_HANDLE hash64_create_default_hash(UINT32 hash_size);
    40  
    41  /* Function: hash64_create_hash
    42  *  Description: This function is used in order to create 1-1 hash
    43  *  Input: hash_func - hash function which returns index in array which is lower
    44  *                     than "hash_size" parameter.
    45   *         mem_alloc_func - function which will be used for allocation of inner
    46   *                    data structures. If it is NULL then allocation will
    47   *                    be performed directly from heap.
    48   *         mem_dealloc_func - function which will be used for deallocation of
    49   *                    inner data structures. If it is NULL then deallocation
    50   *                    will be performed directly to heap.
    51   *         node_alloc_func - function which will be used for allocation of hash nodes.
    52   *                    Node that function doesn't receive the size as parameter.
    53   *                    In order to know the required size, use "hash64_get_node_size"
    54   *                    function.
    55   *         node_dealloc_func - function which will be used for deallocation of each node,
    56   *                    when necessary.
    57   *         node_allocation_deallocation_context - context which will be passed to
    58   *                    "node_alloc_func" and "node_dealloc_func"
    59   *                    functions as parameter.
    60   *         hash_size - number of cells in hash array.
    61   *  Return value: Hash handle which should be used as parameter for other functions.
    62   *                In case of failure, HASH64_INVALID_HANDLE will be returned
    63   */
    64  HASH64_HANDLE hash64_create_hash(HASH64_FUNC hash_func,
    65                                   HASH64_INTERNAL_MEM_ALLOCATION_FUNC mem_alloc_func,
    66                                   HASH64_INTERNAL_MEM_DEALLOCATION_FUNC mem_dealloc_func,
    67                                   HASH64_NODE_ALLOCATION_FUNC node_alloc_func,
    68                                   HASH64_NODE_DEALLOCATION_FUNC node_dealloc_func,
    69                                   void* node_allocation_deallocation_context,
    70                                   UINT32 hash_size);
    71  
    72  
    73  /* Function: hash64_create_hash
    74   *  Description: This function is used in order to destroy 1-1 hash
    75   *  Input: hash_handle - handle returned by "hash64_create_hash" function
    76   */
    77  void hash64_destroy_hash(HASH64_HANDLE hash_handle);
    78  
    79  
    80  /* Function: hash64_lookup
    81   *  Description: This function is used in order to find the value in 1-1 hash for given key.
    82   *  Input:
    83   *         hash_handle - handle returned by "hash64_create_hash" function
    84   *         key -
    85   *  Output:
    86   *         value -
    87   *  Return value: TRUE in case the value is found
    88   */
    89  BOOLEAN hash64_lookup(HASH64_HANDLE hash_handle,
    90                       UINT64 key,
    91                       UINT64* value);
    92  
    93  
    94  /* Function: hash64_insert
    95   *  Description: This function is used in order to insert the value into 1-1 hash.
    96   *               If some value for given key exists, FALSE will be returned.
    97   *  Input:
    98   *         hash_handle - handle returned by "hash64_create_hash" function
    99   *         key -
   100   *         value -
   101   *  Return value: TRUE in case the operation is successful
   102   */
   103  BOOLEAN hash64_insert(HASH64_HANDLE hash_handle,
   104                       UINT64 key,
   105                       UINT64 value);
   106  
   107  /* Function: hash64_update
   108   *  Description: This function is used in order to update the value in 1-1 hash.
   109   *               If the value doesn't exist it will be inserted.
   110   *  Input:
   111   *         hash_handle - handle returned by "hash64_create_hash" function
   112   *         key -
   113   *         value -
   114   *  Return value: TRUE in case the operation is successful
   115   */
   116  BOOLEAN hash64_update(HASH64_HANDLE hash_handle,
   117                       UINT64 key, UINT64 value);
   118  
   119  /* Function: hash64_remove
   120   *  Description: This function is used in order to remove the value from 1-1 hash.
   121   *  Input:
   122   *         hash_handle - handle returned by "hash64_create_hash" function
   123   *         key -
   124   *  Return value: TRUE in case the operation is successful
   125   */
   126  BOOLEAN hash64_remove(HASH64_HANDLE hash_handle,
   127                       UINT64 key);
   128  
   129  
   130  /* Function: hash64_is_empty
   131   *  Description: This function is used in order check whether 1-1 hash is empty.
   132   *  Input:
   133   *         hash_handle - handle returned by "hash64_create_hash" function
   134   *  Return value: TRUE in case the hash is empty.
   135   */
   136  BOOLEAN hash64_is_empty(HASH64_HANDLE hash_handle);
   137  
   138  /* Function: hash64_change_size_and_rehash
   139   *  Description: This function is used in order to change the size of the hash and rehash it.
   140   *  Input:
   141   *         hash_handle - handle returned by "hash64_create_hash" function
   142   *         hash_size   - new size
   143   *  Return value: TRUE in case the operation is successfull.
   144   */
   145  BOOLEAN hash64_change_size_and_rehash(HASH64_HANDLE hash_handle,
   146                                        UINT32 hash_size);
   147  
   148  
   149  /* Function: hash64_change_size_and_rehash
   150   *  Description: change the size of the hash and rehash it.
   151   *  Input:
   152   *         hash_handle - handle returned by "hash64_create_hash" function
   153   *  Return value: Number of elements in hash.
   154   */
   155  UINT32 hash64_get_num_of_elements(HASH64_HANDLE hash_handle);
   156  
   157  /* Function: hash64_get_current_size
   158   *  Description: This function returns the size (in number of cells) of hash array.
   159   *  Input:
   160   *         hash_handle - handle returned by "hash64_create_hash" function
   161   *  Return value: Size of hash.
   162   */
   163  UINT32 hash64_get_current_size(HASH64_HANDLE hash_handle);
   164  
   165  
   166  /* Function: hash64_create_multiple_values_hash
   167   *  Description: This function is used in order to create 1-n (one to many) hash
   168   *  Input: hash_func - hash function which returns index in array which is lower
   169   *                     than "hash_size" parameter.
   170   *         mem_alloc_func - function which will be used for allocation of inner
   171   *                      data structures. If it is NULL then allocation will
   172   *                      be performed directly from heap.
   173   *         mem_dealloc_func - function which will be used for deallocation of
   174   *                      inner data structures. If it is NULL then deallocation
   175   *                      will be performed directly to heap.
   176   *         node_alloc_func - function which will be used for allocation of hash nodes.
   177   *                      Node that function doesn't receive the size as parameter.
   178   *                      In order to know the required size, use "hash64_get_node_size"
   179   *                      function.
   180   *         node_dealloc_func - function which will be used for deallocation of each node,
   181   *                      when necessary.
   182   *         node_allocation_deallocation_context - context which will be passed to
   183   *                      "node_alloc_func" and "node_dealloc_func"
   184    *                     functions as parameter.
   185   *         hash_size - number of cells in hash array.
   186   *  Return value: Hash handle which should be used as parameter for other functions.
   187   *                In case of failure, HASH64_INVALID_HANDLE will be returned.
   188   */
   189  HASH64_HANDLE hash64_create_multiple_values_hash(HASH64_FUNC hash_func,
   190                  HASH64_INTERNAL_MEM_ALLOCATION_FUNC mem_alloc_func,
   191                  HASH64_INTERNAL_MEM_DEALLOCATION_FUNC mem_dealloc_func,
   192                  HASH64_NODE_ALLOCATION_FUNC node_alloc_func,
   193                  HASH64_NODE_DEALLOCATION_FUNC node_dealloc_func,
   194                  void* node_allocation_deallocation_context, UINT32 hash_size);
   195  
   196  
   197  /* Function: hash64_destroy_multiple_values_hash
   198   *  Description: This function is used in order to destroy 1-n hash
   199   *  Input: hash_handle - handle returned by "hash64_create_multiple_values_hash" function
   200   */
   201  void hash64_destroy_multiple_values_hash(HASH64_HANDLE hash_handle);
   202  
   203  
   204  /* Function: hash64_lookup_in_multiple_values_hash
   205  *  Description: This function is used in order to find the value in 1-n hash for given key.
   206   *  Input:
   207   *         hash_handle - handle returned by "hash64_create_multiple_values_hash" function
   208   *         key -
   209   *  Output:
   210   *         iter - iterator for the existing values
   211   *  Return value: TRUE in case when at least one value exists.
   212   */
   213  BOOLEAN hash64_lookup_in_multiple_values_hash(HASH64_HANDLE hash_handle,
   214                UINT64 key, HASH64_MULTIPLE_VALUES_HASH_ITERATOR* iter);
   215  
   216  
   217  /* Function: hash64_multiple_values_hash_iterator_get_next
   218   *  Description: This function is used to advance iterator to the next value
   219   *  Input:
   220   *         iter - iterator (output of "hash64_lookup_in_multiple_values_hash" function).
   221   *  Return value: iterator which points to next value. If there is no next value,
   222   *                HASH64_NULL_ITERATOR will be returned.
   223   */
   224  HASH64_MULTIPLE_VALUES_HASH_ITERATOR
   225  hash64_multiple_values_hash_iterator_get_next(HASH64_MULTIPLE_VALUES_HASH_ITERATOR iter);
   226  
   227  
   228  /* Function: hash64_multiple_values_hash_iterator_get_value
   229   *  Description: This function is used to retrieve value from iterator
   230   *  Input:
   231   *    iter - iterator (output of "hash64_lookup_in_multiple_values_hash" function).
   232   *  Return value: iterator which points to next value. If there is no next value,
   233   *    HASH64_NULL_ITERATOR will be returned.
   234   */
   235  UINT64 hash64_multiple_values_hash_iterator_get_value(HASH64_MULTIPLE_VALUES_HASH_ITERATOR iter);
   236  
   237  
   238  /* Function: hash64_insert_into_multiple_values_hash
   239   *  Description: insert the value into 1-n hash.
   240   *  Input:
   241   *         hash_handle - handle returned by "hash64_create_multiple_values_hash" function
   242   *         key -
   243   *         value -
   244   *  Return value: TRUE in case the operation is successful
   245  */
   246  BOOLEAN hash64_insert_into_multiple_values_hash(HASH64_HANDLE hash_handle,
   247                                                 UINT64 key, UINT64 value);
   248  
   249  /* Function: hash64_remove_from_multiple_values_hash
   250   *  Description: remove the value from 1-n hash.
   251   *  Input:
   252   *         hash_handle - handle returned by "hash64_lookup_in_multiple_values_hash" function
   253   *         key -
   254   *         value - value to remove
   255   *  Return value: TRUE in case the operation is successful.
   256   */
   257  BOOLEAN hash64_remove_from_multiple_values_hash(HASH64_HANDLE hash_handle,
   258                                                 UINT64 key, UINT64 value);
   259  
   260  /* Function: hash64_is_value_in_multiple_values_hash
   261   *  Description: This function is used in order to check whether some value is
   262   *               recorded for given key in 1-n hash.
   263   *  Input:
   264   *         hash_handle - handle returned by "hash64_create_multiple_values_hash" function
   265   *         key -
   266   *         value -
   267   *  Return value: TRUE in case the value exists.
   268   */
   269  BOOLEAN hash64_is_value_in_multiple_values_hash(HASH64_HANDLE hash_handle,
   270                                                 UINT64 key, UINT64 value);
   271  
   272  
   273  /* Function: hash64_remove_range_from_multiple_values_hash
   274   *  Description: remove range of values from 1-n hash.
   275   *  Input:
   276   *         hash_handle - handle returned by "hash64_create_multiple_values_hash" function
   277   *         key -
   278   *         value_from - remove all recorded values starting from this one and including it.
   279   *         value_to - remove all recorded values ending this one and including it.
   280   *  Return value: TRUE in case the operation is successful.
   281   */
   282  BOOLEAN hash64_remove_range_from_multiple_values_hash(HASH64_HANDLE hash_handle,
   283                                   UINT64 key, UINT64 value_from, UINT64 value_to);
   284  
   285  
   286  /* Function: hash64_multiple_values_is_empty
   287   *  Description: This function is used in order check whether 1-n hash is empty.
   288   *  Input:
   289   *    hash_handle - handle returned by "hash64_create_multiple_values_hash" function
   290   *  Return value: TRUE in case the hash is empty.
   291   */
   292  BOOLEAN hash64_multiple_values_is_empty(HASH64_HANDLE hash_handle);
   293  
   294  #ifdef DEBUG
   295  void hash64_print(HASH64_HANDLE hash_handle);
   296  #endif
   297  #endif