Giter Club home page Giter Club logo

perfhash's Introduction

perfhash

perfhash is a perfect hash table generator for C++ (And hopefully later other languages). It's based in part on GNU gperf's internals, but with a completely different interface and API for the generated tables. In particular, instead of a static table, it creates hash table objects so that multiple tables with the same keys can exist in the same program - one per thread, say.

Building

perfhash uses cmake. In the base perfhash directory:

$ mkdir build
$ cd build
$ cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo [OTHER OPTIONS] ../src
$ cmake --build

This creates an executable named perfhash that can be copied whereever.

Usage

Generating tables

perfhash takes an input file that is a JSON document whose layout is described below, and creates source code files containing the implementation of a perfect hash or set. Usage is simple:

$ perfhash table_description.json

All options and settings are controlled by the input file.

Using tables

perfhash can create two types of tables, corresponding roughly to std::unordered_set and std::unordered_map. The keys are always strings, the values if present are an arbitrary user-controlled type.

Sets

Maps

Table description file

The JSON file that describes the table to be created. It holds a single JSON object, with the following fields:

type

Can be either "set" or "map".

output

Controls the output language, files and language-specific options. The "language" field controls what else is present.

C++ output

For C++ output, "language" can be "c++17" or "c++14". Older versions are not currently supported.

The key "header file" names the output file (The hash table is a header-only). "class" is used to control the name of the resulting table type. For maps, "value type" is the type of the value. The optional "namespace" field puts the generated classes in the given namespace.

Example

{ "type": "map",
  "output": {
    "language": "c++14",
    "source file": "foo.cpp",
    "header file": "foo.h".
    "class": "my_map",
    "value type": "int"
    },
  "data": [
    {"key": "dog", "value":"1"},
    {"key": "cat", "value":"2"},
    {"key": "rat", "value":"3"}
    ]
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.