Is it possible to make a minimal perfect hash function in this situation?

前端 未结 4 731
孤独总比滥情好
孤独总比滥情好 2021-02-15 11:07

I want to create a Hash Map (or another structure, if you have any suggestions) to store key value pairs. The keys will all be inserted at once at the same time as the map is cr

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-15 11:59

    if you know the set of all possible variable names, then it would be possible to use to perfect hash the names to numbers

    but each of the hash tables would end up having the same length an example is if X and y are the names then the map would always be of length 2

    if perfect(str) turns 'x' and 'y' into 0 and 1; then the function get would be

    get(field, table) 
    {
       return table[perfect(field)];
    }
    

提交回复
热议问题