]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
Use XOR, not OR to combine bits.
authorJim Meyering <jim@meyering.net>
Tue, 25 Sep 2007 19:27:14 +0000 (21:27 +0200)
committerJim Meyering <jim@meyering.net>
Tue, 25 Sep 2007 19:27:14 +0000 (21:27 +0200)
* gl/lib/hash-triple.c (triple_hash): Use XOR (^), not OR (|), to
combine the bits from hashing the name and those of the inode number.
Add a few comments and remove out-of-context ones.

ChangeLog
gl/lib/hash-triple.c

index 8fb325414710c0c239a7172dcdbc0c7724c3956e..228d26df66e8633b38ce65f985c067f91fad5d65 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2007-09-25  Jim Meyering  <jim@meyering.net>
+
+       Use XOR, not OR to combine bits.
+       * gl/lib/hash-triple.c (triple_hash): Use XOR (^), not OR (|), to
+       combine the bits from hashing the name and those of the inode number.
+       Add a few comments and remove out-of-context ones.
+
 2007-09-24  Jim Meyering  <jim@meyering.net>
 
        * NEWS: The recent rm-diagnostic fix also affects cross-partition "mv".
index dfe2a592dc7b2563e06c18e8fbe5562ce87c7c7b..74b9de80cfbbb589f2676ac8fc74f9df6ee04b8e 100644 (file)
@@ -8,27 +8,18 @@
 #include "same.h"
 #include "same-inode.h"
 
-/* Hash an F_triple.  */
+/* 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;
-
-  /* Also take the name into account, so that when moving N hard links to the
-     same file (all listed on the command line) all into the same directory,
-     we don't experience any N^2 behavior.  */
-  /* FIXME-maybe: is it worth the overhead of doing this
-     just to avoid N^2 in such an unusual case?  N would have
-     to be very large to make the N^2 factor noticable, and
-     one would probably encounter a limit on the length of
-     a command line before it became a problem.  */
   size_t tmp = hash_pjw (p->name, table_size);
 
   /* Ignoring the device number here should be fine.  */
-  return (tmp | p->st_ino) % table_size;
+  return (tmp ^ p->st_ino) % table_size;
 }
 
-/* Hash an F_triple.  */
+/* Hash an F_triple, without considering the file name.  */
 size_t
 triple_hash_no_name (void const *x, size_t table_size)
 {