blocked_range.h Source File

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# blocked_range.h

    00001 /*
    00002     Copyright 2005-2011 Intel Corporation.  All Rights Reserved.
    00003
    00004     The source code contained or described herein and all documents related
    00005     to the source code ("Material") are owned by Intel Corporation or its
    00006     suppliers or licensors.  Title to the Material remains with Intel
    00007     Corporation or its suppliers and licensors.  The Material is protected
    00008     by worldwide copyright laws and treaty provisions.  No part of the
    00009     Material may be used, copied, reproduced, modified, published, uploaded,
    00010     posted, transmitted, distributed, or disclosed in any way without
    00011     Intel's prior express written permission.
    00012
    00013     No license under any patent, copyright, trade secret or other
    00014     intellectual property right is granted to or conferred upon you by
    00015     disclosure or delivery of the Materials, either expressly, by
    00016     implication, inducement, estoppel or otherwise.  Any license under such
    00017     intellectual property rights must be express and approved by Intel in
    00018     writing.
    00019 */
    00020
    00021 #ifndef __TBB_blocked_range_H
    00022 #define __TBB_blocked_range_H
    00023
    00024 #include "tbb_stddef.h"
    00025
    00026 namespace tbb {
    00027
    00037
    00038
    00039 template<typename Value>
    00040 class blocked_range {
    00041 public:
    00043
    00045     typedef Value const_iterator;
    00046
    00048     typedef std::size_t size_type;
    00049
    00051
    00052     blocked_range() : my_end(), my_begin() {}
    00053
    00055     blocked_range( Value begin_, Value end_, size_type grainsize_=1 ) :
    00056         my_end(end_), my_begin(begin_), my_grainsize(grainsize_)
    00057     {
    00058         __TBB_ASSERT( my_grainsize>0, "grainsize must be positive" );
    00059     }
    00060
    00062     const_iterator begin() const {return my_begin;}
    00063
    00065     const_iterator end() const {return my_end;}
    00066
    00068
    00069     size_type size() const {
    00070         __TBB_ASSERT( !(end()<begin()), "size() unspecified if end()<begin()" );
    00071         return size_type(my_end-my_begin);
    00072     }
    00073
    00075     size_type grainsize() const {return my_grainsize;}
    00076
    00077     //------------------------------------------------------------------------
    00078     // Methods that implement Range concept
    00079     //------------------------------------------------------------------------
    00080
    00082     bool empty() const {return !(my_begin<my_end);}
    00083
    00085
    00086     bool is_divisible() const {return my_grainsize<size();}
    00087
    00089
    00091     blocked_range( blocked_range& r, split ) :
    00092         my_end(r.my_end),
    00093         my_begin(do_split(r)),
    00094         my_grainsize(r.my_grainsize)
    00095     {}
    00096
    00097 private:
    00099     Value my_end;
    00100     Value my_begin;
    00101     size_type my_grainsize;
    00102
    00104
    00105     static Value do_split( blocked_range& r ) {
    00106         __TBB_ASSERT( r.is_divisible(), "cannot split blocked_range that is not divisible" );
    00107         Value middle = r.my_begin + (r.my_end-r.my_begin)/2u;
    00108         r.my_end = middle;
    00109         return middle;
    00110     }
    00111
    00112     template<typename RowValue, typename ColValue>
    00113     friend class blocked_range2d;
    00114
    00115     template<typename RowValue, typename ColValue, typename PageValue>
    00116     friend class blocked_range3d;
    00117 };
    00118
    00119 } // namespace tbb
    00120
    00121 #endif /* __TBB_blocked_range_H */

Copyright © 2005-2011 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.