search_hash.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright (c) 2009 Openmoko Inc.
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef SEARCH_HASH_H
  18. #define SEARCH_HASH_H
  19. #include <inttypes.h>
  20. #include "bigram.h"
  21. #define MAX_SEARCH_HASH_TABLE_ENTRIES (4 * 256 * 1024)
  22. #define MAX_SEARCH_HASH_KEY (256 * 1024)
  23. #define MAX_SEARCH_STRING_HASHED_LEN 15
  24. #define MAX_SEARCH_STRING_ALL_HASHED_LEN 5
  25. #define SEARCH_HASH_SEQUENTIAL_SEARCH_THRESHOLD 64
  26. typedef struct _search_hash_table {
  27. uint32_t offset_fnd; // offset to pedia.fnd for the search title hashed
  28. uint32_t next_entry_idx; // byte 1: length of hash string byte 2~4: index (of struct hash_table array) of the next entry with the same hash key
  29. } SEARCH_HASH_TABLE;
  30. typedef struct _search_hash_string {
  31. char str[MAX_SEARCH_STRING_HASHED_LEN + 1];
  32. } SEARCH_HASH_STRING;
  33. #ifdef WIKIPCF
  34. void create_search_hash(const char *filename);
  35. long add_search_hash(char *sSearchString, int len, long offset_fnd);
  36. void save_search_hash(void);
  37. #else
  38. void init_search_hash(void);
  39. int copy_fnd_to_buf(long offset, char *buf, int len);
  40. int copy_str_to_buf(long offset, char *buf, int len);
  41. long get_search_hash_offset_fnd(char *sSearchString, int len);
  42. #endif
  43. #endif