CodeCogs - An iteractive open source Numerical library Welcome... Login
CodeCogs
shopping cart
OSXWindowsLinux
Search CodeCogs
Numerical Components

Valid RSS

Array

grid

Available under GPL (Free) and Commercial licence
get a GPL licence
COST (GBP)
this unit 1.01
sub units 0.00
add a commercial licence to your cart
0
viewed 181 times and licensed 22 times

A stl-compliant N-dimensional grid class

Controller: samtheman  Contact Controller
+View version details
Contents hide toc
buy now     get GPL     add to cart

Group Description

A N-dimensional grid class. It has the same interface and time complexity as vectors do. Having said that, construction can be slightly different and the time complexity for functions that are linear for the vector are actually O(N^dimensions) because each linear time function performs the same linear time function on each element, and so forth.
Example 1:
#include <cstdlib>
#include <iostream>
#include <stdexcept>
#include <codecogs\array\Grid.hpp>
#include <ctime>
using namespace std;
int main(int argc, char *argv[])
{
    std::vector<int> v;
    v.push_back(7); //first dimension
    v.push_back(6); //second dimension
    v.push_back(5); //third dimension
    //non-default ctor
    Grid<int, 3> g3d(v);
    Grid<int, 2> g2d(g3d.front());
    Grid<int, 1> g1d(g2d.back());
    Grid<int, 3> cube3d(3, g3d.front()); //3 in length
    //all 2d dimensions are the same as g3d.front()
    //dimension size checking
    cout << "First dimension: " << g1d.size() << endl;
    cout << "Second dimension: " << g2d.size() << endl;
    cout << "Third dimension: " << g3d.size() << endl;
    try //bounds checking
    {
        int x = g1d.at(9);
    }
    catch(const std::out_of_range& e)
    {
        cout << "Bounds checking test: " << e.what() << endl;
    }
    srand(time(NULL));
    for(int x = 0; x < 7; x++)
    {
        for(int y = 0; y < 6; y++)
        {
            for(int z = 0; z < 5; z++)
            {
                //operator[]
                //oppositly sorted
                g3d[z][y][x] = (100 - x) + (100 - y) + (100 - z);
            }
        }
    }
   cout << "Unsorted" << endl;
   //operators
   cout << (g3d[0] < g3d[1]) << endl;
   cout << (g3d[1] < g3d[0]) << endl;
   cout << (g3d[0] == g3d[0]) << endl;
   cout << (g3d[0] != g3d[0]) << endl;
   //begin/end/rbegin/rend
   sort(g3d.begin(), g3d.end());
   cout << "Sorted" << endl;
   cout << (g3d[0] < g3d[1]) << endl;
   cout << (g3d[1] < g3d[0]) << endl;
   cout << (g3d[0] == g3d[0]) << endl;
   cout << (g3d[0] != g3d[0]) << endl;
   return 0;
}
Output:
First dimension: 7
Second dimension: 6
Third dimension: 5
Bounds checking test: vector::_M_range_check
Unsorted
0
1
1
0
Sorted
1
0
1
0
Authors:
Sam Schetterer (June 2007)

Interface

#include <codecogs/array/grid.h>

