codekingpro/portable-devtools
114k
1/*-------------------------------------------------------------------------2 *3 * kwlookup.h4 * Key word lookup for PostgreSQL5 *6 *7 * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group8 * Portions Copyright (c) 1994, Regents of the University of California9 *10 * src/include/common/kwlookup.h11 *12 *-------------------------------------------------------------------------13 */14#ifndef KWLOOKUP_H15#define KWLOOKUP_H16 17/* Hash function used by ScanKeywordLookup */18typedef int (*ScanKeywordHashFunc) (const void *key, size_t keylen);19 20/*21 * This struct contains the data needed by ScanKeywordLookup to perform a22 * search within a set of keywords. The contents are typically generated by23 * src/tools/gen_keywordlist.pl from a header containing PG_KEYWORD macros.24 */25typedef struct ScanKeywordList26{27 const char *kw_string; /* all keywords in order, separated by \0 */28 const uint16 *kw_offsets; /* offsets to the start of each keyword */29 ScanKeywordHashFunc hash; /* perfect hash function for keywords */30 int num_keywords; /* number of keywords */31 int max_kw_len; /* length of longest keyword */32} ScanKeywordList;33 34 35extern int ScanKeywordLookup(const char *str, const ScanKeywordList *keywords);36 37/* Code that wants to retrieve the text of the N'th keyword should use this. */38static inline const char *39GetScanKeyword(int n, const ScanKeywordList *keywords)40{41 return keywords->kw_string + keywords->kw_offsets[n];42}43 44#endif /* KWLOOKUP_H */45 