Google

C++ Portable Types Library (PTypes) Version 1.7


Top: Basic types: Lists: strlist: Search

#include <ptypes.h>

bool search(const strlist& s, const string& key, int& index);
int  find(const strlist& s, const string& key);
int  indexof(const strlist& s, unknown* obj);

virtual int strlist::compare(const string& key1, const string& key2);

bool search(const strlist& s, const string& key, int& index) works only on sorted lists and returns true if the given string key was found in the list s, or false otherwise. The parameter index returns either the index (position) of the item found, or the position where this item should be placed if it does not exist in the list.

int find(const strlist& s, const string& key) finds the given string key in the list s. It returns the index of the item, or -1 if the item was not found. This function works both on sorted and unsorted lists, however, a sorted list provides better performance.

int indexof(const strlist& s, unknown* obj) finds the given object obj in the list s. It returns the index of the item, or -1 if the item was not found. This function works both on sorted and unsorted lists, but unlike find(), it always uses linear search method.

virtual int strlist::compare(const string& key1, const string& key2) is a protected virtual method that can be overridden to provide alternate comparison algorithm for sorted lists. The overridden function should return -1, 0 or 1 as a result of comparing keys key1 and key2.

See also: Constructors/destructors, Manipulation


PTypes home