# HG changeset patch # User Jim Meyering # Date 1190751102 -7200 # Node ID 5a4ec2c38ec483a61fadc571b43f238fd75498df # Parent 404ee875898f632895f0ad8b782bdd6971083311 New module, hash-triple. * modules/hash-triple: Define it. * lib/hash-triple.c, lib/hash-triple.h: Implement. diff -r 404ee875898f -r 5a4ec2c38ec4 ChangeLog --- a/ChangeLog Tue Sep 25 10:40:16 2007 -0600 +++ b/ChangeLog Tue Sep 25 22:11:42 2007 +0200 @@ -1,3 +1,9 @@ +2007-09-27 Jim Meyering + + New module, hash-triple. + * modules/hash-triple: Define it. + * lib/hash-triple.c, lib/hash-triple.h: Implement. + 2007-09-25 Eric Blake Fix strerror on Interix. diff -r 404ee875898f -r 5a4ec2c38ec4 lib/hash-triple.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/hash-triple.c Tue Sep 25 22:11:42 2007 +0200 @@ -0,0 +1,67 @@ +/* Hash functions for file-related triples: name, device, inode. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* written by Jim Meyering */ + +#include + +#include "hash-triple.h" + +#include + +#include "hash-pjw.h" +#include "same.h" +#include "same-inode.h" + +/* Hash an F_triple, and *do* consider the file name. */ +size_t +triple_hash (void const *x, size_t table_size) +{ + struct F_triple const *p = x; + size_t tmp = hash_pjw (p->name, table_size); + + /* Ignoring the device number here should be fine. */ + return (tmp ^ p->st_ino) % table_size; +} + +/* Hash an F_triple, without considering the file name. */ +size_t +triple_hash_no_name (void const *x, size_t table_size) +{ + struct F_triple const *p = x; + + /* Ignoring the device number here should be fine. */ + return p->st_ino % table_size; +} + +/* Compare two F_triple structs. */ +bool +triple_compare (void const *x, void const *y) +{ + struct F_triple const *a = x; + struct F_triple const *b = y; + return (SAME_INODE (*a, *b) && same_name (a->name, b->name)) ? true : false; +} + +/* Free an F_triple. */ +void +triple_free (void *x) +{ + struct F_triple *a = x; + free (a->name); + free (a); +} diff -r 404ee875898f -r 5a4ec2c38ec4 lib/hash-triple.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/hash-triple.h Tue Sep 25 22:11:42 2007 +0200 @@ -0,0 +1,21 @@ +#ifndef HASH_TRIPLE_H +#define HASH_TRIPLE_H + +#include +#include +#include + +/* Describe a just-created or just-renamed destination file. */ +struct F_triple +{ + char *name; + ino_t st_ino; + dev_t st_dev; +}; + +extern size_t triple_hash (void const *x, size_t table_size); +extern size_t triple_hash_no_name (void const *x, size_t table_size); +extern bool triple_compare (void const *x, void const *y); +extern void triple_free (void *x); + +#endif diff -r 404ee875898f -r 5a4ec2c38ec4 modules/hash-triple --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/modules/hash-triple Tue Sep 25 22:11:42 2007 +0200 @@ -0,0 +1,25 @@ +Description: +Hash functions for file-related triples: name, device, inode. + +Files: +lib/hash-triple.c +lib/hash-triple.h + +Depends-on: +hash-pjw +same +same-inode + +configure.ac: + +Makefile.am: +lib_SOURCES += hash-triple.c + +Include: +"hash-triple.h" + +License: +GPL + +Maintainer: +Jim Meyering