BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bdlc_packedintarrayutil

Detailed Description

Outline

Purpose

Provide common non-primitive operations on bdlc::PackedIntArray.

Classes

See also
bdlc_packedintarray

Description

This component provides a struct, bdlc::PackedIntArrayUtil, that serves as a namespace for utility functions that operate on bdlc::PackedIntArray objects.

The following list of methods are provided by bdlc::PackedIntArrayUtil:

'isSorted' Returns 'true' if the range from a
'bdlc::PackedIntArray' is sorted, and 'false' otherwise.
'lowerBound' Returns an iterator to the first element in a sorted
range from a 'bdlc::PackedIntArray' that compares
greater than or equal to a specified value.
'upperBound' Returns an iterator to the first element in a sorted
range from a 'bdlc::PackedIntArray' that compares
greater than a specified value.

Usage

This section illustrates intended use of this component.

Example 1: lowerBound

Suppose that given a sorted bdlc::PackedIntArray, we want to find the first value greater than or equal to the value 17. First, create and populate with sorted data the bdlc::PackedIntArray to be searched:

array.push_back( 5);
array.push_back( 9);
array.push_back(15);
array.push_back(19);
array.push_back(23);
array.push_back(36);
assert(6 == array.length());
Definition bdlc_packedintarray.h:1048
bsl::size_t length() const
Return number of elements in this array.
Definition bdlc_packedintarray.h:2586
void push_back(TYPE value)
Definition bdlc_packedintarray.h:2377

Then, verify the array's data has sorted values:

assert(bdlc::PackedIntArrayUtil::isSorted(array.begin(), array.end()));
const_iterator end() const
Definition bdlc_packedintarray.h:2556
const_iterator begin() const
Definition bdlc_packedintarray.h:2535
static bool isSorted(PackedIntArrayConstIterator< TYPE > first, PackedIntArrayConstIterator< TYPE > last)
Definition bdlc_packedintarrayutil.h:167

Finally, use bdlc::PackedIntArrayUtil::lowerBound to find the desired value:

array.end(),
17);
assert(iterator != array.end() && 19 == *iterator);
Definition bdlc_packedintarray.h:770
static PackedIntArrayConstIterator< TYPE > lowerBound(PackedIntArrayConstIterator< TYPE > first, PackedIntArrayConstIterator< TYPE > last, TYPE value)
Definition bdlc_packedintarrayutil.h:186