Home » Projects » JPerf

JPerf - A Java Perfect Hash Generator

Introduction

Perfect hashing is much written about but less often used. The principle is to reduce the average constant overhead of a hash table by precomputing a hash function which is optimal for the key set. Other advantages include a reduction in memory usage. % Finding such a hash function is hard, especially in the general case and these run-time savings come at a cost of increased map creation time.

Users of the C programming language will no doubt be familiar with gperf, a much more complete tool which generates C source for a perfect hash. Douglas C Schmidt's paper was an invaluable resource in the creation of this library.

Using the Library

The structure of this library is as follows: The user creates a PerfectMapGenerator, adds the key-value pairs to it, and then asks the generator to create a Map. The returned Map is a perfect hash for the given keys and values. The JPerf library offers a general purpose PerfectMapGenerator for Java Objects, and a special case for Java Strings.

Future versions of this library may also generate source code, or even a Class at runtime using the asm library. However, the nature of Java is such that these options may not offer much (if any) runtime performance benefit over the generated Map, and the only cost saved is that of generation time (which may be significant).

License

The license is GPL-2. Subversion access is available on request. Less restrictive licenses are freely available on request, but please ask, because I want people to use this software, but I'm curious to know who is using it and for what purpose.

Documentation

Requirements

Download

Subversion

svn co https://svn.anarres.org/svn/repos/code/java/jperf/trunk/

Older versions

See also