PREV INDEX NEXT

Author: Stan Eisenstat
Subject: Re: [Cs323] Hash Function clarifications
Date: Tuesday, 03 Nov 2020, 08:12:00


    > Message Posted By: Unknown
    >
    > 1. What is CHAR_BIT? Is it the last bit in the value of CHAR?

CHAR_BIT is the number of bits in a char, which is
defined in <limits.h>.
=====

    > 2. Not sure if I am missing something, but why does SIZE need to be odd?
    > How can we guarantee that the number of chains is odd? Can't it be 0 if
    > there are no hash collisions?

For the hash function given in the specification, an odd
SIZE generally yields a more uniform distribution of the
items among chains than an even one.

The number of chains is a parameter, not a function of
the items added to the hash table.
=====

    > 3. Is the value returned by the hash function guaranteed to be less than
    > the size of the table? If not, does this mean we need another mod by the
    > size of the table to use it as an index?


As you can see by examining the expression

  (((unsigned long)(PREF) << CHAR_BIT) | (unsigned)(CHAR)) % SIZE

its value must be nonnegative and less than SIZE.

--Stan-
PREV INDEX NEXT