Skip to content

Commit

Permalink
Merge pull request #1570 from KurtMi/opmphm_integration0
Browse files Browse the repository at this point in the history
Opmphm Integration Part 1
  • Loading branch information
markus2330 committed Aug 11, 2017
2 parents f634c5e + b38db54 commit a18716d
Show file tree
Hide file tree
Showing 15 changed files with 980 additions and 149 deletions.
64 changes: 32 additions & 32 deletions benchmarks/benchmarks.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static void fillUpWithRandomChars (char * name, size_t length, int32_t * seed, K
uint8_t ds = (*seed >> (8 * s * 2)) & 0xFF;
uint8_t dc = (*seed >> (8 * (s * 2 + 1))) & 0xFF;
// special or not
bool special = (ds % shape->special) == 0;
bool special = shape->special && (ds % shape->special) == 0;
// choose
if (special)
{
Expand Down Expand Up @@ -125,7 +125,7 @@ static void fillUpWithRandomChars (char * name, size_t length, int32_t * seed, K
* @param shape the shape of the KeySet
*
*/
static void recGenerateKeySet (Key * key, size_t * size, KeySet * out, int32_t * seed, int level, size_t initSize, KeySetShape * shape)
static void recGenerateKeySet (Key * key, size_t * size, KeySet * out, int32_t * seed, size_t level, size_t initSize, KeySetShape * shape)
{
// to restore if key already in keyset
size_t sizeBackup = *size;
Expand All @@ -147,66 +147,64 @@ static void recGenerateKeySet (Key * key, size_t * size, KeySet * out, int32_t *
fprintf (stderr, "generateKeySet: Can not add KeyBaseName %s to key %s\n", subName, keyName (key));
exit (EXIT_FAILURE);
}
// check if add possible
if (ksLookup (out, key, KDB_O_NONE))
{
// key is in out, therefore restore size and start from new
*size = sizeBackup;
keyDel (key);
recGenerateKeySet (keyBackup, size, out, seed, level, initSize, shape);
return;
}
keyDel (keyBackup);
// determine subkeys
size_t subKeys = shape->shapef (initSize, *size, level, seed);
ELEKTRA_ASSERT (subKeys <= *size, "KsShapeFunction return value > size");
ELEKTRA_ASSERT (subKeys <= *size + 1, "KsShapeFunction return value > size");
// remove costs for subkeys
if (subKeys)
{
*size -= (subKeys - 1); // the cost for one is included in the size from the parent call
if (*size && (shape->parent == 1 || (dp % shape->parent) == 0))
if (*size && shape->parent && (dp % shape->parent) == 0)
{
// counts extra so costs need to be removed
--*size;
Key * keydub = keyDup (key);
if (!keydub)
ssize_t sizeBefore = ksGetSize (out);
if (ksAppendKey (out, key) < 0)
{
fprintf (stderr, "generateKeySet: Can not dup Key %s\n", subName);
fprintf (stderr, "generateKeySet: Can not add Key %s\n", subName);
exit (EXIT_FAILURE);
}
if (ksAppendKey (out, keydub) < 0)
if (sizeBefore == ksGetSize (out))
{
fprintf (stderr, "generateKeySet: Can not add Key %s\n", subName);
exit (EXIT_FAILURE);
// key is in out, therefore restore size and start from new
*size = sizeBackup;
keyDel (key);
recGenerateKeySet (keyBackup, size, out, seed, level, initSize, shape);
return;
}
}
}
else
{
// no size decrement need because the costs where removed before
ssize_t sizeBefore = ksGetSize (out);
if (ksAppendKey (out, key) < 0)
{
fprintf (stderr, "generateKeySet: Can not add Key %s\n", subName);
exit (EXIT_FAILURE);
}
if (sizeBefore == ksGetSize (out))
{
// key is in out, therefore restore size and start from new
*size = sizeBackup;
keyDel (key);
recGenerateKeySet (keyBackup, size, out, seed, level, initSize, shape);
return;
}
}
keyDel (keyBackup);
++level;
for (size_t i = 0; i < subKeys; ++i)
{
if (i)
{
Key * keydub = keyDup (key);
if (!keydub)
{
fprintf (stderr, "generateKeySet: Can not dup Key %s\n", subName);
exit (EXIT_FAILURE);
}
recGenerateKeySet (keydub, size, out, seed, ++level, initSize, shape);
}
else
Key * keydub = keyDup (key);
if (!keydub)
{
recGenerateKeySet (key, size, out, seed, ++level, initSize, shape);
fprintf (stderr, "generateKeySet: Can not dup Key %s\n", subName);
exit (EXIT_FAILURE);
}
recGenerateKeySet (keydub, size, out, seed, level, initSize, shape);
}
keyDel (key);
}

/**
Expand Down Expand Up @@ -241,6 +239,8 @@ KeySet * generateKeySet (size_t size, int32_t * seed, KeySetShape * shape)
ELEKTRA_ASSERT (shape->maxWordLength - shape->minWordLength <= 16777215, "max world length variation exceeded 16777215");
ELEKTRA_ASSERT (shape->parent <= 127, "parent > 127");
ELEKTRA_ASSERT (shape->special <= 127, "parent > 127");
ELEKTRA_ASSERT (shape->minWordLength != 0, "minWordLength is 0");
ELEKTRA_ASSERT (shape->maxWordLength != 0, "maxWordLength is 0");
ELEKTRA_ASSERT (shape->shapef, "shape->shapef");
KeySet * out = ksNew (size, KS_END);
if (!out)
Expand Down
13 changes: 9 additions & 4 deletions benchmarks/benchmarks.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <kdbinternal.h>
#include <kdbrand.h>

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand Down Expand Up @@ -54,19 +55,21 @@ extern KeySet * large;
* Restrictions due to elektraRand:
*
* maxWordLength - minWordLength <= 16777215
* parent <= 127
* special <= 127
* 0 < maxWordLength
* 0 < minWordLength
* 0 <= parent <= 127
* 0 <= special <= 127
*
* The shapef is used to determine the number of sub Keys.
* shapef will be executed on each node in the hierarchal tree of your KeySet.
* The parameter of the shapef are the following (in order):
*
* initSize: is the maximal size of the KeySet
* size: the remaining space in the KeySet
* level: the actual level (root is 1)
* level: the actual level (root is 0)
* seed: a seed for random actions
*
* The shapef should retuen always a value >= 0 and <= size.
* The shapef should retuen always a value >= 0 and <= size + 1.
*
* Example:
* Call: generateKeySet (100,...
Expand All @@ -80,6 +83,8 @@ extern KeySet * large;
* level= 3
*
*/
extern const char * const alphabetnumbers;
extern const char * const alphabetspecial;

typedef size_t (*KsShapeFunction) (size_t, size_t, size_t, int32_t *);
typedef struct
Expand Down
Loading

0 comments on commit a18716d

Please sign in to comment.