class Grid
The N-dimensional grid class
std::vector<...>elems
The elements in the array
typedefstd::vector<...>container
The container used to hold elements
typedefGrid<...>my_type
The type of the Grid
intN
The size of the dimension
typedefGrid<...>value_type
The type held in the dimension
typedef typename container::iteratoriterator
The type of iterator to be used to iterator over the values in the dimension
typedef typename container::const_iteratorconst_iterator
The type of const_iterator to be used to iterator over the values in the dimension
typedefstd::reverse_iterator<iterator>reverse_iterator
The reverse iterator
typedefstd::reverse_iterator<...>const_reverse_iterator
The reverse const_iterator
typedef typename container::pointerpointer
The pointer type to elements in the dimension
typedef typename container::const_pointerconst_pointer
The const pointer type to elements in the dimension
typedefvalue_type &reference
The reference type to elements in the dimension
typedefvalue_type &const_reference[const]
The const reference type to elements in the dimension
typedef allocallocator_type
The allocator type for elements in the dimension(will only be used for the 1-dimensional grid)
typedef typename container::size_typesize_type
The size type used to reference elements in the dimension
typedef typename container::difference_typedifference_type
The difference type between pointers
[constructor]Grid ()
Constructs an empty grid
[constructor]Grid (size_type length)
Constructs a grid of length length
[constructor]Grid (size_type length, const value_type& val)
Constructs a grid of length with default value val
[constructor]Grid (const my_type& a)
Copy constructor
template<...> explicitGrid (const Container& c)
Constructs a grid using sizes for each dimension specified in c. The first object in c is the size of the first dimension, and so forth
iteratorbegin ()
Returns the iterator at the begining of the dimension
const_iteratorbegin ()
Returns the const iterator at the beginning of the dimension
iteratorend ()
Returns the iterator one element past the end of the dimension
const_iteratorend ()
Returns the const iterator one element past the end of the dimension
reverse_iteratorrbegin ()
Returns the reverse iterator at the beginning of the dimension
const_reverse_iteratorrbegin ()
Returns the const reverse iterator at the beginning of the dimension
reverse_iteratorrend ()
Returns the reverse iterator at the end of the dimension
const_reverse_iteratorrend ()
Returns the const reverse iterator at the end of the dimension
reference*operator (size_type i)
Returns a reference to the ith element in the dimension. Bounds are not checked
const_reference*operator (size_type i)
Return a const reference to the ith element in the dimension. Bounds are not checked
referencefront ()
Returns a reference first element in the dimension
const_referencefront ()
Returns a const reference to the first element in the dimension
referenceback ()
Returns a reference to the last element in the dimension
const_referenceback ()
Returns a const reference to the last element in the dimension
referenceat (size_type loc)
Returns a reference to the loc-the element in the dimension. Bounds are checked, and an out_of_range exception is thrown when loc is out of bounds
const_referenceat (size_type loc)
Returns a const reference to the loc-the element in the dimension. Bounds are checked, and an out_of_range exception is thrown when loc is out of bounds
size_typesize ()
Returns the size of the dimension
boolempty ()
Returns whether the dimension is empty or not. A dimension can be empty but have non-zero capacity
size_typemax_size ()
Returns the maximum amount of elements in the dimension
voidswap (my_type& a)
Swaps the dimension with another dimension
my_type &operator= (const my_type& a)
Sets the dimension equal to another dimension
template<...> voidassign (Itit first, Itit last)
voidassign (size_type number, const value_type& val)
voidinsert (iterator position, size_type number, const value_type& val)
iteratorinsert (iterator position, const value_type& val)
template<...> voidinsert (iterator position, Itit first, Itit last)
iteratorerase (iterator position)
iteratorerase (iterator first, iterator last)
voidclear ()
voidresize (size_type length, value_type val = value_type())
voidpush_back (const value_type& val)
voidpop_back ()
size_typecapacity ()
voidreserve (size_type num)
template<...> bool operator== (const Grid<T, dimensions, alloc>& a, const Grid<T, dimensions, alloc>& b)[inline]
Element-by-element comparison functions
template<...> bool operator!= (const Grid<T, dimensions, alloc>& a, const Grid<T, dimensions, alloc>& b)[inline]
template<...> bool operator< (const Grid<T, dimensions, alloc>& a, const Grid<T, dimensions, alloc>& b)[inline]
template<...> bool operator> (const Grid<T, dimensions, alloc>& a, const Grid<T, dimensions, alloc>& b)[inline]
template<...> bool operator>= (const Grid<T, dimensions, alloc>& a, const Grid<T, dimensions, alloc>& b)[inline]
template<...> bool operator<= (const Grid<T, dimensions, alloc>& a, const Grid<T, dimensions, alloc>& b)[inline]
class Grid<T, 1, alloc>
The specialization for the Grid of the first dimension
std::vector<T, alloc>elems
typedefstd::vector<T, alloc>container
allocAlloc
typedefGrid<...>my_type
intN
typedef Tvalue_type
typedef typename container::iteratoriterator
typedef typename container::const_iteratorconst_iterator
typedefstd::reverse_iterator<iterator>reverse_iterator
typedefstd::reverse_iterator<...>const_reverse_iterator
typedef typename alloc::pointerpointer
typedef typename alloc::const_pointerconst_pointer
typedef typename alloc::referencereference
typedef typename alloc::const_referenceconst_reference
typedef allocallocator_type
typedef typename container::size_typesize_type
typedef typename container::difference_typedifference_type
Gridunknown ()
Gridunknown (const my_type& a)
template<...>Grid (const Container& c)
iteratorbegin ()
const_iteratorbegin ()
iteratorend ()
const_iteratorend ()
reverse_iteratorrbegin ()
const_reverse_iteratorrbegin ()
reverse_iteratorrend ()
const_reverse_iteratorrend ()
reference*operator (size_type i)
const_reference*operator (size_type i)
referencefront ()
const_referencefront ()
referenceback ()
const_referenceback ()
referenceat (size_type loc)
const_referenceat (size_type loc)
size_typesize ()
boolempty ()
size_typemax_size ()
voidswap (my_type& a)
my_type &operator= (const my_type& a)
template<...> voidassign (Itit first, Itit last)
voidassign (size_type number, const value_type& val)
voidinsert (iterator position, size_type number, const value_type& val)
iteratorinsert (iterator position, const value_type& val)
template<...> voidinsert (iterator position, Itit first, Itit last)
iteratorerase (iterator position)
iteratorerase (iterator first, iterator last)
voidclear ()
voidresize (size_type length, value_type val = value_type())
voidpush_back (const value_type& val)
voidpop_back ()
size_typecapacity ()
voidreserve (size_type num)

Class Documentation

 
Grid
A N-dimensional grid class.
Source Code:

To view or download source code you need either a GPL or Commercial Licence.

buy now     get GPL     add to cart

Not a member, then Register with CodeCogs. Already a Member, then Login.

Members of Grid

 
voidresizesize_typelength
value_typeval = value_type() )
Parameters:
valDefault value = value_type()


 
Grid<T, 1, alloc>
Authors:
Sam Schetterer (June 2007)
Source Code:

To view or download source code you need either a GPL or Commercial Licence.

buy now     get GPL     add to cart

Not a member, then Register with CodeCogs. Already a Member, then Login.

Members of Grid<T, 1, alloc>

 
voidresizesize_typelength
value_typeval = value_type() )
Parameters:
valDefault value = value_type()


Function Documentation

 
template<...> booloperator==const Grid<...>& a
const Grid<...>& b )[inline]
Authors:
Sam Schetterer (June 2007)
Source Code:

To view or download source code you need either a GPL or Commercial Licence.

buy now     get GPL     add to cart

Not a member, then Register with CodeCogs. Already a Member, then Login.


Page Comments

Format Excel Equations

  You must login to leave a messge


Last Modified: 27 Nov 07 @ 23:39     Page Rendered: 2010-03-10 14:35:41

Valid CSS!   Valid XHTML 1.0 Transitional