font_mph-tmpl.c 1005 B

1234567891011121314151617181920212223242526272829303132333435
  1. /* adapted from utils/perfect_hash/example1-C/states-tmpl.c */
  2. #include <rtthread.h>
  3. #include <string.h>
  4. static const rt_uint32_t T1[] = { $S1 };
  5. static const rt_uint32_t T2[] = { $S2 };
  6. static const rt_uint16_t G[] = { $G };
  7. static rt_uint32_t hash_g(const rt_uint16_t key, const rt_uint32_t *T)
  8. {
  9. rt_uint32_t sum = (T[0] * (key & 0xFF) + T[1] * (key >> 8)) % $NG;
  10. return G[sum % $NG];
  11. }
  12. static rt_uint32_t perfect_hash(const rt_uint16_t key)
  13. {
  14. return (hash_g(key, T1) + hash_g(key, T2)) % $NG;
  15. }
  16. rt_uint32_t rtgui_font_mph${height}(const rt_uint16_t key)
  17. {
  18. rt_uint32_t hash_value = perfect_hash(key);
  19. /*rt_kprintf("hash 0x7684 is %d", perfect_hash(0x7684));*/
  20. /*RT_ASSERT(K[hash_value] == key);*/
  21. /* NOTE: we trust you will not feed invalid data into me. So there is no
  22. * more sanity check which will consume more flash and memory. */
  23. if (hash_value < $NK)
  24. return hash_value;
  25. return -1;
  26. }
  27. const unsigned char hz${height}_font[] = { $font_data };