LCOV - code coverage report
Current view: top level - external/hash - ptr_set.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 2 2 100.0 %
Date: 2016-11-30 13:12:14 Functions: 4 11 36.4 %
Branches: 0 2 0.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * Creates a set of stored pointers by using the pointer itself as key.
       3                 :            :  *
       4                 :            :  * (void *)0 (HT_MISSING) cannot be stored.
       5                 :            :  * (void *)1 (HT_DELETED) also cannot be stored.
       6                 :            :  *
       7                 :            :  * ht_item, ht_key, ht_key_len, and ht_match are required.
       8                 :            :  *
       9                 :            :  * In this case HT_HASH_FUNCTION is also required because
      10                 :            :  * we do not read the content of the key but use the pointer
      11                 :            :  * itself as a key. The default behavior would crash.
      12                 :            :  *
      13                 :            :  * Only one hash table can be defined in a single compilation unit
      14                 :            :  * because of static function names in the generic implementation.
      15                 :            :  */
      16                 :            : 
      17                 :            : #include "ptr_set.h"
      18                 :            : 
      19                 :            : static inline size_t ptr_set_hash_function(const void *s, size_t len);
      20                 :            : #define HT_HASH_FUNCTION ptr_set_hash_function
      21                 :            : 
      22                 :            : #define HT_LOAD_FACTOR 0.7
      23                 :            : #include "hash_table_def.h"
      24         [ #  # ]:       1306 : DEFINE_HASH_TABLE(ptr_set)
      25                 :            : 
      26                 :            : #if defined(PTR_SET_RH)
      27                 :            : #include "hash_table_impl_rh.h"
      28                 :            : #elif defined(PTR_SET_SRH)
      29                 :            : #include "hash_table_impl_srh.h"
      30                 :            : #else
      31                 :            : #include "hash_table_impl.h"
      32                 :            : #endif
      33                 :            : 
      34                 :            : static inline const void *ht_key(ht_item_t x)
      35                 :            : {
      36                 :            :     return (const void *)x;
      37                 :            : }
      38                 :            : 
      39                 :            : static inline size_t ht_key_len(ht_item_t x)
      40                 :            : {
      41                 :            :     return sizeof(x);
      42                 :            : }
      43                 :            : 
      44                 :            : static inline int ht_match(const void *key, size_t len, ht_item_t x)
      45                 :            : {
      46                 :            :     (void)len;
      47                 :        462 :     return (size_t)key == (size_t)x;
      48                 :            : }
      49                 :            : 
      50                 :            : static inline size_t ptr_set_hash_function(const void *s, size_t len)
      51                 :            : {
      52                 :            : #if defined (PTR_SET_PTR_HASH)
      53                 :            :     /* Murmur hash like finalization step. */
      54                 :            :     return ht_ptr_hash_function(s, len);
      55                 :            : #elif defined (PTR_SET_INT_HASH)
      56                 :            :     /* Knuths multiplication. */
      57                 :            :     return ht_int_hash_function(s, len);
      58                 :            : #else
      59                 :            :     (void)len;
      60                 :            :     return ht_default_hash_function(&s, sizeof(char *));
      61                 :            : #endif
      62                 :            : }

Generated by: LCOV version 1.12