Thread: How to write a pro-grade hashtable

  1. #1
    Old Fashioned
    Join Date
    Nov 2016
    Posts
    137

    Question How to write a pro-grade hashtable

    I see all of these basic hashtable tutorials where they just calculate a hash with a modulus and they say "dont use this in production."

    So my question is... What CAN I use in production? What does a good hash table configuration look like? Which operators should I use besides modulus the hash table size?
    If I was homeless and jobless, I would take my laptop to a wifi source and write C for fun all day. It's the same thing I enjoy now!

  2. #2
    Registered User
    Join Date
    Apr 2017
    Location
    Iran
    Posts
    138
    Quote Originally Posted by Asymptotic View Post
    I see all of these basic hashtable tutorials where they just calculate a hash with a modulus and they say "dont use this in production."

    So my question is... What CAN I use in production? What does a good hash table configuration look like? Which operators should I use besides modulus the hash table size?
    Hash table in chess programming link.

  3. #3
    Registered User
    Join Date
    Apr 2017
    Location
    Iran
    Posts
    138
    Quote Originally Posted by Asymptotic View Post
    I see all of these basic hashtable tutorials where they just calculate a hash with a modulus and they say "dont use this in production."

    So my question is... What CAN I use in production? What does a good hash table configuration look like? Which operators should I use besides modulus the hash table size?
    Let me tell an example based on my experience. Suppose you want to solve Sudoku. At one stage you want to know whether two Sudoku states are equal or not. Some Sudoku cells are bounded (they have a single value). Some unbounded (they can have multiple values).

    The obvious way to compare two Sudoku states is to compare all 9*9 cells. If all bounded cells are equal, they are the same states.

    This method is OK, but there is a drawback here. The number of comparisons is high.

    Here is a trick. Let me introduce a new variable for each Sudoku state. I define it as number of bounded cells. Let us call this hash.

    There are two possibilities when comparing hashes of two Sudoku states. If hashes are different then the two states are different. Think of saved computations here. Otherwise in case of hashes being equal, I need a full states comparison.

    Conclusion : At the cost of tiny extra memory and tiny extra computation, Huge gain in resources is achieved.

  4. #4
    Old Fashioned
    Join Date
    Nov 2016
    Posts
    137
    @ordak honestly you might like to check into Microsoft Z3 SMT Solver. It sounds like you could use this for your Sudoku work as well. I've used it to solve other constrained problems. Check out this page: Z3Py Guide But note that Z3 also has a C API: Z3: C API
    If I was homeless and jobless, I would take my laptop to a wifi source and write C for fun all day. It's the same thing I enjoy now!

  5. #5
    Registered User
    Join Date
    Apr 2017
    Location
    Iran
    Posts
    138
    Quote Originally Posted by Asymptotic View Post
    @ordak honestly you might like to check into Microsoft Z3 SMT Solver. It sounds like you could use this for your Sudoku work as well. I've used it to solve other constrained problems. Check out this page: Z3Py Guide But note that Z3 also has a C API: Z3: C API
    I already have a Sudoku solver here.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hashtable
    By RyanC in forum C Programming
    Replies: 4
    Last Post: 05-23-2019, 06:45 PM
  2. Hashtable in C programming
    By RyanC in forum C Programming
    Replies: 3
    Last Post: 12-03-2018, 06:04 AM
  3. Replies: 2
    Last Post: 01-29-2011, 12:58 PM
  4. Hashtable v.s. Dictionary
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 06-06-2008, 02:09 AM
  5. HashTable help?
    By -EquinoX- in forum C Programming
    Replies: 66
    Last Post: 03-31-2008, 12:15 AM

Tags for this Thread