realbasic-nug
[Top] [All Lists]

Re: Removing Duplicates in an Array

To: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Subject: Re: Removing Duplicates in an Array
From: Charles Yeomans <charles@declareSub.com>
Date: Sat, 31 Jan 2009 20:57:06 -0500
Authentication-results: mx.google.com; spf=neutral (google.com: 74.124.194.228 is neither permitted nor denied by best guess record for domain of realbasic-nug-bounces@lists.realsoftware.com) smtp.mail=realbasic-nug-bounces@lists.realsoftware.com
Delivered-to: listarchive@realsoftware.com
In-reply-to: <C5AA5E99.1ECD9%ktekinay@mactechnologies.com>
References: <C5AA5E99.1ECD9%ktekinay@mactechnologies.com>
Reply-to: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Sender: realbasic-nug-bounces@lists.realsoftware.com

On Jan 31, 2009, at 8:01 PM, Kem Tekinay wrote:

On 1/31/09 3:45 PM, "Charles Yeomans" <charles@declareSub.com> wrote:

Someone else suggested using a Dictionary object.  I suggest using it
as follows.

Function RemoveDuplicates(theList() as Integer) as Integer()
  dim d as new Dictionary
  dim newList() as Integer
  for i as Integer = 0 to UBound(theList)
    if not d.HasKey(theList(i)) then
      newList.Append theList(i)
      d.Value(theList(i) = nil
    end if
  next
  return newList
End Function

It probably would be faster to predimension the array, especially for large
arrays. (And, this is supposed to be for strings.)

I expect it would.  But that's not what I was optimizing for :)

Charles Yeomans


_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>


<Prev in Thread] Current Thread [Next in Thread>