Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve PerfectHash code to avoid infinite loops. #1010

Open
etiotto opened this issue Nov 17, 2021 · 1 comment
Open

Improve PerfectHash code to avoid infinite loops. #1010

etiotto opened this issue Nov 17, 2021 · 1 comment
Assignees

Comments

@etiotto
Copy link
Collaborator

etiotto commented Nov 17, 2021

No description provided.

@AlexandreEichenberger
Copy link
Collaborator

AlexandreEichenberger commented Nov 17, 2021

See this issue for a few suggestions on how to avoid the infinite loop.

#941 (comment)

I came to realize that V and G can have different sizes: grow G to have a bigger set of hash values that then map to the V array
Or grow V with the same sized G to have more entries and thus more possibilities.

This is exemplified by the fact that the modulo in the evaluation function are separate for the Gs and the Vs, see below.

# Look up a value in the hash table, defined by G and V.
def PerfectHashLookup( G, V, key ):
    d = G[hash(0,key) % len(G)]
    if d < 0: return V[-d-1]
    return V[hash(d, key) % len(V)]

Personally, I prefer the growing of G as this is only an array of numbers, whereas V and the original keys are possibly larger data types (including int64 and strings).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants