LCOV - code coverage report
Current view: top level - lib - hash-triple.c (source / functions) Hit Total Coverage
Test: coreutils.info Lines: 16 20 80.0 %
Date: 2018-01-30 Functions: 4 5 80.0 %

          Line data    Source code
       1             : /* Hash functions for file-related triples: name, device, inode.
       2             :    Copyright (C) 2007 Free Software Foundation, Inc.
       3             : 
       4             :    This program is free software: you can redistribute it and/or modify
       5             :    it under the terms of the GNU General Public License as published by
       6             :    the Free Software Foundation; either version 3 of the License, or
       7             :    (at your option) any later version.
       8             : 
       9             :    This program is distributed in the hope that it will be useful,
      10             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      11             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12             :    GNU General Public License for more details.
      13             : 
      14             :    You should have received a copy of the GNU General Public License
      15             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
      16             : 
      17             : /* written by Jim Meyering */
      18             : 
      19             : #include <config.h>
      20             : 
      21             : #include "hash-triple.h"
      22             : 
      23             : #include <stdlib.h>
      24             : #include <string.h>
      25             : 
      26             : #include "hash-pjw.h"
      27             : #include "same.h"
      28             : #include "same-inode.h"
      29             : 
      30             : #define STREQ(a, b) (strcmp ((a), (b)) == 0)
      31             : 
      32             : /* Hash an F_triple, and *do* consider the file name.  */
      33             : size_t
      34           5 : triple_hash (void const *x, size_t table_size)
      35             : {
      36           5 :   struct F_triple const *p = x;
      37           5 :   size_t tmp = hash_pjw (p->name, table_size);
      38             : 
      39             :   /* Ignoring the device number here should be fine.  */
      40           5 :   return (tmp ^ p->st_ino) % table_size;
      41             : }
      42             : 
      43             : /* Hash an F_triple, without considering the file name.  */
      44             : size_t
      45          21 : triple_hash_no_name (void const *x, size_t table_size)
      46             : {
      47          21 :   struct F_triple const *p = x;
      48             : 
      49             :   /* Ignoring the device number here should be fine.  */
      50          21 :   return p->st_ino % table_size;
      51             : }
      52             : 
      53             : /* Compare two F_triple structs.  */
      54             : bool
      55           1 : triple_compare (void const *x, void const *y)
      56             : {
      57           1 :   struct F_triple const *a = x;
      58           1 :   struct F_triple const *b = y;
      59           1 :   return (SAME_INODE (*a, *b) && same_name (a->name, b->name)) ? true : false;
      60             : }
      61             : 
      62             : bool
      63           0 : triple_compare_ino_str (void const *x, void const *y)
      64             : {
      65           0 :   struct F_triple const *a = x;
      66           0 :   struct F_triple const *b = y;
      67           0 :   return (SAME_INODE (*a, *b) && STREQ (a->name, b->name)) ? true : false;
      68             : }
      69             : 
      70             : /* Free an F_triple.  */
      71             : void
      72           2 : triple_free (void *x)
      73             : {
      74           2 :   struct F_triple *a = x;
      75           2 :   free (a->name);
      76           2 :   free (a);
      77           2 : }

Generated by: LCOV version 1.10