From: Bruno Haible Date: Wed, 30 Apr 2025 10:28:42 +0000 (+0200) Subject: Rename module hashcode-string to hashcode-string2. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=a7785e699ab31dc0d2a51b8dbdedde4e82389201;p=gnulib.git Rename module hashcode-string to hashcode-string2. * lib/hashcode-string2.h: Renamed from lib/hashcode-string.h. * lib/hashcode-string2.c: Renamed from lib/hashcode-string.c. * modules/hashcode-string2: Renamed from modules/hashcode-string. * MODULES.html.sh: Update. * top/maint.mk: Update. * lib/hash-pjw.h: Update. * modules/hash-pjw: Update. * lib/hashcode-named-file.c: Update. * modules/hashcode-named-file (Depends-on): Update. * tests/test-hash.c: Update. * modules/hash-tests (Depends-on): Update. --- diff --git a/ChangeLog b/ChangeLog index 4d3ba4d7b8..8d8567413b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2025-04-30 Bruno Haible + + Rename module hashcode-string to hashcode-string2. + * lib/hashcode-string2.h: Renamed from lib/hashcode-string.h. + * lib/hashcode-string2.c: Renamed from lib/hashcode-string.c. + * modules/hashcode-string2: Renamed from modules/hashcode-string. + * MODULES.html.sh: Update. + * top/maint.mk: Update. + * lib/hash-pjw.h: Update. + * modules/hash-pjw: Update. + * lib/hashcode-named-file.c: Update. + * modules/hashcode-named-file (Depends-on): Update. + * tests/test-hash.c: Update. + * modules/hash-tests (Depends-on): Update. + 2025-04-30 Bruno Haible clean-temp: Fix link error (regression yesterday). diff --git a/MODULES.html.sh b/MODULES.html.sh index baee4f95fd..d57d76531e 100755 --- a/MODULES.html.sh +++ b/MODULES.html.sh @@ -2095,7 +2095,7 @@ func_all_modules () func_module obstack func_module obstack-printf func_module obstack-printf-posix - func_module hashcode-string + func_module hashcode-string2 func_module hashcode-mem func_module hash func_module hamt diff --git a/lib/hash-pjw.h b/lib/hash-pjw.h index 14af42a891..0b143f2934 100644 --- a/lib/hash-pjw.h +++ b/lib/hash-pjw.h @@ -14,8 +14,8 @@ You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ -#include "hashcode-string.h" +#include "hashcode-string2.h" #if __GNUC__ || (__clang_major__ >= 4) -# warning "The include file hash-pjw.h is deprecated. Use hashcode-string.h instead." +# warning "The include file hash-pjw.h is deprecated. Use hashcode-string2.h instead." #endif diff --git a/lib/hashcode-named-file.c b/lib/hashcode-named-file.c index a488147edd..1611cb5138 100644 --- a/lib/hashcode-named-file.c +++ b/lib/hashcode-named-file.c @@ -24,7 +24,7 @@ #include #include -#include "hashcode-string.h" +#include "hashcode-string2.h" #include "same-inode.h" #define STREQ(a, b) (strcmp (a, b) == 0) diff --git a/lib/hashcode-string.c b/lib/hashcode-string.c deleted file mode 100644 index 6943d7b17b..0000000000 --- a/lib/hashcode-string.c +++ /dev/null @@ -1,41 +0,0 @@ -/* hashcode-string.c -- compute a hash value from a NUL-terminated string. - - Copyright (C) 2001, 2003, 2006, 2009-2025 Free Software Foundation, Inc. - - This file is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 2.1 of the - License, or (at your option) any later version. - - This file 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 Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . */ - -#include - -/* Specification. */ -#include "hashcode-string.h" - -#include - -#define SIZE_BITS (sizeof (size_t) * CHAR_BIT) - -/* A hash function for NUL-terminated char* strings using - the method described by Bruno Haible. - See https://www.haible.de/bruno/hashfunc.html. */ - -size_t -hash_pjw (const void *x, size_t tablesize) -{ - const char *s; - size_t h = 0; - - for (s = x; *s; s++) - h = *s + ((h << 9) | (h >> (SIZE_BITS - 9))); - - return h % tablesize; -} diff --git a/lib/hashcode-string.h b/lib/hashcode-string.h deleted file mode 100644 index af99f4e74c..0000000000 --- a/lib/hashcode-string.h +++ /dev/null @@ -1,38 +0,0 @@ -/* hashcode-string.h -- declaration for a simple hash function - Copyright (C) 2001, 2003, 2009-2025 Free Software Foundation, Inc. - - This file is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 2.1 of the - License, or (at your option) any later version. - - This file 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 Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see . */ - -/* This file uses _GL_ATTRIBUTE_PURE. */ -#if !_GL_CONFIG_H_INCLUDED - #error "Please include config.h first." -#endif - -#include - -#ifdef __cplusplus -extern "C" { -#endif - - -/* Compute a hash code for a NUL-terminated string starting at X, - and return the hash code modulo TABLESIZE. - The result is platform dependent: it depends on the size of the 'size_t' - type and on the signedness of the 'char' type. */ -extern size_t hash_pjw (void const *x, size_t tablesize) _GL_ATTRIBUTE_PURE; - - -#ifdef __cplusplus -} -#endif diff --git a/lib/hashcode-string2.c b/lib/hashcode-string2.c new file mode 100644 index 0000000000..5a44762723 --- /dev/null +++ b/lib/hashcode-string2.c @@ -0,0 +1,41 @@ +/* hashcode-string2.c -- compute a hash value from a NUL-terminated string. + + Copyright (C) 2001, 2003, 2006, 2009-2025 Free Software Foundation, Inc. + + This file is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or (at your option) any later version. + + This file 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include "hashcode-string2.h" + +#include + +#define SIZE_BITS (sizeof (size_t) * CHAR_BIT) + +/* A hash function for NUL-terminated char* strings using + the method described by Bruno Haible. + See https://www.haible.de/bruno/hashfunc.html. */ + +size_t +hash_pjw (const void *x, size_t tablesize) +{ + const char *s; + size_t h = 0; + + for (s = x; *s; s++) + h = *s + ((h << 9) | (h >> (SIZE_BITS - 9))); + + return h % tablesize; +} diff --git a/lib/hashcode-string2.h b/lib/hashcode-string2.h new file mode 100644 index 0000000000..9c10951222 --- /dev/null +++ b/lib/hashcode-string2.h @@ -0,0 +1,38 @@ +/* hashcode-string2.h -- declaration for a simple hash function + Copyright (C) 2001, 2003, 2009-2025 Free Software Foundation, Inc. + + This file is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or (at your option) any later version. + + This file 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public License + along with this program. If not, see . */ + +/* This file uses _GL_ATTRIBUTE_PURE. */ +#if !_GL_CONFIG_H_INCLUDED + #error "Please include config.h first." +#endif + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/* Compute a hash code for a NUL-terminated string starting at X, + and return the hash code modulo TABLESIZE. + The result is platform dependent: it depends on the size of the 'size_t' + type and on the signedness of the 'char' type. */ +extern size_t hash_pjw (void const *x, size_t tablesize) _GL_ATTRIBUTE_PURE; + + +#ifdef __cplusplus +} +#endif diff --git a/modules/hash-pjw b/modules/hash-pjw index 56193fa2d1..d1905ed4f2 100644 --- a/modules/hash-pjw +++ b/modules/hash-pjw @@ -5,19 +5,19 @@ Status: deprecated Notice: -This module is deprecated. Use the module 'hashcode-string' instead. +This module is deprecated. Use the module 'hashcode-string2' instead. Files: Depends-on: -hashcode-string +hashcode-string2 configure.ac: Makefile.am: Include: -"hashcode-string.h" +"hashcode-string2.h" License: LGPLv2+ diff --git a/modules/hash-tests b/modules/hash-tests index c9593f347d..b9f99d9900 100644 --- a/modules/hash-tests +++ b/modules/hash-tests @@ -3,7 +3,7 @@ tests/test-hash.c tests/macros.h Depends-on: -hashcode-string +hashcode-string2 inttostr bool diff --git a/modules/hashcode-named-file b/modules/hashcode-named-file index bdc68502f8..7e5eebf763 100644 --- a/modules/hashcode-named-file +++ b/modules/hashcode-named-file @@ -7,7 +7,7 @@ lib/hashcode-file.h lib/hash-triple.h Depends-on: -hashcode-string +hashcode-string2 same-inode bool diff --git a/modules/hashcode-string b/modules/hashcode-string deleted file mode 100644 index a9484514db..0000000000 --- a/modules/hashcode-string +++ /dev/null @@ -1,23 +0,0 @@ -Description: -Compute a hash value for a NUL-terminated string. - -Files: -lib/hashcode-string.h -lib/hashcode-string.c -lib/hash-pjw.h - -Depends-on: - -configure.ac: - -Makefile.am: -lib_SOURCES += hashcode-string.h hashcode-string.c - -Include: -"hashcode-string.h" - -License: -LGPLv2+ - -Maintainer: -Jim Meyering diff --git a/modules/hashcode-string2 b/modules/hashcode-string2 new file mode 100644 index 0000000000..7a26702471 --- /dev/null +++ b/modules/hashcode-string2 @@ -0,0 +1,23 @@ +Description: +Compute a hash value for a NUL-terminated string. + +Files: +lib/hashcode-string2.h +lib/hashcode-string2.c +lib/hash-pjw.h + +Depends-on: + +configure.ac: + +Makefile.am: +lib_SOURCES += hashcode-string2.h hashcode-string2.c + +Include: +"hashcode-string2.h" + +License: +LGPLv2+ + +Maintainer: +Jim Meyering diff --git a/tests/test-hash.c b/tests/test-hash.c index e7735684be..78a1bff37c 100644 --- a/tests/test-hash.c +++ b/tests/test-hash.c @@ -18,7 +18,7 @@ #include #include "hash.h" -#include "hashcode-string.h" +#include "hashcode-string2.h" #include "inttostr.h" #include diff --git a/top/maint.mk b/top/maint.mk index a5392fc938..e03e887cba 100644 --- a/top/maint.mk +++ b/top/maint.mk @@ -728,8 +728,8 @@ sc_prohibit_posixver_without_use: sc_prohibit_same_without_use: @h='same.h' re='\