| Version: 3.3.1

Public Member Functions | List of all members
wxSortedArrayString Class Reference
Class List by Category » Containers

`#include <wx/arrstr.h>`

Inheritance diagram for wxSortedArrayString:
[legend]

## Detailed Description

wxSortedArrayString is an efficient container for storing wxString objects which always keeps the strings in alphabetical order.

wxSortedArrayString uses binary search in its wxSortedArrayString::Index() method (instead of linear search for wxArrayString::Index()) which makes it much more efficient if you add strings to the array rarely (because, of course, you have to pay for Index() efficiency by having Add() be slower) but search for them often. Several methods should not be used with sorted array (basically, all those which break the order of items) which is mentioned in their description.

##

Library: wxBase
Category: Containers

See also
  wxArray, wxString, wxString Overview

## Public Member Functions
| wxSortedArrayString ()
| Default constructor. More...
| wxSortedArrayString (CompareFunction compareFunction)
| Constructs a sorted array using the specified compareFunction for item comparison. More...
| wxSortedArrayString (const wxArrayString &array)
| Conversion constructor. More...
size_t | Add (const wxString &str, size_t copies=1)
| Appends the given number of copies of the new item str to the array and returns the index of the first new item in the array. More...
int | Index (const wxString &str, bool bCase=true, bool bFromEnd=false) const
| Searches the array for str, starting from the beginning if bFromEnd is false or from the end otherwise. More...
void | Insert (const wxString &str, size_t nIndex, size_t copies=1)
void | Sort (bool reverseOrder=false)
void | Sort (CompareFunction compareFunction)

## Constructor & Destructor Documentation

## ◆ wxSortedArrayString() [1/3]

wxSortedArrayString::wxSortedArrayString | ( |  | ) |

Default constructor.

The elements of the array are kept sorted in alphabetical order.

## ◆ wxSortedArrayString() [2/3]

wxSortedArrayString::wxSortedArrayString | ( | CompareFunction | compareFunction | ) |

Constructs a sorted array using the specified compareFunction for item comparison.

See also
  wxStringSortAscending(), wxDictionaryStringSortAscending()

Since
  3.1.0

## ◆ wxSortedArrayString() [3/3]

wxSortedArrayString::wxSortedArrayString | ( | const wxArrayString & | array | ) |

Conversion constructor.

Constructs a sorted array with the same contents as the (possibly unsorted) array argument.

## Member Function Documentation

## ◆ Add()

size_t wxSortedArrayString::Add | ( | const wxString & | str,
|  | size_t | copies = `1`
| ) |  |

Appends the given number of copies of the new item str to the array and returns the index of the first new item in the array.

See also
  Insert()

Warning
  For sorted arrays, the index of the inserted item will not be, in general, equal to GetCount() - 1 because the item is inserted at the correct position to keep the array sorted and not appended.

## ◆ Index()

int wxSortedArrayString::Index | ( | const wxString & | str,
|  | bool | bCase = `true`,
|  | bool | bFromEnd = `false`
| ) |  | const

Searches the array for str, starting from the beginning if bFromEnd is false or from the end otherwise.

If bCase, comparison is case sensitive (default), otherwise the case is ignored.

This function uses linear search for wxArrayString. Returns the index of the first item matched or `wxNOT_FOUND` if there is no match.

This function uses binary search for wxSortedArrayString, but it ignores the bCase and bFromEnd parameters.

## ◆ Insert()

void wxSortedArrayString::Insert | ( | const wxString & | str,
|  | size_t | nIndex,
|  | size_t | copies = `1`
| ) |  |

Warning
  This function should not be used with sorted arrays because it could break the order of items and, for example, subsequent calls to Index() would then not work!
  In STL mode, Insert is private and simply invokes wxFAIL_MSG.

## ◆ Sort() [1/2]

void wxSortedArrayString::Sort | ( | bool | reverseOrder = `false` | ) |

Warning
  This function should not be used with sorted array because it could break the order of items and, for example, subsequent calls to Index() would then not work! Also, sorting a wxSortedArrayString doesn't make sense because its elements are always already sorted.
  In STL mode, Sort is private and simply invokes wxFAIL_MSG.

## ◆ Sort() [2/2]

void wxSortedArrayString::Sort | ( | CompareFunction | compareFunction | ) |

Warning
  This function should not be used with sorted array because it could break the order of items and, for example, subsequent calls to Index() would then not work! Also, sorting a wxSortedArrayString doesn't make sense because its elements are always already sorted.
  In STL mode, Sort is private and simply invokes wxFAIL_MSG.