Use Bob Jenkins lookup3 hash instead of FNV.
[pspp-builds.git] / src / data / value.c
index 49555d9a4ea3b11ce15149ebdca388722af6dcb4..180f1b6d1e064d8195fda7f033bf72ecb3cccfd6 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2009 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
@@ -20,6 +20,7 @@
 #include <data/val-type.h>
 #include <libpspp/hash.h>
 #include <libpspp/str.h>
+#include "variable.h"
 
 #include "xalloc.h"
 
@@ -46,34 +47,25 @@ value_create (int width)
    Only the short string portion of longer strings are
    compared. */
 int
-compare_values (const union value *a, const union value *b, int width)
+compare_values_short (const void *a_, const void *b_, const void *var_) 
 {
-  return (width == 0
-          ? (a->f < b->f ? -1 : a->f > b->f)
-          : memcmp (a->s, b->s, MIN (MAX_SHORT_STRING, width)));
+  const union value *a = a_;
+  const union value *b = b_;
+  const struct variable *var = var_;
+  int width = var_get_width (var);
+  return value_compare_3way (a, b, MIN (width, MAX_SHORT_STRING));
 }
 
+
 /* Create a hash of V, which has the given WIDTH.
    Only the short string portion of a longer string is hashed. */
 unsigned
-hash_value (const union value *v, int width)
-{
-  return (width == 0
-          ? hsh_hash_double (v->f)
-          : hsh_hash_bytes (v->s, MIN (MAX_SHORT_STRING, width)));
-}
-
-
-int
-compare_ptr_values (const union value **v1, const union value **v2, int width)
-{
-  return compare_values (*v1, *v2, width);
-}
-
-unsigned
-hash_ptr_value (const union value **v, int width)
+hash_value_short (const void *v_, const void *var_)
 {
-  return hash_value (*v, width);
+  const union value *v = v_;
+  const struct variable *var = var_;
+  int width = var_get_width (var);
+  return width == 0 ? hash_double (v->f, 0) : hash_bytes (v->s, width, 0);
 }
 
 
@@ -127,3 +119,13 @@ value_resize (union value *value, int old_width, int new_width)
   if (new_width > old_width)
     memset (&value->s[old_width], ' ', new_width - old_width);
 }
+
+/* Compares A and B, which both have the given WIDTH, and returns
+   a strcmp()-type result. */
+int
+value_compare_3way (const union value *a, const union value *b, int width)
+{
+  return (width == 0
+          ? (a->f < b->f ? -1 : a->f > b->f)
+          : memcmp (a->s, b->s, width));
+}