PFUNC 1.0
|
00001 #ifndef PFUNC_SPACE_1D_HPP 00002 #define PFUNC_SPACE_1D_HPP 00003 00004 #include <cassert> 00005 #include <utility> 00006 #include <vector> 00007 00008 namespace pfunc { 00013 struct space_1D { 00014 public: 00015 typedef std::vector<space_1D> subspace_container; 00016 static size_t base_case_size; 00018 const static size_t arity = 2; 00019 const static size_t dimension = 1; 00021 private: 00022 size_t space_begin; 00023 size_t space_end; 00024 bool splittable; 00026 public: 00032 space_1D (const size_t space_begin, const size_t space_end) : 00033 space_begin(space_begin), space_end(space_end), 00034 splittable ((space_end-space_begin)>base_case_size) {} 00035 00040 size_t begin () const { return space_begin; } 00041 00046 size_t end () const { return space_end; } 00047 00052 bool can_split () const { return splittable; } 00053 00060 subspace_container split () const { 00061 // Make sure that the space is splittable 00062 assert (splittable); 00063 00064 // Get a vector to store the subspaces 00065 subspace_container subspaces; 00066 00067 const size_t split_point = space_begin + (space_end-space_begin)/2; 00068 const size_t left_space_begin = space_begin; 00069 const size_t left_space_end = split_point; 00070 const size_t right_space_begin = split_point; 00071 const size_t right_space_end = space_end; 00072 00073 subspaces.push_back (space_1D (left_space_begin, left_space_end)); 00074 subspaces.push_back (space_1D (right_space_begin, right_space_end)); 00075 00076 return subspaces; 00077 } 00078 00082 void pretty_print () const { 00083 std::cout << "[" << begin() << "," << end() << ") -- " 00084 << ((splittable) ? "splittable" : "NOT splittable") << std::endl; 00085 } 00086 }; 00087 00091 size_t pfunc::space_1D::base_case_size = 100; 00092 00093 } // end namespace pfunc 00094 00095 #endif // PFUNC_SPACE_1D_HPP