Add readsig tool to build

As requested in #22
This commit is contained in:
nemerle 2016-05-19 20:03:49 +02:00
parent cd6797499f
commit ccc8cc526b
4 changed files with 174 additions and 187 deletions

View File

@ -1,3 +1,4 @@
#pragma once
#include <stdint.h> #include <stdint.h>
/** Perfect hashing function library. Contains functions to generate perfect /** Perfect hashing function library. Contains functions to generate perfect
hashing functions */ hashing functions */

View File

@ -1,2 +1,3 @@
add_subdirectory(makedsig) add_subdirectory(makedsig)
add_subdirectory(readsig)
add_subdirectory(parsehdr) add_subdirectory(parsehdr)

View File

@ -0,0 +1,4 @@
add_executable(readsig readsig.cpp)
target_link_libraries(readsig dcc_hash)
qt5_use_modules(readsig Core)

View File

@ -1,34 +1,33 @@
/* Quick program to read the output from makedsig */ /* Quick program to read the output from makedsig */
#include <stdio.h> #include <stdio.h>
#include <io.h>
#include <stdlib.h> #include <stdlib.h>
#include <memory.h> #include <memory.h>
#include <string.h> #include <string.h>
#include "perfhlib.h" #include "perfhlib.h"
/* statics */ /* statics */
byte buf[100]; uint8_t buf[100];
int numKeys; /* Number of hash table entries (keys) */ int numKeys; /* Number of hash table entries (keys) */
int numVert; /* Number of vertices in the graph (also size of g[]) */ int numVert; /* Number of vertices in the graph (also size of g[]) */
int PatLen; /* Size of the keys (pattern length) */ int PatLen; /* Size of the keys (pattern length) */
int SymLen; /* Max size of the symbols, including null */ int SymLen; /* Max size of the symbols, including null */
FILE *f; /* File being read */ FILE *f; /* File being read */
static word *T1base, *T2base; /* Pointers to start of T1, T2 */
static word *g; /* g[] */
/* prototypes */ /* prototypes */
void grab(int n); void grab(int n);
word readFileShort(void); uint16_t readFileShort(void);
void cleanup(void); void cleanup(void);
static bool bDispAll = FALSE; static bool bDispAll = false;
static PerfectHash g_pattern_hasher;
static uint16_t *T1base;
static uint16_t *T2base;
static uint16_t *g;
void int main(int argc, char *argv[])
main(int argc, char *argv[])
{ {
word w, len; uint16_t w, len;
int h, i, j; int h, i, j;
long filePos; long filePos;
@ -44,7 +43,7 @@ main(int argc, char *argv[])
if (strcmp(argv[i], "-a") == 0) if (strcmp(argv[i], "-a") == 0)
{ {
i++; i++;
bDispAll = TRUE; bDispAll = true;
} }
if ((f = fopen(argv[i], "rb")) == NULL) if ((f = fopen(argv[i], "rb")) == NULL)
{ {
@ -65,18 +64,16 @@ main(int argc, char *argv[])
SymLen = readFileShort(); SymLen = readFileShort();
/* Initialise the perfhlib stuff. Also allocates T1, T2, g, etc */ /* Initialise the perfhlib stuff. Also allocates T1, T2, g, etc */
hashParams( /* Set the parameters for the hash table */ g_pattern_hasher.setHashParams(
numKeys, /* The number of symbols */ numKeys, /* The number of symbols */
PatLen, /* The length of the pattern to be hashed */ PatLen, /* The length of the pattern to be hashed */
256, /* The character set of the pattern (0-FF) */ 256, /* The character set of the pattern (0-FF) */
0, /* Minimum pattern character value */ 0, /* Minimum pattern character value */
numVert); /* Specifies C, the sparseness of the graph. numVert); /* Specifies C, the sparseness of the graph. See Czech, Havas and Majewski for details */
See Czech, Havas and Majewski for details
*/
T1base = readT1(); T1base = g_pattern_hasher.readT1();
T2base = readT2(); T2base = g_pattern_hasher.readT2();
g = readG(); g = g_pattern_hasher.readG();
/* Read T1 and T2 tables */ /* Read T1 and T2 tables */
grab(2); grab(2);
@ -85,7 +82,7 @@ main(int argc, char *argv[])
printf("Expected 'T1'\n"); printf("Expected 'T1'\n");
exit(3); exit(3);
} }
len = PatLen * 256 * sizeof(word); len = PatLen * 256 * sizeof(uint16_t);
w = readFileShort(); w = readFileShort();
if (w != len) if (w != len)
{ {
@ -123,7 +120,7 @@ main(int argc, char *argv[])
printf("Expected 'gg'\n"); printf("Expected 'gg'\n");
exit(3); exit(3);
} }
len = numVert * sizeof(word); len = numVert * sizeof(uint16_t);
w = readFileShort(); w = readFileShort();
if (w != len) if (w != len)
{ {
@ -145,7 +142,7 @@ main(int argc, char *argv[])
exit(3); exit(3);
} }
w = readFileShort(); w = readFileShort();
if (w != numKeys * (SymLen + PatLen + sizeof(word))) if (w != numKeys * (SymLen + PatLen + sizeof(uint16_t)))
{ {
printf("Problem with size of hash table: file %d, calc %d\n", w, len); printf("Problem with size of hash table: file %d, calc %d\n", w, len);
exit(6); exit(6);
@ -153,8 +150,7 @@ main(int argc, char *argv[])
if (bDispAll) if (bDispAll)
{ {
fseek(f, 0, SEEK_CUR); /* Needed due to bug in MS fread()! */ filePos = ftell(f);
filePos = _lseek(fileno(f), 0, SEEK_CUR);
for (i=0; i < numKeys; i++) for (i=0; i < numKeys; i++)
{ {
grab(SymLen + PatLen); grab(SymLen + PatLen);
@ -175,17 +171,16 @@ main(int argc, char *argv[])
{ {
grab(SymLen + PatLen); grab(SymLen + PatLen);
h = hash(&buf[SymLen]); h = g_pattern_hasher.hash(&buf[SymLen]);
if (h != i) if (h != i)
{ {
printf("Symbol %16s (index %3d) hashed to %d\n", printf("Symbol %16s (index %3d) hashed to %d\n", buf, i, h);
buf, i, h);
} }
} }
printf("Done!\n"); printf("Done!\n");
fclose(f); fclose(f);
return 0;
} }
@ -207,10 +202,9 @@ void grab(int n)
} }
} }
word uint16_t readFileShort(void)
readFileShort(void)
{ {
byte b1, b2; uint8_t b1, b2;
if (fread(&b1, 1, 1, f) != 1) if (fread(&b1, 1, 1, f) != 1)
{ {
@ -224,16 +218,3 @@ readFileShort(void)
} }
return (b2 << 8) + b1; return (b2 << 8) + b1;
} }
/* Following two functions not needed unless creating tables */
void getKey(int i, byte **keys)
{
}
/* Display key i */
void
dispKey(int i)
{
}