tire.h 791 B

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