iCoder
iCoder

Reputation: 476

Is safe to use gperf generated perfect hash function?

I'm now considering using gperf generated hash function to replace our old one, but I had no idea if it's safe or not, and will that add our maintaining cost.

The reliability and system complexity is our first consideration.

Is there someone who had used gperf generated hash function in big project?

Is safe to use it in my project?

BTW, our project is a C++ project, runs on a 64-bit Linux machine.

Thanks in advance!

Upvotes: 2

Views: 2295

Answers (2)

Damon
Damon

Reputation: 70186

gperf is known to work very well. Insofar, yes it is "safe".

Complexity is usually on the order of reading 2 characters, doing 2 table lookups, and one string compare. Reliability is 100%. If something went wrong, you get an error message, otherwise it will work.

Maintenance cost is between "low" and "non-existen", you need to figure out how to write the input file once, then run it through gperf once, and compile it. It's simple C code that every 10-20 year old compiler can grok. Call the lookup function whenever you want to lookup a value, that's all there is to do.

You'll need to run the input file through gperf again if you change it, obviously... otherwise that's just it. If your list of keys does not change, you never need to do anything again. I've used gperf in several projects to full satisfaction.

Upvotes: 3

Paul Rubel
Paul Rubel

Reputation: 27232

Never had to use the API myself, but, in this write-up, which seems to be from the late 90s, they show that GPERF has been used in TAO, gnu indent, and a handful of other applications.

It's been out for a while, and likely to be well shaken out. Here's an interesting developer works writeup.

Upvotes: 4

Related Questions