<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<br>
<br>
<div class="moz-cite-prefix">On 3/22/16 9:53 AM, Denis Kozlov wrote:<br>
</div>
<blockquote
cite="mid:CAC9nf9pzT7=UbVKewXyG87eL=69Rw4oJP+CzbZZzi501CQ-ytw@mail.gmail.com"
type="cite">
<div dir="ltr">
<div class="gmail_extra"><br>
<div class="gmail_quote"><br>
<div><br>
</div>
<div>Please consider the following implementation logic, I
think it covers all angles:</div>
<div><br>
</div>
<div>procedure Find(const S: string; out Index:
Integer):Boolean;</div>
<div>begin</div>
<div> if Sorted then</div>
<div> Result := FindSorted(S, Index);</div>
<div> else</div>
<div> begin</div>
<div> Index := IndexOf(S);</div>
<div> Result := (Index >= 0);</div>
<div> end;</div>
<div>end;</div>
<div><br>
</div>
<div>procedure FindSorted(const S: string; out Index:
Integer; CheckSorted: Boolean = True):Boolean;</div>
<div>begin</div>
<div> if CheckSorted and not Sorted then</div>
<div> raise Exception.Create('List must be sorted');</div>
<div> // search logic here...</div>
<div>end;</div>
<div><br>
</div>
<div><br>
</div>
<div>Denis</div>
</div>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
fpc-devel maillist - <a class="moz-txt-link-abbreviated" href="mailto:fpc-devel@lists.freepascal.org">fpc-devel@lists.freepascal.org</a>
<a class="moz-txt-link-freetext" href="http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel">http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel</a>
</pre>
</blockquote>
Denis,<br>
<br>
I like how this solves the issue of calling find on truly unsorted
lists. My only quibble with this is that 'Sorted' still does not
reflect the actual state of the list. For a naturally sorted list
there is still unnecessary calls to sort both in your suggested code
above and in the existing code (if sorted is set). Can that be
handled as well? 'Sorted' right now is a request and an expression
of state. As an expression of state it is only valid if the request
has been first made.<br>
<br>
David<br>
<br>
</body>
</html>