kwlookup.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*-------------------------------------------------------------------------
  2. *
  3. * kwlookup.h
  4. * Key word lookup for PostgreSQL
  5. *
  6. *
  7. * Portions Copyright (c) 1996-2022, PostgreSQL Global Development Group
  8. * Portions Copyright (c) 1994, Regents of the University of California
  9. *
  10. * src/include/common/kwlookup.h
  11. *
  12. *-------------------------------------------------------------------------
  13. */
  14. #ifndef KWLOOKUP_H
  15. #define KWLOOKUP_H
  16. /* Hash function used by ScanKeywordLookup */
  17. typedef int (*ScanKeywordHashFunc) (const void *key, size_t keylen);
  18. /*
  19. * This struct contains the data needed by ScanKeywordLookup to perform a
  20. * search within a set of keywords. The contents are typically generated by
  21. * src/tools/gen_keywordlist.pl from a header containing PG_KEYWORD macros.
  22. */
  23. typedef struct ScanKeywordList
  24. {
  25. const char *kw_string; /* all keywords in order, separated by \0 */
  26. const uint16 *kw_offsets; /* offsets to the start of each keyword */
  27. ScanKeywordHashFunc hash; /* perfect hash function for keywords */
  28. int num_keywords; /* number of keywords */
  29. int max_kw_len; /* length of longest keyword */
  30. } ScanKeywordList;
  31. extern int ScanKeywordLookup(const char *text, const ScanKeywordList *keywords);
  32. /* Code that wants to retrieve the text of the N'th keyword should use this. */
  33. static inline const char *
  34. GetScanKeyword(int n, const ScanKeywordList *keywords)
  35. {
  36. return keywords->kw_string + keywords->kw_offsets[n];
  37. }
  38. #endif /* KWLOOKUP_H */