Java Mailing List Archive

http://www.gg3721.com/

Home » user.groovy »

[groovy-user] how to find similar values between two lists Double[]

Andreas Quandt

2010-03-18

Replies: Find Java Web Hosting

Author LoginPost Reply
dear list,

i have a list of several thousands of double. now i have to test if
this list contains values which match doubles from another (very large)
list.
here some pseudo-code:

def list1 = [0.0..1000.9]
def list2 = [100.9..999.9]

problem is that a equal comparison

assert list2.each{list1.contains[it]}

will not work because i rather have to check if list1 contains values
which are in a specific range based on each value in list2

 list2.each{ val ->
    def urange = val + 0.25
    def lrange= val - 0.25
    def found_values = list1.grep({lrange <= it && it <= urange})
    assert found_values.size() != 0
  }

the snipped works so far but will be very slow when doing this
comparison for the thousands of values in each list.
hence, i was wondering if one of you could help me finding a 'groovier'
solution which is also fast ;-)

many thanks in advance for any help!

cheers,
andreas

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email


©2008 gg3721.com - Jax Systems, LLC, U.S.A.