[ 
https://issues.apache.org/jira/browse/GROOVY-4606?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16299379#comment-16299379
 ] 

Jochen Theodorou commented on GROOVY-4606:
------------------------------------------

The problem with the HashMap idea is, that it works only if equals and hashcode 
are defined accordingly. That is not the case in general. For example for 
double 0 and BigDecimal 0 being equal in the Groovy sense, but not for a 
HashMap.

I guess a better solution would be to have a second, faster unique method, that 
does not take coercing into account.

> Exteremely bad performance of .unique() and .unique {closure}
> -------------------------------------------------------------
>
>                 Key: GROOVY-4606
>                 URL: https://issues.apache.org/jira/browse/GROOVY-4606
>             Project: Groovy
>          Issue Type: Bug
>          Components: groovy-jdk
>    Affects Versions: 1.7.5
>            Reporter: Maxym Mykhalchuk
>         Attachments: UniqueMath.java
>
>
> DefaultGroovyMethods.unique has two inner loops, so its complexity is O(n^2)
> Practically it means that it starts taking ages on collections with 1000 or 
> more elements.
> Simply adding elements to a linked hash set would get O(n*log n) performance.
> Will develop my own unique implementation after New Year, and will attach it 
> here



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to