# FoundationClasses
TKernel
NCollection

# NCollection_SparseArray< TheItemType > Class Template Reference

`#include <NCollection_SparseArray.hxx>`

Inheritance diagram for NCollection_SparseArray< TheItemType >:

[legend]

## Public Member Functions

| NCollection_SparseArray (Standard_Size theIncrement)
| Constructor; accepts size of blocks.
NCollection_SparseArray & | Assign (const NCollection_SparseArray &theOther)
| Explicit assignment operator.
void | Exchange (NCollection_SparseArray &theOther)
| Exchange the data of two arrays; can be used primarily to move contents of theOther into the new array in a fast way (without creation of duplicated data).
virtual | ~NCollection_SparseArray ()
| Destructor.
Array-like interface (in addition to inherited methods)
const TheItemType & | Value (const Standard_Integer theIndex) const
| Direct const access to the item.
const TheItemType & | operator() (const Standard_Integer theIndex) const
| Const access to the item - operator().
TheItemType & | ChangeValue (const Standard_Integer theIndex)
| Modification access to the item.
TheItemType & | operator() (const Standard_Integer theIndex)
| Access to the item - operator().
TheItemType & | SetValue (const Standard_Integer theIndex, const TheItemType &theValue)
| Set a value at specified index method.
DataMap-like interface
Standard_Size | Extent () const
| Returns number of items in the array.
Standard_Boolean | IsEmpty () const
| Returns True if array is empty.
const TheItemType & | Find (const Standard_Integer theIndex) const
| Direct const access to the item.
TheItemType & | ChangeFind (const Standard_Integer theIndex)
| Modification access to the item; allocates space if necessary and marks the item as defined.
TheItemType & | Bind (const Standard_Integer theIndex, const TheItemType &theValue)
| Set a value as explicit method.
Standard_Boolean | IsBound (const Standard_Integer theIndex) const
| Returns True if the item is defined.
Standard_Boolean | UnBind (const Standard_Integer theIndex)
| Remove the item from array.

## Private Member Functions

virtual void | createItem (Standard_Address theAddress, Standard_Address theOther)
| Create new item at the specified address with copy constructor from existing item.
virtual void | destroyItem (Standard_Address theAddress)
| Call destructor to the item at given address.
virtual void | copyItem (Standard_Address theAddress, Standard_Address theOther)
| Call assignment operator to the item.

## Data Structures

class | ConstIterator
class | Iterator

## Detailed Description

### template<class TheItemType>
class NCollection_SparseArray< TheItemType >

Dynamically resizable sparse array of objects

This class is similar to NCollection_Vector: it works like virtually unlimited array of items accessible by index; however unlike simple Vector it distinguishes items that have been set from the ones that have not been set explicitly.

This class can be also seen as equivalence of NCollection_DataMap<Standard_Integer,TheItemType> with the only one practical difference: it can be much less memory-expensive if items are small (e.g. Integer or Handle).

The index starts from 0, i.e. should be non-negative. Memory is allocated when item is set by SetValue().

Iterator returns only defined items; the item can be tested for being defined by IsSet(), and undefined by UnsetValue().

The attempt to access the item that has not been set will result in OutOfRange exception in Debug mode; in Release mode this will either return null-filled object or cause access violation.

## Constructor & Destructor Documentation

template<class TheItemType>
NCollection_SparseArray< TheItemType >::NCollection_SparseArray | ( | Standard_Size | theIncrement | ) | `[inline]`

template<class TheItemType>
virtual NCollection_SparseArray< TheItemType >::~NCollection_SparseArray | ( |  | ) | `[inline, virtual]`

## Member Function Documentation

template<class TheItemType>
NCollection_SparseArray& NCollection_SparseArray< TheItemType >::Assign | ( | const NCollection_SparseArray< TheItemType > & | theOther | ) | `[inline]`

template<class TheItemType>
TheItemType& NCollection_SparseArray< TheItemType >::Bind | ( | const Standard_Integer | theIndex,
|  | const TheItemType & | theValue
| ) | `[inline]`

template<class TheItemType>
TheItemType& NCollection_SparseArray< TheItemType >::ChangeFind | ( | const Standard_Integer | theIndex | ) | `[inline]`

template<class TheItemType>
TheItemType& NCollection_SparseArray< TheItemType >::ChangeValue | ( | const Standard_Integer | theIndex | ) | `[inline]`

template<class TheItemType>
virtual void NCollection_SparseArray< TheItemType >::copyItem | ( | Standard_Address | theAddress,
|  | Standard_Address | theOther
| ) | `[inline, private, virtual]`

| Implements NCollection_SparseArrayBase.

template<class TheItemType>
virtual void NCollection_SparseArray< TheItemType >::createItem | ( | Standard_Address | theAddress,
|  | Standard_Address | theOther
| ) | `[inline, private, virtual]`

| Implements NCollection_SparseArrayBase.

template<class TheItemType>
virtual void NCollection_SparseArray< TheItemType >::destroyItem | ( | Standard_Address | theAddress | ) | `[inline, private, virtual]`

| Implements NCollection_SparseArrayBase.

template<class TheItemType>
void NCollection_SparseArray< TheItemType >::Exchange | ( | NCollection_SparseArray< TheItemType > & | theOther | ) | `[inline]`

template<class TheItemType>
Standard_Size NCollection_SparseArray< TheItemType >::Extent | ( |  | ) | const`[inline]`

template<class TheItemType>
const TheItemType& NCollection_SparseArray< TheItemType >::Find | ( | const Standard_Integer | theIndex | ) | const`[inline]`

template<class TheItemType>
Standard_Boolean NCollection_SparseArray< TheItemType >::IsBound | ( | const Standard_Integer | theIndex | ) | const`[inline]`

template<class TheItemType>
Standard_Boolean NCollection_SparseArray< TheItemType >::IsEmpty | ( |  | ) | const`[inline]`

template<class TheItemType>
TheItemType& NCollection_SparseArray< TheItemType >::operator() | ( | const Standard_Integer | theIndex | ) | `[inline]`

template<class TheItemType>
const TheItemType& NCollection_SparseArray< TheItemType >::operator() | ( | const Standard_Integer | theIndex | ) | const`[inline]`

template<class TheItemType>
TheItemType& NCollection_SparseArray< TheItemType >::SetValue | ( | const Standard_Integer | theIndex,
|  | const TheItemType & | theValue
| ) | `[inline]`

template<class TheItemType>
Standard_Boolean NCollection_SparseArray< TheItemType >::UnBind | ( | const Standard_Integer | theIndex | ) | `[inline]`

template<class TheItemType>
const TheItemType& NCollection_SparseArray< TheItemType >::Value | ( | const Standard_Integer | theIndex | ) | const`[inline]`

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

- NCollection_SparseArray.hxx