tire.h 963 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #ifndef __L87_TIRE_H__
  2. #define __L87_TIRE_H__
  3. #include "list.h"
  4. #include <string>
  5. const int TIRE_NODE_NUMBER = 128;
  6. const int UINT_SIZE = sizeof(unsigned int);
  7. const int BITMAP_NUMBER = TIRE_NODE_NUMBER / UINT_SIZE / 8;
  8. template<typename Type,
  9. typename Container = List<Type>>
  10. class Tire {
  11. public:
  12. struct Node {
  13. Node();
  14. ~Node();
  15. Node* operator[](const int ch);
  16. Node* next[TIRE_NODE_NUMBER] { nullptr };
  17. unsigned int bitmap[BITMAP_NUMBER] = { 0 };
  18. typename Container::Node* value = nullptr;
  19. };
  20. typedef typename Container::iterator iterator;
  21. private:
  22. Node* _root = new Node();
  23. Container _container;
  24. public:
  25. Tire();
  26. ~Tire();
  27. Type& operator[](const std::string& key);
  28. iterator find(const std::string& key);
  29. iterator insert(const std::string& key, Type& value);
  30. size_t erase(const std::string& key);
  31. public:
  32. iterator begin();
  33. iterator end();
  34. iterator rbegin();
  35. iterator rend();
  36. };
  37. #include "tire.inl"
  38. #endif