X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftinfo%2Fmake_hash.c;h=9980279b2d216568f78d2a67b748bbb209362636;hp=906dfafa29fa12128c9b30e56b93bd1fadf86ec0;hb=81304798ee736c467839c779c9ca5dca48db7bea;hpb=5f288254c618ae86f3811f2797e4d942061c9101 diff --git a/ncurses/tinfo/make_hash.c b/ncurses/tinfo/make_hash.c index 906dfafa..9980279b 100644 --- a/ncurses/tinfo/make_hash.c +++ b/ncurses/tinfo/make_hash.c @@ -1,5 +1,6 @@ /**************************************************************************** - * Copyright (c) 1998-2018,2019 Free Software Foundation, Inc. * + * Copyright 2018-2019,2020 Thomas E. Dickey * + * Copyright 2009-2013,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -43,7 +44,7 @@ #include -MODULE_ID("$Id: make_hash.c,v 1.29 2019/10/19 21:02:19 tom Exp $") +MODULE_ID("$Id: make_hash.c,v 1.33 2020/02/02 23:34:34 tom Exp $") /* * _nc_make_hash_table() @@ -89,7 +90,7 @@ strmalloc(char *s) * * Computes the hashing function on the given string. * - * The current hash function is the sum of each consectutive pair + * The current hash function is the sum of each consecutive pair * of characters, taken as two-byte integers, mod HASHTABSIZE. * */ @@ -100,13 +101,15 @@ hash_function(const char *string) long sum = 0; while (*string) { - sum += (long) (*string + (*(string + 1) << 8)); + sum += (long) (UChar(*string) + (UChar(*(string + 1)) << 8)); string++; } return (int) (sum % HASHTABSIZE); } +#define UNUSED -1 + static void _nc_make_hash_table(struct user_table_entry *table, HashValue * hash_table, @@ -117,7 +120,7 @@ _nc_make_hash_table(struct user_table_entry *table, int collisions = 0; for (i = 0; i < HASHTABSIZE; i++) { - hash_table[i] = -1; + hash_table[i] = UNUSED; } for (i = 0; i < tablesize; i++) { hashvalue = hash_function(table[i].ute_name); @@ -125,8 +128,9 @@ _nc_make_hash_table(struct user_table_entry *table, if (hash_table[hashvalue] >= 0) collisions++; - if (hash_table[hashvalue] != 0) + if (hash_table[hashvalue] != UNUSED) { table[i].ute_link = hash_table[hashvalue]; + } hash_table[hashvalue] = (HashValue) i; }