tire.h 830 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #ifndef __L87_TIRE_H__
  2. #define __L87_TIRE_H__
  3. #include "list.h"
  4. #include "list.cpp"
  5. #include <string>
  6. #define TIRE_NODE_NUMBER 128
  7. #define INDEX(x) ((const int)(x))
  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. typename Container::Node* _value = nullptr;
  18. };
  19. typedef typename Container::iterator iterator;
  20. private:
  21. Node _root;
  22. Container _container;
  23. public:
  24. Tire();
  25. ~Tire();
  26. Type& operator[](const std::string& key);
  27. iterator find(const std::string& key);
  28. iterator insert(const std::string& key, Type& value);
  29. iterator erase(const std::string& key);
  30. public:
  31. iterator begin();
  32. iterator end();
  33. iterator rbegin();
  34. iterator rend();
  35. };
  36. #endif