array_t Class Template Reference

Simple resizable container representing 1-dimensional array. More...

#include <array.hh>

List of all members.

Public Types

typedef const T * const_iterator
 Constant iterator.
typedef T * iterator
 Iterator.

Public Member Functions

 array_t (const array_t< T, Alloc > &to_copy)
 A copy constructor.
 array_t (size_int_t allocate=2, size_int_t step=2)
 A constructor.
void assign_from (const array_t< T, Alloc > &to_copy)
 Copies `to_copy' to this container.
const T & back () const
 Returns a constant reference to the last item in the container.
T & back ()
 Returns a reference to the last item in the container.
const_iterator begin () const
 Returns a constant iterator pointing to the first item of the container.
iterator begin ()
 Returns an iterator pointing to the first item of the container.
void clear ()
 Lowers the size of array to zero, but does not release allocated memory.
const_iterator end () const
iterator end ()
void extend (const size_int_t count)
 Extends the container by count members.
void extend_to (const size_int_t count)
 Extends the container to the size of `count' elements.
const T & front () const
 Returns a constant reference to the first item in the container.
T & front ()
 Returns a reference to the first item in the container.
size_int_t get_alloc_step () const
 Returns an allocation step.
size_int_t get_allocated () const
 Returns a count of items allocated in a memory of this container.
const_iterator last () const
 Returns a constant iterator pointing to the last item of the container.
iterator last ()
 Returns an iterator pointing to the last item of the container.
const T & operator[] (const size_int_t i) const
 Returns a constant reference to `i'-th item in the container.
T & operator[] (const size_int_t i)
 Returns a reference to `i'-th item in the container.
pop_back ()
 Removes the last item from the container.
void push_back (T what)
 Appends `what' to the end of the container.
void resize (const size_int_t count)
 Resizes the container to the size of `count' elements.
void set_alloc_step (const size_int_t new_alloc_step)
 Sets an alloc_step step.
void shrink_to (const size_int_t count)
 Shrinks the container to the size of `count' elements.
size_int_t size () const
 Returns a count of items stored in a container.
void swap (array_t< T, Alloc > &second)
 Swaps the containment of instance `second' and this.
 ~array_t ()
 A destructor.

Protected Attributes

T * field
 The entire field of objects stored in array_t.


Detailed Description

template<class T, T *(*)(const size_int_t count) Alloc = default_new_field_of_objects<T>>
class array_t< T, Alloc >

Simple resizable container representing 1-dimensional array.

This container implement a resizable 1-dimensional array of a choosen type. The access to the single item of an array is implemented simply using operator [].

Constraints imposed on type that can be paramater of this template: Type must not have contructor or destructor. It should be a scalar type like integer, pointer, etc.

You can do reallocation using methods resize(), shrink_to(), extend_to(), extend() or push_back().

The purpose of this container is to implement container with really fast random access times to it. The penalty for the really fast read/write operations is a possibly slow realocation. Reallocation is implemented such way that if the container has not allocated sufficiently large memory, reallocation methods resize(), extend(), extend_to() or push_back() allocate a larger piece of memory. It means that resize(), extend(), extend_to() and push_back() may have time complexity O(n), where n is a number items in an array. You can influence how often the array will be reallocated using set_alloc_step() method.

There are defined functions swap() and assign_from() to copy the contents of one instace of the container to another instance.


Member Typedef Documentation

typedef const T* const_iterator

Constant iterator.

Constant iterator - you cannot change the value to which the iterator points. Dereferencing, increasing and descresing takes time O(1) and it is really fast.

typedef T* iterator

Iterator.

Iterator. Dereferencing, increasing and descresing takes time O(1) and it is really fast.


Constructor & Destructor Documentation

array_t ( size_int_t  allocate = 2,
size_int_t  step = 2 
) [inline]

A constructor.

Parameters:
allocate = the number of items to pre-alllocate
step = the step of allocation in case of extending the container


Member Function Documentation

void assign_from ( const array_t< T, Alloc > &  to_copy  )  [inline]

