perfhlib.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #pragma once
  2. /* Perfect hashing function library. Contains functions to generate perfect
  3. hashing functions
  4. * (C) Mike van Emmerik
  5. */
  6. #include <stdint.h>
  7. /* Prototypes */
  8. void hashCleanup(void); /* Frees memory allocated by hashParams() */
  9. void map(void); /* Part 1 of creating the tables */
  10. /* The application must provide these functions: */
  11. void getKey(int i, uint8_t **pKeys);/* Set *keys to point to the i+1th key */
  12. void dispKey(int i); /* Display the key */
  13. class PatternHasher
  14. {
  15. uint16_t *T1base, *T2base; /* Pointers to start of T1, T2 */
  16. int NumEntry; /* Number of entries in the hash table (# keys) */
  17. int EntryLen; /* Size (bytes) of each entry (size of keys) */
  18. int SetSize; /* Size of the char set */
  19. char SetMin; /* First char in the set */
  20. int NumVert; /* c times NumEntry */
  21. int *graphNode; /* The array of edges */
  22. int *graphNext; /* Linked list of edges */
  23. int *graphFirst;/* First edge at a vertex */
  24. public:
  25. uint16_t *readT1(void); /* Returns a pointer to the T1 table */
  26. uint16_t *readT2(void); /* Returns a pointer to the T2 table */
  27. uint16_t *readG(void); /* Returns a pointer to the g table */
  28. void init(int _NumEntry, int _EntryLen, int _SetSize, char _SetMin,int _NumVert); /* Set the parameters for the hash table */
  29. void cleanup();
  30. int hash(unsigned char *string); //!< Hash the string to an int 0 .. NUMENTRY-1
  31. };
  32. extern PatternHasher g_pattern_hasher;
  33. /* Macro reads a LH uint16_t from the image regardless of host convention */
  34. #ifndef LH
  35. #define LH(p) ((int)((uint8_t *)(p))[0] + ((int)((uint8_t *)(p))[1] << 8))
  36. #endif