Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

RWSortedVector


RWSortedVector-->RWOrdered-->RWSequenceable--> ... ... RWCollection-->RWCollectable

Data Type and Member Function Indexes
(exclusive of constructors and destructors)

Synopsis

#include <rw/sortvec.h>
RWSortedVector a;

Description

Class RWSortedVector represents a group of ordered items, internally sorted by the compareTo() function and accessible by an index number. Duplicates are allowed. An object stored by RWSortedVector must inherit from the abstract base class RWCollectable. An insertion sort is used to maintain the vector in sorted order.

Because class RWSortedVector is implemented as a vector of pointers, traversing the collection is more efficient than with class RWBinaryTree. However, insertions are slower in the center of the collection.

Note that because the vector is sorted, you must not modify elements contained in the vector in such a way as to invalidate the ordering.

Persistence

Polymorphic

Example

#include <rw/sortvec.h>
#include <rw/collstr.h>
#include <rw/rstream.h>

main(){
   RWSortedVector sv;
   sv.insert(new RWCollectableString("dog"));
   sv.insert(new RWCollectableString("cat"));
   sv.insert(new RWCollectableString("fish"));
   RWSortedVectorIterator next(sv);
   RWCollectableString* item;
   while( item = (RWCollectableString*)next() )
     cout << *item << endl;
   sv.clearAndDestroy();
}

Program output:

cat
dog
fish

Public Constructors

RWSortedVector(size_t size = RWDEFAULT_CAPACITY);

Public Member Operators

RWBoolean
operator==(const RWSortedVector& sv) const;
const RWCollectable*
operator[](size_t i);
const RWCollectable*
operator()(size_t i);

Public Member Functions

virtual void
apply(RWapplyCollectable ap, void* x);
virtual const RWCollectable*
at(size_t i) const;
virtual RWspace
binaryStoreSize() const;
virtual void
clear();
virtual void
clearAndDestroy();
virtual int
compareTo(const RWCollectable* a) const;
virtual RWBoolean
contains(const RWCollectable* target) const;
virtual size_t
entries() const;
virtual RWCollectable*
find(const RWCollectable* target) const;
virtual RWCollectable*
first() const;
virtual unsigned
hash() const;
virtual size_t
index(const RWCollectable*) const;
virtual RWCollectable*
insert(RWCollectable* c);
virtual RWClassID
isA() const;
virtual RWBoolean
isEmpty() const;
virtual RWBoolean
isEqual(const RWCollectable* a) const;
virtual RWCollectable*
last() const;
virtual size_t
occurrencesOf(const RWCollectable* target) const;
virtual RWCollectable*
remove(const RWCollectable* target);
virtual void
removeAndDestroy(const RWCollectable* target);
RWCollectable*
removeAt(size_t index);


Previous fileTop of documentContentsIndexNext file
©Copyright 1999, Rogue Wave Software, Inc.
Send mail to report errors or comment on the documentation.