Rogue Wave banner
Previous fileTop of documentContentsIndexNext file

RWTValSortedVector<T,C>

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

Synopsis

#include <rw/tvsrtvec.h> 
RWTValSortedVector<T,C> srtvec;

Please Note!


If you have the Standard C++ Library, use the interface described here. Otherwise, use the restricted interface to RWTValSortedVector described in Appendix A.


Description

This class maintains an always-sorted collection of values, implemented as a vector.

The value type must have operator== and operator< defined. This requirement is imposed by the Standard C++ Library.

Persistence

Isomorphic

Example

In this example, a sorted vector of RWDates is exercised.

//
// tvsvcdat.cpp
//
#include <rw/tvsrtvec.h>
#include <rw/rwdate.h>
#include <iostream.h>

main(){
  RWTValSortedVector<RWDate, less<RWDate> > vec;

  vec.insert(RWDate(10, "Aug", 1991));
  vec.insert(RWDate(9, "Aug", 1991));
  vec.insert(RWDate(1, "Sep", 1991));
  vec.insert(RWDate(14, "May", 1990));
  vec.insert(RWDate(1, "Sep", 1991));   // Add a duplicate
  vec.insert(RWDate(2, "June", 1991));

  for (int i=0; i<vec.entries(); i++)
    cout << vec[i] << endl;
  return 0;
}
Program Output:
05/14/90
06/02/91
08/09/91
08/10/91
09/01/91
09/01/91

Related Classes

RWTValSortedDlist<T,C> is an alternative always-sorted collection. RWTValOrderedVector<T> is an unsorted vector of values.

Class vector<T,allocator> is the C++-standard collection that serves as the underlying implementation for this class.

Public Typedefs

typedef:vector<T,allocator>                    container_type; 
typedef:container_type::const_iterator         iterator;
typedef:container_type::const_iterator         const_iterator;
typedef:container_type::size_type              size_type;
typedef:T                                      value_type; 
typedef:const T&                               reference; 
typedef:const T&                               const_reference; 

Public Constructors

RWTValSortedVector<T,C>();
RWTValSortedVector<T,C>(const vector<T,allocator>& vec);
RWTValSortedVector<T,C>(const RWTValSortedVector<T,C>& rwvec);
RWTValSortedVector<T,C>(size_type n, const T& val);
RWTValSortedVector<T,C>(size_type n);
RWTValSortedVector<T,C>(const T* first, const T* last);

Public Member Operators

bool
operator<(const RWTValSortedVector<T,C>& vec) const; 
bool
operator<(const vector<T,allocator>& vec) const;
bool
operator==(const RWTValSortedVector<T,C>& vec) const; 
bool
operator==(const vector<T,allocator>& vec) const;
reference
operator()(size_type i); 
const_reference
operator()(size_type i) const;
reference
operator[](size_type i); 
const_reference
operator[](size_type i) const;

Public Member Functions

void
apply(void (*fn)(const_reference,void*), void* d) const; 
reference
at(size_type i); 
const_reference
at(size_type i) const;
iterator
begin();
const_iterator
begin() const;
void
clear();
bool
contains(const_reference a) const; 
bool
contains(bool (*fn)(const_reference,void*), void* d) const;
const T*
data();
iterator
end();
const_iterator
end() const;
size_type
entries() const; 
bool
find(const_reference a, value_type& k) const; 
bool
find(bool (*fn)(const_reference,void*), void* d, 
     value_type& k) const;
reference
first();
const_reference
first() const;
size_type
index(const_reference a) const; 
size_type
index(bool (*fn)(const_reference,void*), void* d) const;
bool
insert(const_reference a); 
size_type
insert(const vector<T,allocator>& a);
bool
isEmpty() const; 
bool
isSorted() const; 
const_reference
last() const; 
size_type
length() const; 
size_type
merge(const RWTValSortedVector<T,C>& dl); 
size_type
occurrencesOf(const_reference a) const; 
size_type
occurrencesOf(bool (*fn)(const_reference,void*), 
              void* d) const;
bool
remove(const_reference a); 
bool
remove(bool (*fn)(const_reference,void*), void* d);
size_type
removeAll(const_reference a); 
size_type
removeAll(bool (*fn)(const_reference,void*), void* d);
value_type
removeAt(size_type i); 
value_type
removeFirst();
value_type
removeLast();
void
resize(size_type n); 
vector<T,allocator>&
std();
const vector<T,allocator>&
std() const;

Static Public Data Member

const size_type  npos;

Related Global Operators

RWvostream&
operator<<(RWvostream& strm, 
      const RWTValSortedVector<T,C>& coll);
RWFile&
operator<<(RWFile& strm, const RWTValSortedVector<T,C>& coll);
RWvistream&
operator>>(RWvistream& strm, RWTValSortedVector<T,C>& coll); 
RWFile&
operator>>(RWFile& strm, RWTValSortedVector<T,C>& coll);
RWvistream&
operator>>(RWvistream& strm, RWTValSortedVector<T,C>*& p);
RWFile&
operator>>(RWFile& strm, RWTValSortedVector<T,C>*& p);


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