Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

Array Class Reference

#include <Array.h>

Inheritance diagram for Array:

String TempString StringNode

List of all members.


Public Members

 Array ()
 Array (UInt32 size, Int alloc = kFirstAllocation)
 Array (const TArray &array)
 ~Array ()
T& operator[] (Int i)
Indexing operator.

const T& operator[] (Int i) const
Indexing operator.

Int NumItems () const
Number of items in the array.

TArray& operator= (const TArray &array)
Assignment!

T& Top ()
Return top of stack.

Void Pop ()
Delete top of stack.

Void Push (const T &t)
Push item onto stack.

Void Append (const T &t)
Append single item to array.

T& Last ()
Return last item in array.

Void Clear ()
Delete all items.

Void PreAllocate (UInt32 numItems)
Preallocate space for array.

Void SetSize (Int newSize)
Set array size directly.

Void Add (Int n = 1)
Add n items to the array.

Void Shrink (Int n = 1)
shrink the array by n items.

Void Insert (Int i, Int n = 1)
Insert n items at i.

Void Delete (Int i, Int n = 1)
Delete n items at i.

Void ShrinkWrap ()
Ensure allocated space = space being used.

Void ClearTo (const T &t)
Clear the array using t.

Void Append (const TArray &a)
Append array to array.

Void SwapWith (TArray &a)
Swaps this array with a.

Void Replace (TArray &a)
Replace this array with a & clear a.

const T& Item (Int i) const
T& Item (Int i)
T* Ref () const
Return pointer to array.

T* Detach ()
As above, but the array no longer owns the data.

Void Attach (T *itemsPtr, Int numItems, Bool shared)
Attach the array to the given chunk of memory. More...

Void WriteFile (const Char *filename)
Void ReadFile (const Char *filename)
Int FWrite (FILE *file)
Int FRead (FILE *file)

Protected Members

Void Grow ()
T* item
pointer to array.

UInt32 items
items in the array.

UInt32 allocated
number of items we have space allocated for.


Detailed Description

Note: We grow the array in size exponentially. That is, every time we need to increase the size of the array, we double its size rather than increasing it by a fixed amount. For appending n items to an empty list, this gives us O(n) copies, as opposed to the O(n^2) copies required if we increment by a fixed size each time.

It would be useful to have an array data structure that utilises a tree of fixed-size arrays, thus trading off access time (const vs. o(logbn)) against eliminating copies.

Definition at line 25 of file Array.h.


Constructor & Destructor Documentation

Array::Array ()

Array::Array (UInt32 size, Int alloc = kFirstAllocation)

Array::Array (const TArray & array)

Array::~Array ()


Member Function Documentation

Void Array::Add (Int n = 1)

Add n items to the array.

Void Array::Append (const TArray & a)

Append array to array.

Void Array::Append (const T & t) [inline]

Append single item to array.

Void Array::Attach (T * itemsPtr, Int numItems, Bool shared)

Attach the array to the given chunk of memory.

If shared is true, the memory won't be deleted when the array is destroyed.

Void Array::Clear ()

Delete all items.

Void Array::ClearTo (const T & t)

Clear the array using t.

Void Array::Delete (Int start, Int length = 1)

Delete n items at i.

Reimplemented in String.

T * Array::Detach () [inline]

As above, but the array no longer owns the data.

Int Array::FRead (FILE * file)

Int Array::FWrite (FILE * file)

Void Array::Grow () [protected]

Void Array::Insert (Int i, Int n = 1)

Insert n items at i.

T & Array::Item (Int i) [inline]

Definition at line 70 of file Array.h.

const T & Array::Item (Int i) const [inline]

Definition at line 68 of file Array.h.

T & Array::Last () [inline]

Return last item in array.

Int Array::NumItems () const [inline]

Number of items in the array.

Void Array::Pop () [inline]

Delete top of stack.

Void Array::PreAllocate (UInt32 numItems)

Preallocate space for array.

Void Array::Push (const T & t) [inline]

Push item onto stack.

Void Array::ReadFile (const Char * filename)

T * Array::Ref () const [inline]

Return pointer to array.

Void Array::Replace (TArray & a)

Replace this array with a & clear a.

Void Array::SetSize (Int newSize)

Set array size directly.

Void Array::Shrink (Int n = 1)

shrink the array by n items.

Void Array::ShrinkWrap ()

Ensure allocated space = space being used.

Void Array::SwapWith (TArray & a)

Swaps this array with a.

T & Array::Top () [inline]

Return top of stack.

Void Array::WriteFile (const Char * filename)

TArray & Array::operator= (const TArray & array)

Assignment!

const T & Array::operator[] (Int i) const [inline]

Indexing operator.

T & Array::operator[] (Int i) [inline]

Indexing operator.


Member Data Documentation

UInt32 Array::allocated [protected]

number of items we have space allocated for.

Definition at line 95 of file Array.h.

T * Array::item [protected]

pointer to array.

Definition at line 93 of file Array.h.

UInt32 Array::items [protected]

items in the array.

Definition at line 94 of file Array.h.


The documentation for this class was generated from the following files:
Generated at Sat Aug 5 00:16:33 2000 for Class Library by doxygen 1.1.0 written by Dimitri van Heesch, © 1997-2000