table.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /**
  2. ******************************************************************************
  3. * @file : table.h
  4. * @author : simon
  5. * @brief : Building a Hash Table -- buckets, load factors, open addressing
  6. * collision resolution, and hash functions
  7. * @attention : None
  8. * @date : 2023/8/24
  9. ******************************************************************************
  10. */
  11. #ifndef CLOX_TABLE_H
  12. #define CLOX_TABLE_H
  13. #include "common.h"
  14. #include "value.h"
  15. typedef struct {
  16. ObjString *key;
  17. Value value;
  18. } Entry;
  19. typedef struct {
  20. int count;
  21. int capacity;
  22. Entry *entries;
  23. } Table;
  24. void initTable(Table *table);
  25. void freeTable(Table *table);
  26. bool tableGet(Table *table, ObjString *key, Value *value);
  27. bool tableSet(Table *table, ObjString *key, Value value);
  28. bool tableDelete(Table *table, ObjString *key);
  29. void tableAddAll(Table *from, Table *to);
  30. /// 查找字符串
  31. /// \param table Table*
  32. /// \param chars const char*
  33. /// \param length int
  34. /// \param hash uint32_t
  35. /// \return ObjString*
  36. ObjString *tableFindString(Table *table, const char *chars, int length, uint32_t hash);
  37. #endif//CLOX_TABLE_H