|
1 <?xml version="1.0" encoding="utf-8"?> |
|
2 <!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. --> |
|
3 <!-- This component and the accompanying materials are made available under the terms of the License |
|
4 "Eclipse Public License v1.0" which accompanies this distribution, |
|
5 and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". --> |
|
6 <!-- Initial Contributors: |
|
7 Nokia Corporation - initial contribution. |
|
8 Contributors: |
|
9 --> |
|
10 <!DOCTYPE concept |
|
11 PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd"> |
|
12 <concept id="GUID-07FA8EC8-151F-574A-89F2-34C4AE2D1F0B" xml:lang="en"><title>How |
|
13 to find elements</title><shortdesc>There are two methods for searching for data in an array. Sequentially |
|
14 and binary chop.</shortdesc><prolog><metadata><keywords/></metadata></prolog><conbody> |
|
15 <p>A search can be made for elements based on the value of a key. A search |
|
16 can be done in one of two ways: </p> |
|
17 <ul> |
|
18 <li id="GUID-1C8D05FB-E5CA-5237-9666-CE4EF72A0920"><p>Sequentially through |
|
19 the array, starting with the first element — performed using the <codeph>Find()</codeph> member |
|
20 function</p> </li> |
|
21 <li id="GUID-B4727A94-2FA9-5F98-B0E2-DA63AF73191B"><p>Using a binary search |
|
22 (binary chop) technique — performed using the <codeph>FindIsq()</codeph> member |
|
23 function. This technique assumes that the array elements are in key sequence.</p> </li> |
|
24 </ul> |
|
25 <p>Both functions indicate the success or failure of the search and, if successful, |
|
26 supply the position of the element within the array.</p> |
|
27 <p>Note that where an array has elements with <i>duplicate keys</i>:</p> |
|
28 <ul> |
|
29 <li id="GUID-EB9FCE02-B203-525D-AED7-5D5E6E2E054C"><p><codeph>Find()</codeph> only |
|
30 supplies the position of the <i>first</i> element in the array with that key.</p> </li> |
|
31 <li id="GUID-B084BCB6-18C7-5EE1-8184-AB17A525967F"><p><codeph>FindIsq()</codeph> cannot |
|
32 guarantee which element, with the given key value, it will return; except |
|
33 that it will find one of them.</p> </li> |
|
34 </ul> |
|
35 <p>The elements of arrays can be sorted. This is done by the <codeph>Sort()</codeph> member |
|
36 function for <codeph>CArrayFixFlat<class T></codeph>, <codeph>CArrayFixSeg<class T></codeph>, <codeph>CArrayVarFlat<class T></codeph> and <codeph>CArrayVarSeg<class T></codeph> arrays. You must use the <codeph>SortL()</codeph> member |
|
37 function for the <codeph>CArrayPakFlat<class T></codeph> array. </p> |
|
38 </conbody></concept> |