Mercurial > hg > octave-nkf > gnulib-hg
changeset 9225:5a4ec2c38ec4
New module, hash-triple.
* modules/hash-triple: Define it.
* lib/hash-triple.c, lib/hash-triple.h: Implement.
author | Jim Meyering <jim@meyering.net> |
---|---|
date | Tue, 25 Sep 2007 22:11:42 +0200 |
parents | 404ee875898f |
children | b7de93942166 |
files | ChangeLog lib/hash-triple.c lib/hash-triple.h modules/hash-triple |
diffstat | 4 files changed, 119 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2007-09-27 Jim Meyering <jim@meyering.net> + + New module, hash-triple. + * modules/hash-triple: Define it. + * lib/hash-triple.c, lib/hash-triple.h: Implement. + 2007-09-25 Eric Blake <ebb9@byu.net> Fix strerror on Interix.
new file mode 100644 --- /dev/null +++ b/lib/hash-triple.c @@ -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 <config.h> + +#include "hash-triple.h" + +#include <stdlib.h> + +#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); +}
new file mode 100644 --- /dev/null +++ b/lib/hash-triple.h @@ -0,0 +1,21 @@ +#ifndef HASH_TRIPLE_H +#define HASH_TRIPLE_H + +#include <sys/types.h> +#include <sys/stat.h> +#include <stdbool.h> + +/* 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
new file mode 100644 --- /dev/null +++ b/modules/hash-triple @@ -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