| Elektra 0.11.0

Functions | Variables
opmphmpredictor.c File Reference

The Order Preserving Minimal Perfect Hash Map Predictor. More...

`#include <kdbassert.h>`
`#include <kdbhelper.h>`
`#include <kdblogger.h>`
`#include <kdbopmphmpredictor.h>`
`#include <kdbprivate.h>`
`#include <stdlib.h>`
`#include <string.h>`

## Functions
size_t | opmphmPredictorWorthOpmphm (size_t n)
| Heuristic function above the OPMPHM usage is worth.
void | opmphmPredictorIncCountOpmphm (OpmphmPredictor *op)
| Increases the counter when the OPMPHM was used for the ksLookup (...) .
int | opmphmPredictorIncCountBinarySearch (OpmphmPredictor *op, size_t n)
| Increases the counter when the Binary Search was used for the ksLookup (...) .
int | opmphmPredictor (OpmphmPredictor *op, size_t n)
| Predictcs at the first ksLookup (...) after a KeySet changed if it will be worth using the OPMPHM.
OpmphmPredictor * | opmphmPredictorNew (void)
| Allocates and initializes the OpmphmPredictor.
void | opmphmPredictorCopy (OpmphmPredictor *dest, OpmphmPredictor *source)
| Make a copy of the OpmphmPredictor.
void | opmphmPredictorDel (OpmphmPredictor *op)
| Deletes the OpmphmPredictor.

## Variables
const uint16_t | opmphmPredictorHistoryMask = 0x1FF
| The benchmarked and evaluated values of the predictors configuration.
const size_t | opmphmPredictorActionLimit = 599
| The opmphmPredictorActionLimit define the minimum KeySet size necessary for predictor actions.

## Detailed Description

The Order Preserving Minimal Perfect Hash Map Predictor.

Copyright
  BSD License (see LICENSE.md or https://www.libelektra.org)

## Function Documentation

## ◆ opmphmPredictor()

int opmphmPredictor | ( | OpmphmPredictor * | op,
|  | size_t | n
| ) |  |

Predictcs at the first ksLookup (...) after a KeySet changed if it will be worth using the OPMPHM.

Predictor functions.

Uses the opmphmPredictorWorthOpmphm (...) to check if the previous sequence of ksLookup (...) invocations without alteration was worth using the OPMPHM. Updates the state with the predictionAutomata and the worth information of the previous history. Alters the history with the worth information and makes the prediction for the next sequence of ksLookup (...) invocations.

Parameters

  op | the Predictor
  n | the number of elements in the KeySet

Return values

  1 | it is worth using the OPMPHM
  0 | it is not worth using the OPMPHM

## ◆ opmphmPredictorCopy()

void opmphmPredictorCopy | ( | OpmphmPredictor * | dest,
|  | OpmphmPredictor * | source
| ) |  |

Make a copy of the OpmphmPredictor.

Parameters

  source | the OpmphmPredictor source
  dest | the OpmphmPredictor destination

## ◆ opmphmPredictorDel()

void opmphmPredictorDel | ( | OpmphmPredictor * | op | ) |

Deletes the OpmphmPredictor.

Clears and frees all memory in OpmphmPredictor.

Parameters

  op | the OpmphmPredictor

## ◆ opmphmPredictorIncCountBinarySearch()

int opmphmPredictorIncCountBinarySearch | ( | OpmphmPredictor * | op,
|  | size_t | n
| ) |  |
| inline

Increases the counter when the Binary Search was used for the ksLookup (...) .

Prevents also an endless Binary Search usage by a simple heuristic.

Parameters

  op | the Predictor
  n | the number of elements in the KeySet

Return values

  1 | it is worth using the OPMPHM
  0 | it is not worth using the OPMPHM

## ◆ opmphmPredictorIncCountOpmphm()

void opmphmPredictorIncCountOpmphm | ( | OpmphmPredictor * | op | ) |
| inline

Increases the counter when the OPMPHM was used for the ksLookup (...) .

Parameters

  op | the Predictor

## ◆ opmphmPredictorNew()

OpmphmPredictor * opmphmPredictorNew | ( | void |  | ) |

Allocates and initializes the OpmphmPredictor.

Basic functions.

Reserves for all possible values of opmphmPredictorHistoryMask two bits to store all 4 states of the Prediction Automata A2. Sets the initial state to 0.

Return values

  OpmphmPredictor | * success
  NULL | memory error

## ◆ opmphmPredictorWorthOpmphm()

size_t opmphmPredictorWorthOpmphm | ( | size_t | n | ) |
| inline

Heuristic function above the OPMPHM usage is worth.

Heuristic function.

This easy and fast computable heuristic function tells how many ksLookup (...) invocations without alteration of the KeySet need to be made to justify the OPMPHM usage. This heuristic function is developed and measured by benchmarks.

Parameters

  n | the number of elements in the KeySet

Return values

  size_t | the heuristic value

## Variable Documentation

## ◆ opmphmPredictorHistoryMask

const uint16_t opmphmPredictorHistoryMask = 0x1FF

The benchmarked and evaluated values of the predictors configuration.

Order Preserving Minimal Perfect Hash Map Predictor.