Copies `to_copy' to this container.

Copies the entrire contents of one instance of container to another one.

This operation takes both memory and time O(n), where n is a number of items in to_copy instance of the container.

const_iterator begin (  )  const [inline]

Returns a constant iterator pointing to the first item of the container.

It is really fast operation running in time O(1)

iterator begin (  )  [inline]

Returns an iterator pointing to the first item of the container.

It is really fast operation running in time O(1)

Referenced by dve_explicit_system_t::get_sync_succs_internal(), and dve_transition_t::~dve_transition_t().

void clear (  )  [inline]

Lowers the size of array to zero, but does not release allocated memory.

Lowers the size of array to zero, but does not release allocated memory. It is the same as shrink_to(0).

Referenced by dve_explicit_system_t::get_async_enabled_trans_succs(), dve_prob_explicit_system_t::get_succs(), bymoc_explicit_system_t::get_succs(), dve_explicit_system_t::get_sync_enabled_trans(), dve_explicit_system_t::get_sync_succs_internal(), dve_transition_t::read(), and dve_prob_transition_t::read().

const_iterator end (  )  const [inline]

Returns a constant iterator pointing immediatelly behind the last item of the container

It is really fast operation running in time O(1)

iterator end (  )  [inline]

Returns an iterator pointing immediatelly behind the last item of the container

It is really fast operation running in time O(1)

Referenced by dve_explicit_system_t::get_sync_succs_internal(), and dve_transition_t::~dve_transition_t().

void extend ( const size_int_t  count  )  [inline]

Extends the container by count members.

Parameters:
count = the count of items we want to add to the container
Its running time is O(n), where n is a number of items stored in the container.

Referenced by dve_process_t::add_assertion(), dve_process_t::add_state(), and dve_expression_t::dve_expression_t().

void extend_to ( const size_int_t  count  )  [inline]

Extends the container to the size of `count' elements.

Warning:
Important: This method presumes, that count >= size().
Its running time is O(n), where n is a number of items stored in the container.

size_int_t get_alloc_step (  )  const [inline]

Returns an allocation step.

Returns an allocation step. Allocation step is the least step of allocation of new items (we always allocate the number of items, which is divisible by get_alloc_step())

Referenced by array_t< dve_symbol_t * >::assign_from().

size_int_t get_allocated (  )  const [inline]

Returns a count of items allocated in a memory of this container.

Returns a count of items allocated in a memory of this container. It's return value is always more or equal to return value of size()

Referenced by array_t< dve_symbol_t * >::assign_from().

const_iterator last (  )  const [inline]

Returns a constant iterator pointing to the last item of the container.

It is really fast operation running in time O(1)

iterator last (  )  [inline]

Returns an iterator pointing to the last item of the container.

It is really fast operation running in time O(1)

T pop_back (  )  [inline]

Removes the last item from the container.

Removes the last item from the container and returns its value. It doesn't relesase the memory allocated for the last item (this memory will be reused in the next push_back()) - therefore it runs in a time O(1) and it it really fast operation.

void push_back ( what  )  [inline]

void resize ( const size_int_t  count  )  [inline]

Resizes the container to the size of `count' elements.

It is implemented using shrink_to() and extend_to() methods. Therefore if count <= size() it runs in a time O(1) (it uses shrink_to() method), otherwise it runs in a time O(n) (it uses extend_to() method), where n is a number of items stored in the container.

Referenced by dve_expression_t::assign(), and prob_transition_t::set_trans_count().

void set_alloc_step ( const size_int_t  new_alloc_step  )  [inline]

Sets an alloc_step step.

Sets an allocation step. Allocation step is the least step of allocation of new items (we always allocate the number of items, which is divisible by get_alloc_step())

void shrink_to ( const size_int_t  count  )  [inline]

Shrinks the container to the size of `count' elements.

Warning:
Important: This method presumes, that count <= size().
Its running time is O(1) and it is really fast operation

void swap ( array_t< T, Alloc > &  second  )  [inline]

Swaps the containment of instance `second' and this.

Swaps the containment of instance `second' and this. On one hand (unlike assign_from()) it changes its parameter, but on the other hand it runs only in O(1) time, what is much faster than the running time of assign_from()

Referenced by dve_expression_t::swap().


The documentation for this class was generated from the following file:

Reference Manual for Library, 2006 developed in ParaDiSe laboratory, Faculty of Informatics, Masaryk University