New module, hash-triple.
authorJim Meyering <jim@meyering.net>
Tue, 25 Sep 2007 20:11:42 +0000 (22:11 +0200)
committerJim Meyering <jim@meyering.net>
Thu, 27 Sep 2007 08:48:01 +0000 (10:48 +0200)
* modules/hash-triple: Define it.
* lib/hash-triple.c, lib/hash-triple.h: Implement.

ChangeLog
lib/hash-triple.c [new file with mode: 0644]
lib/hash-triple.h [new file with mode: 0644]
modules/hash-triple [new file with mode: 0644]

index 78fa16c..740ac8f 100644 (file)
--- 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.
diff --git a/lib/hash-triple.c b/lib/hash-triple.c
new file mode 100644 (file)
index 0000000..2644b5f
--- /dev/null
@@ -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);
+}
diff --git a/lib/hash-triple.h b/lib/hash-triple.h
new file mode 100644 (file)
index 0000000..7abe970
--- /dev/null
@@ -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
diff --git a/modules/hash-triple b/modules/hash-triple
new file mode 100644 (file)
index 0000000..b746d47
--- /dev/null
@@ -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