Skip to content

Latest commit

 

History

History
46 lines (31 loc) · 1009 Bytes

README.md

File metadata and controls

46 lines (31 loc) · 1009 Bytes

mph

Minimal Perfect Hashing

Based on the article Throw away the keys: Easy, Minimal Perfect Hashing.

Install

  • lix install gh:skial/mph

Example

package ;

import hash.*;

class Entry {

    public static function main() {
        var map = ['a'=>'A', 'b'=>'B', 'cCCCC'=>'C'];
        var hash = new Mph();
        var table = hash.build(map, Mph.HashString, 3);
        
        for (key in map.keys()) {
            trace( 'Looking up the key `$key` => `${map.get(key)}` in `table`, which is ' + hash.get(table, key, Mph.HashString) );
        }

        // Accessing a non-existent key, depending on platform, 
        // will result in an unexpected error or a false result.
        try {
            trace( hash.get(table, 'c', Mph.HashString) );

        } catch (e:Any) {
            trace( e );

        }
    }

}

Notes

Help from: - perfect - mph