Grasshopper

algorithmic modeling for Rhino

I made a little VBscript that remove duplicate values from a single list of numbers. It's not optimized but it works. Use it, test it and letme know. As usual, hints ad upgrades are welcome. Bye.

Paolo

Tags: VB, duplicate, remove, script, value, values

Views: 2328

Attachments:

Reply to This

Replies to This Discussion

cool, thank you!

Hi Paolo,

 

see attached. It's a bit smaller (and I think quite a bit faster, especially on large lists). I added comments to the code, but here it is without:

 

Dim lut As New SortedDictionary(Of Double, Boolean)       

Dim result As New List(Of Double)      

For Each value As Double In Values            

    If (lut.ContainsKey(value)) Then Continue For            

    result.Add(value)     

    lut.Add(value, True)

Next

A = result

 

--

David Rutten

david@mcneel.com

Poprad, Slovakia

 

 

Attachments:

what to do for string duplicates?

Dim lut As New SortedDictionary(Of String, Boolean)

Dim result As New List(Of String)  

You can use any type you want as long as it provides it's own CompareTo method. If it doesn't, then you'll have to provide the SortedDictionary with a custom delegate which performs the comparison.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Thanks David

(it's always a pleasure learning from the master)

RSS

Translate

Search Grasshopper

Photos

  • Add Photos
  • View All

© 2014   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service