Perfect hash in Scala.
        Posted  
        
            by Lukasz Lew
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Lukasz Lew
        
        
        
        Published on 2010-05-09T09:28:46Z
        Indexed on 
            2010/05/09
            9:38 UTC
        
        
        Read the original article
        Hit count: 322
        
I have some class C:
class C (...) { ... }
I want to use it to index an efficient map. The most efficient map is an Array. So I add a "global" "static" counter in companion object to give each object unique id:
object C {
  var id_counter = 0
}
In primary constructor of C, with each creation of C I want to 
remember global counter value and increase it.
Question 1: How to do it?
Now I can use id in C objects as perfect hash to index array. But array does not preserve type information like map would, that a given array is indexed by C's id.
Question 2: Is it possible to have it with type safety?
© Stack Overflow or respective owner