range_run.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. ==============================================================================*/
  6. #if !defined(BOOST_SPIRIT_RANGE_RUN_MAY_16_2006_0801_PM)
  7. #define BOOST_SPIRIT_RANGE_RUN_MAY_16_2006_0801_PM
  8. #if defined(_MSC_VER)
  9. #pragma once
  10. #endif
  11. #include <boost/spirit/home/support/char_set/range.hpp>
  12. #include <vector>
  13. namespace boost { namespace spirit { namespace support { namespace detail
  14. {
  15. ///////////////////////////////////////////////////////////////////////////
  16. // range_run
  17. //
  18. // An implementation of a sparse bit (boolean) set. The set uses
  19. // a sorted vector of disjoint ranges. This class implements the
  20. // bare minimum essentials from which the full range of set
  21. // operators can be implemented. The set is constructed from
  22. // ranges. Internally, adjacent or overlapping ranges are
  23. // coalesced.
  24. //
  25. // range_runs are very space-economical in situations where there
  26. // are lots of ranges and a few individual disjoint values.
  27. // Searching is O(log n) where n is the number of ranges.
  28. //
  29. // { Low level interface }
  30. ///////////////////////////////////////////////////////////////////////////
  31. template <typename Char>
  32. class range_run
  33. {
  34. public:
  35. typedef range<Char> range_type;
  36. typedef std::vector<range_type> storage_type;
  37. void swap(range_run& other);
  38. bool test(Char v) const;
  39. void set(range_type const& range);
  40. void clear(range_type const& range);
  41. void clear();
  42. private:
  43. storage_type run;
  44. };
  45. }}}}
  46. #include <boost/spirit/home/support/char_set/range_run_impl.hpp>
  47. #endif