Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think there are a couple of questions here</p> <h2>Is it safe to use floats as keys to a hash table?</h2> <p>Yes. I can't think of a language right now where <code>floats</code> do not fit the requirements needed for a key in a hash table (typically stable hash code and equality semantics)</p> <h2>Is it OK to have a hash table with lots of keys?</h2> <p>Depends on how many. If the number of keys is so great it causes the table to expand past the allowable memory size then certainly no as it will cause out of memory situations. It's really impossible to answer this part of the question without more context. Likely you're the only one who will be able to answer it.</p> <h2>Does the precision of <code>float</code> make it any worse than other types like <code>int</code>?</h2> <p>This is implementation specific but I believe in OCaml a <code>float</code> has double precision (8 bytes). So asking if the precision makes it invalid as a key is the equivalent of asking is the C# <code>long</code> type unsuitable as a hash table key. They both have the same number of possible values (they're both 8 bytes). I would certainly say <code>long</code> is a valid key type (used it often and there is nothing wrong with it). </p> <p>I think the real question is are you irresponsibly creating instances of the <code>float</code> to use as a key. </p> <h2>If I'm running out of memory with a hash table will a binary tree be any better?</h2> <p>Possibly but not by a lot. There is overhead involved with both binary trees and hash tables. For hashtables it's typically the unused buckets and the next pointers in the lists inside the buckets. For a binary tree every element in the tree has 2 extra pieces of overhead (the left and right pointer). If you're running out of memory I'm not sure swvitching to a binary tree will be significantly better. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload