Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9058341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:42:05+00:00 2026-06-16T14:42:05+00:00

I have the following C code from here: http://marknelson.us/1989/10/01/lzw-data-compression/ It states that it uses

  • 0

I have the following C code from here:

http://marknelson.us/1989/10/01/lzw-data-compression/

It states that it uses a XOR hashing algorithm to avoid having to search through substring array elements and instead generate an “address” for a substring.

Then there is a hashing function, for which the line below seems to me as being the main part:

index = (hash_character << HASHING_SHIFT) ^ hash_prefix;
  • Here we have an integer value that is shifted ranging from 4 bits to the left (according to definitions of constants).

  • Then this value gets an XOR applied with another integer value.

I am pretty sure that the shifting part is just to get rid of unused bits, and then a single, simple XOR operation is being applied to a very short substring, from 12 to 16 bits; although I might be very wrong on this.

What is the name, or possible list of algorithm names, that explain this specific XOR hashing algorithm, or if possible, a list of algorithm names that are good for this substring application (like in the LZW dictionary of substrings, etc.)?





#define BITS 12                   /* Setting the number of bits to 12, 13*/
#define HASHING_SHIFT (BITS-8)    /* or 14 affects several constants.    */
#define MAX_VALUE (1 << BITS) - 1 /* Note that MS-DOS machines need to   */
#define MAX_CODE MAX_VALUE - 1    /* compile their code in large model if*/
                                  /* 14 bits are selected.               */
#if BITS == 14
  #define TABLE_SIZE 18041        /* The string table size needs to be a */
#endif                            /* prime number that is somewhat larger*/
#if BITS == 13                    /* than 2**BITS.                       */
  #define TABLE_SIZE 9029
#endif
#if BITS <= 12
  #define TABLE_SIZE 5021
#endif

……

……

……

/*
** This is the hashing routine.  It tries to find a match for the prefix+char
** string in the string table.  If it finds it, the index is returned.  If
** the string is not found, the first available index in the string table is
** returned instead.
*/

int find_match(int hash_prefix,unsigned int hash_character)
{
int index;
int offset;

  index = (hash_character << HASHING_SHIFT) ^ hash_prefix;
  if (index == 0)
    offset = 1;
  else
    offset = TABLE_SIZE - index;
  while (1)
  {
    if (code_value[index] == -1)
      return(index);
    if (prefix_code[index] == hash_prefix &&
        append_character[index] == hash_character)
      return(index);
    index -= offset;
    if (index < 0)
      index += TABLE_SIZE;
  }
}




  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T14:42:06+00:00Added an answer on June 16, 2026 at 2:42 pm

    A similar hash function was described in Bruno Preiss’ “Data Structures and Algorithms with Object-Oriented Design Patterns in Java” John Wiley & Sons, 2000

    A nice – but somewhat outdated – survey of hash function is here. The function is named “BPhash” in the survey. The LZW hash function looks very simple to me. There are probably better hash function known by now which produce less fequent clashes und thus improve the hashing efficiency/effectiveness.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been following the validation for Entry boxes from here . The code
I have the following code which i copied from here : /*************************************************************************** * _
I have the following code (I'm working from code at http://www.linuxhowtos.org/C_C++/socket.htm ) which I'm
for example i have data response from here: http://www.facebook.com/ajax/shares/view/?target_fbid=410558838979218&__a=1 there is a pattern that
I have got the following code from here to read an Excel file using
I have the following code for my .htaccess file that I've picked up from
I have the following code: from random import randint,choice add=lambda x:lambda y:x+y sub=lambda x:lambda
I have the following code: from selenium import selenium selenium = selenium(localhost, 4444, *chrome,
I have the following code (from https://github.com/timabell/PageStructureBuilder ) and the ever knowledgeable ReSharper is
I have the following code (inherited from someone): <div class=feedback>&nbsp;</div> <form onsubmit=return false autocomplete=off>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.