tire.h 964 B

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