Rogue Wave banner
Previous fileTop of DocumentContentsIndex pageNext file
Essential Tools Module Reference Guide


Module:  Essential Tools Module   Group:  Generic


Local Index



#include <rw/gsortvec.h>
implement(RWGSortedVector, val)
RWGSortedVector(val) v;    // A sorted vector of vals .


Class RWGSortedVector(val) represents a vector of elements of val val, sorted using an insertion sort. The elements can be retrieved using an index or a search. Duplicates are allowed. Objects of val RWGSortedVector(val) are declared with macros defined in the standard C++ header file <generic.h>.

NOTE -- RWGSortedVector is deprecated. Please use RWTValSortedVector or RWTPtrSortedVector.

Note that it is a value-based collection: items are copied in and out of the collection.

The class val must have:

To use this class you must declare and implement its base class as well as the class itself. For example, here is how you declare and implement a sorted collection of doubles:

For each val of RWGSortedVector you must include one (and only one) call to the macro implement somewhere in your code for both the RWGSortedVector itself and for its base class RWGVector.

Insertions and retrievals are done using a binary search. Note that the constructor of an RWGSortedVector(val) requires a pointer to a "comparison function." This function should have protoval:

and should return an int less than, greater than, or equal to zero, depending on whether the item pointed to by a is less than, greater than, or equal to the item pointed to by b. Candidates from the collection will appear as a, the key as b.




Here's an example of a sorted vector of ints:

Public Constructors

RWGSortedVector(val)( int (*f)(const val*, const val*) );
RWGSortedVector(val)(int (*f)(const val*, const val*), 
                size_t N);

Public Member Functions

operator()(size_t i) const;
operator[](size_t i) const;
entries() const;
index(val v);
insert(val v);
removeAt(size_t indx);
resize(size_t newCapacity);

Previous fileTop of DocumentContentsIndex pageNext file

©2004 Copyright Quovadx, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Quovadx, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.